Last active
August 14, 2018 19:15
-
-
Save buzztaiki/353a2c1363ed067a471752f3dda3e934 to your computer and use it in GitHub Desktop.
include_tasks と import_tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ANSIBLE_STDOUT_CALLBACK=default ansible-playbook test.yml | |
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' | |
PLAY [localhost] ***************************************************************************************************************************************************************************** | |
TASK [include_tasks] ************************************************************************************************************************************************************************* | |
included: /home/taiki/src/github.com/smartoperation/cobit/infra/aws-playbook/test2.yml for localhost | |
TASK [debug] ********************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": "import_tasks は変数の上書きはできない" | |
} | |
TASK [show arg and arg2] ********************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": "arg=hoge, arg2=this" | |
} | |
TASK [debug] ********************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": "import_tasks は変数の上書きはできないからこそ、二重評価もされない" | |
} | |
TASK [show arg and arg2] ********************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": "arg=hoge, arg2=that" | |
} | |
TASK [debug] ********************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": "include_tasks なら変数の上書きができる" | |
} | |
TASK [include_tasks] ************************************************************************************************************************************************************************* | |
included: /home/taiki/src/github.com/smartoperation/cobit/infra/aws-playbook/test3.yml for localhost | |
TASK [show arg and arg2] ********************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": "arg=what?, arg2=is" | |
} | |
TASK [debug] ********************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": "include_tasks で同じ変数を使うと recursive loop detected in template string でエラーになる" | |
} | |
PLAY RECAP *********************************************************************************************************************************************************************************** | |
localhost : ok=9 changed=0 unreachable=0 failed=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: localhost | |
connection: local | |
gather_facts: False | |
tasks: | |
- include_tasks: test2.yml | |
vars: | |
arg: hoge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- debug: | |
msg: import_tasks は変数の上書きはできない | |
- import_tasks: test3.yml | |
vars: | |
arg: what? | |
arg2: this | |
- debug: | |
msg: import_tasks は変数の上書きはできないからこそ、二重評価もされない | |
- import_tasks: test3.yml | |
vars: | |
arg: "{{ arg }}" | |
arg2: that | |
- debug: | |
msg: include_tasks なら変数の上書きができる | |
- include_tasks: test3.yml | |
vars: | |
arg: what? | |
arg2: is | |
- debug: | |
msg: include_tasks で同じ変数を使うと recursive loop detected in template string でエラーになる | |
# - include_tasks: test3.yml | |
# vars: | |
# arg: "{{ arg }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: show arg and arg2 | |
debug: | |
msg: "arg={{ arg }}, arg2={{ arg2 }}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
基本的に import_tasks は変数を指定しないで使うのがよいのだと思う。静的に解決するという意味でも。
include_tasks で使う変数は可能なら role と同様に prefix 付きにするのが良いのでしょう。