Ansible creating a virtualenv


How do you create a virtualenv for a specific python version using ansible. Is there a command in the ansible standard library?

I would like something like:


I have at times experienced some erratic behaviour with specifying virtualenv_command (e.g.: getting a python 2.7 executable in my virtualenv even though I specified to run the command with virtualenv-3.4.

If you experience that problem, you can create the virtualenv manually with the command module:

(note: by specifying creates this command will only run in the case that a virtualenv does not exist at /user/home/venvs/myenv).

Then you can install your requirements as normal with the pip command:


I’ve found that specifying the virtualenv_python (available in Ansible 2.0+) also seems to work in the case stated above. For example:

(with this you shouldn’t need to manually create the virtualenv first)

Leave a Reply