在远程机器上总是运行virtualenv的最佳方式?

是否有更好的方法在远程机器上运行virtualenv?

到目前为止,我可以看到的是修改.bashrc文件,手动或通过合理的方式修改。

例如:

 tasks:
    - name: "Enable virtualenv in .bashrc"
      lineinfile: dest=.bashrc
                  line="source {{ PROJECT_HOME }}/venv/bin/activate"

    #
    # Put tasks that rely on this precondition here (?)
    #

    # Optionally, disable this later on
    - name: "Disable virtualenv in .bashrc"
      lineinfile: dest=.bashrc
                  line="source {{ PROJECT_HOME }}/venv/bin/activate"
                  state=absent

TODO:检查使用ssh授权密钥可以完成的方式:http://binblog.info/2008/10/20/openssh-going-flexible-with-forced-commands/


这是一种为整个游戏启用virtualenv的方法; 这个例子在一个游戏中构建了virtualenv,然后开始使用它。

不知道它是多么干净,但它的工作原理。 我只是在这里提到的mikepurvis上构建一点。

---
# Build virtualenv
- hosts: all
vars:
  PROJECT_HOME: "/tmp/my_test_home"
  ansible_python_interpreter: "/usr/local/bin/python"
tasks:
  - name: "Create virtualenv"
    shell: virtualenv "{{ PROJECT_HOME }}/venv"
           creates="{{ PROJECT_HOME }}/venv/bin/activate"

  - name: "Copy virtualenv wrapper file"
    synchronize: src=pyvenv
                 dest="{{ PROJECT_HOME }}/venv/bin/pyvenv"

# Use virtualenv
- hosts: all
vars:
  PROJECT_HOME: "/tmp/my_test_home"
  ansible_python_interpreter: "/tmp/my_test_home/venv/bin/pyvenv"
tasks:
  - name: "Guard code, so we are more certain we are in a virtualenv"
    shell: echo $VIRTUAL_ENV
    register: command_result
    failed_when: command_result.stdout == ""

pyenv包装文件:

#!/bin/bash
source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/activate"
python $@
链接地址: http://www.djcxy.com/p/17915.html

上一篇: Best way to always run ansible inside a virtualenv on remote machines?

下一篇: source:' of an external page?