Skip to content

Instantly share code, notes, and snippets.

@Blake-
Created October 1, 2016 13:05
Show Gist options
  • Save Blake-/785d2dc6b599e9cbf9bfcdb8d749be19 to your computer and use it in GitHub Desktop.
Save Blake-/785d2dc6b599e9cbf9bfcdb8d749be19 to your computer and use it in GitHub Desktop.
First, you’ll need to install support for Python virtualenvs. Although some folks have said not to use sudo when installing via Pip, I found it necessary:
sudo -H pip install virtualenv
Note that you might need to install Pip first, which—fortunately—is pretty straightforward (easy_install pip).
Once you have virtualenv support installed, then create a virtualenv into which you’ll install the Ansible dependencies:
virtualenv --system-site-packages ansible
This will create a virtualenv called “ansible” in a directory named “ansible” in the current working directory. I used the --system-site-packages flag to allow this virtualenv to have access to the system site packages. I saw various recommendations both for and against this approach; my line of thinking was that this would help prevent some duplication of modules.
Activate the virtualenv by running source ansible/bin/activate (if you used a name other than “ansible”, substitute that in the command). This will modify your prompt so that the name of the virtualenv is shown in parentheses before the prompt.
Now install Ansible using pip install ansible, along with any other necessary dependencies. In my case, I wanted to use the OpenStack modules, so I also ran pip install shade.
When you’re done with the virtualenv, run deactivate. You’ll see your prompt revert to normal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment