Skip to content

Instantly share code, notes, and snippets.

@alces
Last active May 31, 2023 17:43
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save alces/075c871cc4ba76df80740107f677e694 to your computer and use it in GitHub Desktop.
Save alces/075c871cc4ba76df80740107f677e694 to your computer and use it in GitHub Desktop.
Make portable Ansible distribution which can be installed on another host with the same Python version simply by un-tarring it in the same directory. Virtualenv is used during build stage, but isn't required on the target machine. Originally, written as Vagrant provision script but probably can be used outside Vagrant.
#!/bin/bash
ANSIBLE_ROOT=${ANSIBLE_ROOT:-/opt/ansible}
DISTR_ROOT=${DISTR_ROOT:-/vagrant}
yum install -y python-setuptools python-devel libffi-devel openssl-devel
easy_install virtualenv
virtualenv "$ANSIBLE_ROOT"
. "$ANSIBLE_ROOT/bin/activate"
# PY_LIBS can contain a space-separated list of Python libraries your playbooks require to run (e.g., "dnspython shade")
pip install $PY_LIBS ansible
deactivate
echo "Ansible is installed as $ANSIBLE_ROOT/bin/ansible"
cd "$ANSIBLE_ROOT/.." && tar czf "$DISTR_ROOT/ansible.tgz" $(basename "$ANSIBLE_ROOT")
echo "Ansible distribution is saved as $DISTR_ROOT/ansible.tgz"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment