Skip to content

Instantly share code, notes, and snippets.

@daveadams
Created February 10, 2014 14:13
Show Gist options
  • Save daveadams/8916625 to your computer and use it in GitHub Desktop.
Save daveadams/8916625 to your computer and use it in GitHub Desktop.
Install ansible within pyenv
#!/bin/bash -e
which pyenv &>/dev/null \
|| { echo "ERROR: pyenv not found" >&2; exit 1; }
grep -qFx 2.7.6 <(pyenv versions --bare) \
|| { echo "ERROR: python 2.7.6 not installed; run 'pyenv install 2.7.6'" >&2; exit 1; }
export PYENV_VERSION=2.7.6
# define the correct share directory based on the python path
SHAREDIR=$(pyenv which python |sed 's:bin/python$:share:')
# create a temporary directory for pip working files
BUILDDIR=/tmp/build-ansible
mkdir -p $BUILDDIR
# install ansible prerequisites
pip install --upgrade --build $BUILDDIR pyyaml paramiko jinja2
# download but do not install ansible itself
pip install --upgrade --build $BUILDDIR --no-install ansible
# replace /usr/share with the correct share dir
sed -i s:/usr/share:$SHAREDIR:g $BUILDDIR/ansible/lib/ansible/constants.py
# remove constants.pyc if it exists to ensure the change gets propagated
rm -f $BUILDDIR/ansible/lib/ansible/constants.pyc
# okay, now really install the patched ansible
pip install --upgrade --build $BUILDDIR --no-download ansible
# rebuild shims
pyenv rehash
# cleanup
rm -rf $BUILDDIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment