Skip to content

Instantly share code, notes, and snippets.

@gema-arta
Forked from alces/mk_ansible_distro.sh
Created May 31, 2023 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gema-arta/aaacdd5d9f1fd5f28709768b9dab82c8 to your computer and use it in GitHub Desktop.
Save gema-arta/aaacdd5d9f1fd5f28709768b9dab82c8 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