来自 virtualenv 的 Ansible 命令? [英] Ansible command from inside virtualenv?

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

问题描述

这看起来应该很简单:

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 的 activate 脚本,否则该命令不会成功,并且 Ansible 命令模块.

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 的 Ansible 命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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