如何在ansible_python_interpreter变量中使用${USER}?
在deploy.yml中,我有几个任务,第一个任务将python安装到/local/${USER}/venv中。后续任务应该使用已安装的python,而不是我自己的env。我试过不同的组合,这些组合都不起作用。
deploy.yml
- name: use installed python
host: localhost
vars_files:
- settings.yml
vars:
# commented items did not work neither here nor in settings.yml
# ansible_python_interpreter: "/local/{{lookup('env', 'USER')}}/venv/bin/python"
# ansible_python_interpreter: "/local/${USER}/venv/bin/python"
# venv_dir defined in settings.yml
# ansible_python_interpreter: "{{venv_dir}}/bin/python"
# hardcoded worked:
ansible_python_interpreter: "/local/myuser/bin/python"这个错误类似于:
"/bin/sh: {{venv_dir}}/bin/python: No such file or directory\n"
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "/bin/sh: {{venv_dir}}/bin/python: No such file or directory\n", "module_stdout": "", "msg": "MODULE FAILURE"}settings.yml:
---
root_dir: "/local/{{lookup('env', 'USER')}}"
venv_dir: "{{root_dir}}/venv/"注意:将ansible_python_interpreter迁移到settings.yml没有帮助。
我是不是遗漏了什么?
发布于 2017-08-16 18:45:25
我想ansible_python_interpreter不是在引擎盖下做模板的。
您可以使用set_fact解决方案:
---
- hosts: localhost
gather_facts: false
tasks:
# default Python here
- shell: echo hello
- set_fact:
ansible_python_interpreter: /local/{{lookup('env', 'USER')}}/venv/bin/python
# modified Python here
- shell: echo hello发布于 2020-04-14 04:39:29
全局情况下,在interpreter_python的[defaults]部分使用ansible.cfg键
解释器_python=/usr/bin/python2.7
https://stackoverflow.com/questions/45719279
复制相似问题