这看起来应该非常简单:
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 command module中似乎没有提供执行此操作的条件。
我已经尝试过在各种.profile,.bashrc,.bash_login等资源中获取激活脚本,但是没有运气。另外,还有shell命令,但看起来有点笨拙:
- name: create buildbot master
shell: source ~/buildbot-env/bin/activate && \
buildbot create-master ~/buildbot \
creates=~/buildbot/buildbot.tac executable=/bin/bash
有没有更好的办法?
最佳答案
更好的方法是使用安装脚本的完整路径-它会自动在virtualenv中运行:
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"