Ansible creates virtual channel using venv module

How can I use Ansible to create virtualenv with venv module from Python3 standard library?

You can manually do this to create a venv (virtual environment):

 python3 -m venv <venv-name> 

How do I do this with Ansible?

+10
source share
2 answers

Tonight I ran into the same problem and found that specifying the full path to the interpreter, including the arguments, works for me (at least in ansible==2.2.2.0 ):

 - pip: requirements: /website/requirements.txt virtualenv: /opt/website-venv virtualenv_command: /usr/bin/python3.6 -m venv 

or

 - pip: requirements: /opt/project/requirements_prod.txt virtualenv: /opt/.virtualenv/project_env virtualenv_python: python3 
+15
source
 # Install specified python requirements in indicated (virtualenv). - pip: requirements: /my_app/requirements.txt virtualenv: /my_app/venv 

If python3 is really broken, you can specify which version of python you want to use:

 # Install specified python requirements in indicated (virtualenv). - pip: requirements: /my_app/requirements.txt virtualenv: /my_app/venv virtualenv_command: virtualenv-2.7 

I think this answers your question.

-3
source

Source: https://habr.com/ru/post/1015439/


All Articles