...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#!/usr/bin/env bash # Maintains a directory of Ansible virtual environments, and # an accompanying snippet of bash aliases to activate them. # Put the following into your .bash_rc to be able to use the aliases: # source ~/.bash_ansible BASH_SNIPPET="$HOME/.bash_ansible" ANSIBLES="$HOME/.ansible_virtualenvs" # Update this to keep regularly to have the latest of each minor version VERSIONS="2.1.6 2.2.3 2.3.3 2.4.6 2.5.10 2.6.6 2.7.0" # Needed for the projects we work on MODULES="python-keyczar jmespath netaddr dnspython boto botocore boto3 natsort" # Switch between different python versions. Remember to wipe the old virtualenvs if you do this. PYTHON="python" if [ ! -d "$ANSIBLES" ]; then echo "Ansible collection directory $ANSIBLES does not exist yet, creating it." mkdir -v $ANSIBLES fi echo "# Generated at `date` from $0" > $BASH_SNIPPET for v in $VERSIONS; do virtualenv -p "$PYTHON" "$ANSIBLES/ansible-$v" source "$ANSIBLES/ansible-$v/bin/activate" pip install ansible==$v $MODULES deactivate echo "alias ansible-activate-$v='source $ANSIBLES/ansible-$v/bin/activate'" >> $BASH_SNIPPET done |
When this finishes, you can just open up a new terminal and start typing ansible-activateactivate
and use tab completion to pick the specific version.version
Obviously you can use ansible to install ansible - for instance onto a deployment VM or bastion host:
...