How can one use Ansible to create a virtualenv using the venv
module from Python3's standard library?
Manually, one would do this to create a venv (virtual environment):
python3 -m venv <venv-name>
How do I do this using Ansible?
How can one use Ansible to create a virtualenv using the venv
module from Python3's standard library?
Manually, one would do this to create a venv (virtual environment):
python3 -m venv <venv-name>
How do I do this using Ansible?
I ran into the same issue tonight and found that specifying the full path to the interpreter, including the arguments, worked for me (at least it does 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
Here is an example using Ansible's command
statement:
- name: Create Python virtual environment
command:
cmd: python3 -m venv {{ project_path }}/project_venv
creates: "{{ project_path }}/project_venv"
ansible_python_interpreter
instead of python3
directly –
Sakovich # Install specified python requirements in indicated (virtualenv).
- pip:
requirements: /my_app/requirements.txt
virtualenv: /my_app/venv
If python3 is indeed being flaky, you can specify which version of python you'd like 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 that answers your question.
© 2022 - 2024 — McMap. All rights reserved.
virtualenv_command
option in the ansible pip module. However, ansible gives an error thatpython3 -m venv
is not a valid command. So I am at loss. – Glomma