Ansible 创建 virtualenv [英] Ansible creating a virtualenv

查看:33
本文介绍了Ansible 创建 virtualenv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 ansible 为特定的 Python 版本创建 virtualenv.ansible标准库里有命令吗?

我想要类似的东西:

- virtualenv: dest=venv python_version:/usr/bin/python3

解决方案

我有时会在指定 virtualenv_command 时遇到一些不稳定的行为(例如:即使我指定了在我的 virtualenv 中获取 python 2.7 可执行文件使用 virtualenv-3.4 运行命令.

如果您遇到该问题,您可以使用command模块手动创建virtualenv:

- name:手动创建初始virtualenv命令:cmd: virtualenv/user/home/venvs/myenv -p python3.4创建:/user/home/venvs/myenv"

(注意:通过指定creates,此命令只会在/user/home/venvs/myenv 中不存在virtualenv 的情况下运行).

然后你可以像往常一样使用 pip 命令安装你的需求:

- 名称:安装要求点:要求=/my_app/requirements.txtvirtualenv=/user/home/venvs/myenv

更新

我发现指定 virtualenv_python(在 Ansible 2.0+ 中可用)似乎也适用于上述情况.例如:

- 名称:安装要求点:要求:/my_app/requirements.txt虚拟环境:/user/home/venvs/myenvvirtualenv_python:python3.4

(有了这个,你不需要先手动创建 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:

- virtualenv: dest=venv python_version:/usr/bin/python3

解决方案

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:

- name: Manually create the initial virtualenv
  command:
    cmd: virtualenv /user/home/venvs/myenv -p python3.4
    creates: "/user/home/venvs/myenv"

(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:

- name: Install requirements
  pip: 
    requirements=/my_app/requirements.txt 
    virtualenv=/user/home/venvs/myenv

Update

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

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

这篇关于Ansible 创建 virtualenv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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