ansibleのset_factで宣言した変数は、同じset_fact内では参照できない
下記のようなplaybookを作って実行したところ、
- hosts: - localhost connection: local become: False gather_facts: False tasks: - set_fact: aaa="naked" bbb="{{ aaa }}"
undefined variableとか言われちゃって、エラーになっちゃいます。
# ansible-playbook test.yml ... TASK [set_fact] ******************************************************** fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'aaa' is undefined\n\nThe error appears to have been in '/home/naked123/test.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 - set_fact:\n ^ here\n"}
うーん、 aaa
は直前で宣言してるんだけどなぁ。
しょうがないので、下記のようにset_factを2つ使うとエラーは無くなりました。
- hosts: - localhost become: False gather_facts: False connection: local tasks: - set_fact: aaa="naked" - set_fact: bbb="{{ aaa }}"
かっこ悪いなぁ。