前提・実現したいこと
Ansibleで{{ ansible_env.HOME }}がundefinedとなって使うことができていません。{{ ansible_env.HOME }}を使うためには、何かおまじないが必要なんでしょうか?
発生している問題・エラーメッセージ
fatal: [hostname]: FAILED! => { "msg": "The task includes an option with an undefined variable. The error was: 'ansible_env' is undefined\n\nThe error appears to have been in 'debug.yml': line 7, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: print HOME environment variable\n ^ here\n" }
該当のソースコード
yml
1- hosts: all 2 gather_facts: false 3 remote_user: <username> 4 become: yes 5 become_method: sudo 6 tasks: 7 - name: print HOME environment variable 8 debug: msg={{ ansible_env.HOME }}
試したこと
<hostname>に変数があることは確認しました
bash
1$ ansible <hostname> -m setup 2<hostname> | SUCCESS => { 3 "ansible_facts": { 4(中略) 5 "ansible_env": { 6 "HOME": "/home/<username>", 7(以下省略)
lookup pluginでは取得できました。
yml
1- hosts: all 2 gather_facts: false 3 remote_user: <username> 4 become: yes 5 become_method: sudo 6 vars: 7 local_home: "{{ lookup('env', 'HOME') }}" 8 tasks: 9 - name: print HOME env var 10 debug: msg="{{local_home}}"
補足情報(FW/ツールのバージョンなど)
- ansible: 2.7.5
- target os: ubuntu 14.04
- host os: ubuntu 18.04
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/02 06:18