Search code examples
pythonvirtualenvansiblevirtualenvwrapper

Ansible and virtualenvwrapper


I have a deployment problem and I want to be able to use virtualevnwrapper in my host machines. But I didn't find any information according virtualenvwrapper. Just ansible modules for virtualenv.

Does the possibility of using virtualenvwrapper in ansible exists?


Solution

  • You probably don't need virtualenvwrapper as you can activate the virtualenv yourself. You need to source the activate file in the <your_env>/bin/activate directory prior to executing a python command with Ansible.

    If the above doesn't work you can always adjust the PATH variable yourself to include /path/to/my/virtualenv/bin which is effectively what sourcing the activate file does. After that, it means the Python executable in that directory is used instead of the global one.

    In other words, run a python command within Ansible with an updated PATH variable:

    environment:
        PATH: /path/to/my/virtualenv/bin:{{ ansible_env.PATH }}