Ansible创建一个virtualenv [英] Ansible creating a virtualenv

查看:147
本文介绍了Ansible创建一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆