我希望使用ansible在虚拟环境中执行
python setup.py develop
命令。
应该像这样实现:- name: egg
shell: "python setup.py develop"
但我需要在virtualenv中执行它。我该怎么做?
一种方法是从虚拟环境的bin目录调用Python。
- name: egg
shell: "/path/to/env/bin/python setup.py develop"
我通常使用 pip -e
的方式,通过 pip 命令 (它确保存在一个virtualenv
),并使用 extra_args
参数添加 -e
。例如:
- name: install MYPACKAGE in VIRTUALENV
pip: name='PATH TO MYPACKAGE'
extra_args='-e' # this creates a link rather then copying the files
virtualenv='PATH OF YOUR VIRTUALENV' # will be created if does not exist
如果需要指定如何执行 virtualenv
脚本,可以选择添加选项,例如:如果需要使用 python3
,则添加:
virtualenv_command='python3 /PATH_TO_VENV/virtualenv.py'
editable
参数: - name: install MYPACKAGE in VIRTUALENV
pip:
name: 'PATH TO MYPACKAGE'
editable: true
virtualenv: 'PATH TO YOUR VIRTUALENV' # will be created if does not exist
- name: chained shell command
shell: "source /path/to/env/bin/activate; python setup.py develop"