Ansible创建一个virtualenv [英] Ansible creating a virtualenv
问题描述
如何使用ansible为特定的python版本创建virtualenv. ansible标准库中有命令吗?
How do you create a virtualenv for a specific python version using ansible. Is there a command in the ansible standard library?
我想要类似的东西
- virtualenv: dest=venv python_version:/usr/bin/python3
推荐答案
有时我在指定virtualenv_command
时遇到了一些不稳定的行为(例如:即使我指定使用virtualenv-3.4
.
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
.
如果遇到此问题,可以可以使用command
模块手动创建virtualenv:
If you experience that problem, you can create the virtualenv manually with the command
module:
- name: Manually create the initial virtualenv
command:
cmd: virtualenv /user/home/venvs/myenv -p python3.4
creates: "/user/home/venvs/myenv"
(注意:通过指定creates
,此命令仅在/user/home/venvs/myenv
上不存在virtualenv的情况下运行).
(note: by specifying creates
this command will only run in the case that a virtualenv does not exist at /user/home/venvs/myenv
).
然后,您可以使用pip
命令正常安装需求:
Then you can install your requirements as normal with the pip
command:
- name: Install requirements
pip:
requirements=/my_app/requirements.txt
virtualenv=/user/home/venvs/myenv
更新
我发现指定virtualenv_python
(在Ansible 2.0+中可用)在上述情况下似乎也可行.例如:
I've found that specifying the virtualenv_python
(available in Ansible 2.0+) also seems to work in the case stated above. For example:
- name: Install requirements
pip:
requirements: /my_app/requirements.txt
virtualenv: /user/home/venvs/myenv
virtualenv_python: python3.4
(有了这个,您不必首先手动创建virtualenv)
(with this you shouldn't need to manually create the virtualenv first)
这篇关于Ansible创建一个virtualenv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!