2017-08-16 24 views
0

ansible_python_interpreter変数で$ {USER}を使用するにはどうすればよいですか?able_python_interpreter変数でenv変数を使用

deploy.ymlにはいくつかのタスクがあり、最初のタスクは/ local/$ {USER}/venvにpythonをインストールします。フォローアップタスクは私自身のenvからのものではなく、インストールされたpythonを使うべきです。 違う組み合わせを試しましたが、うまくいきませんでした。

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/" 

注:settings.ymlファイルにansible_python_interpreter移動しても解決しません。

何か不足していますか?

答えて

1

ansible_python_interpreterはフードの下にテンプレート化されていないと思います。

--- 
- 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 

あなたはset_fact回避策を使用することができます

関連する問題