Ansible + virtualenvwrapper
virtualenvwrapper is a very convenient tool to use. It provides easier access to all the regular features you like in virtualenv.
But when it comes to automation with Ansible some issues might occur. You cannot just call workon venv
within one task and then continue to work in the same context from another task. There are two options how to overcome this issue.
Call python executable directly from environment directory
In this case you need two extra variables: one for project's root and the other for the path to virtual environment
1 | - name: Install requirements |
The same way you can call your python binary {{ virtualenv_path }}/bin/python
Explicitly modify environment
Just modify PATH
environment variable for the task and it will pick the right one python for you
1 | - name: Call script within proper environment |
Notes
Consider using built-in pip module for Ansible but in case you want to stick with virtualenvwrapper use one of the approaches above.