Last active
August 30, 2022 06:44
-
-
Save agowa/070f9a7adca1ba5c4edcfb30e88199f8 to your computer and use it in GitHub Desktop.
Reproducible ansible init with pinned versions for dependencies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[submodule ".pyenv"] | |
path = .pyenv | |
url = https://github.com/pyenv/pyenv.git | |
branch = master | |
[submodule ".pyenv-doctor"] | |
path = .pyenv-doctor | |
url = https://github.com/pyenv/pyenv-doctor.git | |
branch = master | |
[submodule ".pyenv-installer"] | |
path = .pyenv-installer | |
url = https://github.com/pyenv/pyenv-installer.git | |
branch = master | |
[submodule ".pyenv-update"] | |
path = .pyenv-update | |
url = https://github.com/pyenv/pyenv-update.git | |
branch = master | |
[submodule ".pyenv-virtualenv"] | |
path = .pyenv-virtualenv | |
url = https://github.com/pyenv/pyenv-virtualenv.git | |
branch = master | |
[submodule ".pyenv-which-ext"] | |
path = .pyenv-which-ext | |
url = https://github.com/pyenv/pyenv-which-ext.git | |
branch = master | |
[submodule "collections/ansible_collections/ansible/posix"] | |
path = collections/ansible_collections/ansible/posix | |
url = https://github.com/ansible-collections/ansible.posix.git | |
branch = main | |
[submodule "collections/ansible_collections/community/general"] | |
path = collections/ansible_collections/community/general | |
url = https://github.com/ansible-collections/community.general.git | |
branch = main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3.10.4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.241.1/containers/python-3/.devcontainer/base.Dockerfile | |
# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster | |
ARG VARIANT="3.10-bullseye" | |
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT} | |
# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 | |
ARG NODE_VERSION="none" | |
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi | |
# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image. | |
# COPY requirements.txt /tmp/pip-tmp/ | |
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \ | |
# && rm -rf /tmp/pip-tmp | |
RUN pip3 --no-python-version-warning install --upgrade pip | |
RUN pip3 install \ | |
virtualenv \ | |
virtualenvwrapper | |
# [Optional] Uncomment this section to install additional OS packages. | |
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ | |
&& apt-get -y install \ | |
iputils-ping \ | |
dnsutils \ | |
sshpass \ | |
make \ | |
build-essential \ | |
libssl-dev \ | |
zlib1g-dev \ | |
libbz2-dev \ | |
libreadline-dev \ | |
libsqlite3-dev \ | |
wget \ | |
curl \ | |
llvm \ | |
libncurses5-dev \ | |
libncursesw5-dev \ | |
xz-utils \ | |
tk-dev \ | |
libffi-dev \ | |
liblzma-dev | |
# [Optional] Uncomment this line to install global node packages. | |
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ansible==6.1.0 | |
ansible-compat==2.2.0 | |
ansible-core==2.13.2 | |
ansible-lint==6.3.0 | |
Jinja2==3.1.2 | |
pip==22.2.2 | |
PyYAML==6.0 | |
yamllint==1.27.1 | |
netaddr==0.8.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -x | |
export DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) # The current directory | |
if [[ "$DIR" == "" ]] | |
then | |
echo "Dotsourced, assuming current directory" | |
export DIR=`pwd` | |
fi | |
# Remove unclean git submodules checkout if any | |
git submodule deinit --all | |
# Sync remote paths from .gitmodules | |
git submodule sync --recursive | |
# Initialize submodules to latest remote version (if pinned to a branch) | |
git submodule update --init --recursive --remote | |
export WORKON_HOME="$DIR/.venv" | |
export python_version="$(cat $DIR/.python-version)" | |
export PYENV_ROOT="$DIR/.pyenv" | |
export PATH="$PATH:$PYENV_ROOT/bin" | |
source "$( which virtualenvwrapper.sh)" | |
export VIRTUALENV_PYTHON="$(pyenv prefix $python_version 2>/dev/null)/bin/python" | |
if [[ ! -f "$DIR/.venv/ansible.venv" || $VIRTUALENV_PYTHON == "/bin/python" ]] | |
then | |
mkdir -p .pyenv-versions .pyenv-shims | |
ln -Tfrs .pyenv-versions $PYENV_ROOT/versions | |
ln -Tfrs .pyenv-shims $PYENV_ROOT/shims | |
ln -Tfrs .pyenv-doctor $PYENV_ROOT/plugins/pyenv-doctor | |
ln -Tfrs .pyenv-installer $PYENV_ROOT/plugins/pyenv-installer | |
ln -Tfrs .pyenv-update $PYENV_ROOT/plugins/pyenv-update | |
ln -Tfrs .pyenv-virtualenv $PYENV_ROOT/plugins/pyenv-virtualenv | |
ln -Tfrs .pyenv-which-ext $PYENV_ROOT/plugins/pyenv-which-ext | |
pyenv init 2>/dev/null || true | |
pyenv virtualenv-init 2>/dev/null || true | |
pyenv install -s $python_version | |
export VIRTUALENV_PYTHON="$(pyenv prefix $python_version)/bin/python" | |
mkvirtualenv -a $DIR ansible.venv | |
fi | |
workon ansible.venv | |
pip install -r requirements.txt | |
ansible-playbook $DIR/play.yml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment