我想通过ansible用virtualenvwrapper创建一个virtualenv 我的默认变种:
wrapper_bin: '/usr/local/bin/virtualenvwrapper.sh'
virtualenv_dir: '/home/user/.envs'
{{ project_name }}
来自额外的变量
我的任务:
---
- name: Make a virtualenv
shell: "{{ wrapper_bin }} && mkvirtualenv {{ project_name }}"
args:
executable: /bin/bash
creates: "{{ virtualenv_dir}}/{{ project_name }}"
在远程机器上一切正常
which virtualenvwrapper.sh
返回正确的方式/usr/local/bin/virtualenvwrapper.sh
但Ansible抛出错误/bin/bash: mkvirtualenv: command not found
答案 0 :(得分:2)
将PATH
添加到环境中,例如:
---
- name: Make a virtualenv
shell: "{{ wrapper_bin }} && mkvirtualenv {{ project_name }}"
args:
executable: /bin/bash
creates: "{{ virtualenv_dir}}/{{ project_name }}"
environment:
path: /usr/local/bin:/usr/bin:/bin
这是Ansible最常见的问题之一 - 它运行shell非交互式,非登录会话,通过shell设计不会获取所有rc文件。结果,以交互方式登录时PATH
PATH
,apply plugin: 'com.lazan.javaflavours'
javaFlavours {
flavour 'tool1'
flavour 'tool2'
}
dependencies {
compile 'a:a:1.0' // common to all tools
compileTool1 'b:b:2.0' // compile deps for tool1 only
runtimeTool2 'c:c:2.0' // runtime deps for tool2 only
}
Ansible在其环境中的位置不同。
答案 1 :(得分:0)
- name: Make a virtualenv
shell: export PATH=$PYENV_ROOT/bin:$PATH mkvirtualenv {{ project_name }}
如果您使用pyenv。
答案 2 :(得分:0)
这对我有用
- name: Create the required virtualenv
shell: |
export WORKON_HOME="{{ virtualenv_dir }}"
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
. /usr/local/bin/virtualenvwrapper.sh
mkvirtualenv "{{project_name}}" -p python3.6
args:
executable: /bin/bash
creates: "{{ virtualenv_dir}}/{{ project_name }}"
register: appServer_virtualenv
become_user: "{{sudo_user}}"