从virtualenv内部发出命令吗? [英] Ansible command from inside virtualenv?

查看:62
本文介绍了从virtualenv内部发出命令吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎应该很简单:

tasks:
- name: install python packages
  pip: name=${item} virtualenv=~/buildbot-env
  with_items: [ buildbot ]
- name: create buildbot master
  command: buildbot create-master ~/buildbot creates=~/buildbot/buildbot.tac

但是,除非首先获得virtualenv的激活脚本,否则该命令将不会成功,并且

However, the command will not succeed unless the virtualenv's activate script is sourced first, and there doesn't seem to be provision to do that in the Ansible command module.

我尝试用各种.profile,.bashrc,.bash_login等来获取激活脚本,但是没有运气.另外,也有shell命令,但这似乎有点尴尬:

I've experimented with sourcing the activate script in various of .profile, .bashrc, .bash_login, etc, with no luck. Alternatively, there's the shell command, but it seems like kind of an awkward hack:

- name: create buildbot master
  shell: source ~/buildbot-env/bin/activate && \
         buildbot create-master ~/buildbot \
         creates=~/buildbot/buildbot.tac executable=/bin/bash

有更好的方法吗?

推荐答案

更好的方法是使用已安装脚本的完整路径-它会自动在virtualenv中运行:

The better way is to use the full path to installed script - it will run in its virtualenv automatically:

tasks:
- name: install python packages
  pip: name={{ item }} virtualenv={{ venv }}
  with_items: [ buildbot ]
- name: create buildbot master
  command: "{{ venv }}/bin/buildbot create-master ~/buildbot
            creates=~/buildbot/buildbot.tac"

这篇关于从virtualenv内部发出命令吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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