I have an Ansible playbook that includes a file twice and passes in a parameter to change the behavior:
site.yml:
---
- tasks:
- include: test.yml parm=AAA
- include: test.yml parm=BBB
The include file just prints the parameter value:
test.yml:
- debug: msg="dbg 1 {{ parm }}"
The inventory file is set to run on localhost:
inventory:
localhost ansible_connection=local
The result is what I expect, the include file runs twice, once with parm=AAA and once with parm=BBB:
>ansible-playbook -i inventory site.yml
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [include parm=AAA] ********************************************************
included: test.yml for localhost
TASK [debug msg=dbg 1 {{ parm }}] **********************************************
ok: [localhost] => {
"changed": false,
"msg": "dbg 1 AAA"
}
TASK [include parm=BBB] ********************************************************
included: test.yml for localhost
TASK [debug msg=dbg 1 {{ parm }}] **********************************************
ok: [localhost] => {
"changed": false,
"msg": "dbg 1 BBB"
}
PLAY RECAP *********************************************************************
localhost : ok=5 changed=0 unreachable=0 failed=0
Great. Now I need to do a second task in the include file:
test.yml:
- debug: msg="dbg 1 {{ parm }}"
- debug: msg="dbg 2 {{ parm }}"
What I expect is that the include file will be executed twice, just as before, first doing the original 'dbg 1 AAA' task and then the new 'dbg 2 AAA' task, and then second doing the original 'dbg 1 BBB' task and then the new 'dbg 2 BBB' task.
It does this instead:
>ansible-playbook -i inventory site.yml
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [include parm=AAA] ********************************************************
included: test.yml for localhost
TASK [debug msg=dbg 1 {{ parm }}] **********************************************
ok: [localhost] => {
"changed": false,
"msg": "dbg 1 AAA"
}
TASK [debug msg=dbg 2 {{ parm }}] **********************************************
ok: [localhost] => {
"changed": false,
"msg": "dbg 2 AAA"
}
PLAY RECAP *********************************************************************
localhost : ok=4 changed=0 unreachable=0 failed=0
It has skipped the second include. I thought that perhaps there was a problem including the same file multiple times, so I duplicated the include file with a new name:
test2.yml:
- debug: msg="dbg 1 {{ parm }}"
- debug: msg="dbg 2 {{ parm }}"
And adjust the playbook to include that instead:
site.yml:
---
- tasks:
- include: test.yml parm=AAA
- include: test2.yml parm=BBB
Then if test.yml has only one task, I get the expected result:
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [include parm=AAA] ********************************************************
included: test.yml for localhost
TASK [debug msg=dbg 1 {{ parm }}] **********************************************
ok: [localhost] => {
"changed": false,
"msg": "dbg 1 AAA"
}
TASK [include parm=BBB] ********************************************************
included: test2.yml for localhost
TASK [debug msg=dbg 1 {{ parm }}] **********************************************
ok: [localhost] => {
"changed": false,
"msg": "dbg 1 BBB"
}
TASK [debug msg=dbg 2 {{ parm }}] **********************************************
ok: [localhost] => {
"changed": false,
"msg": "dbg 2 BBB"
}
PLAY RECAP *********************************************************************
localhost : ok=6 changed=0 unreachable=0 failed=0
But if test.yml has two tasks, it skips the second include:
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [include parm=AAA] ********************************************************
included: test.yml for localhost
TASK [debug msg=dbg 1 {{ parm }}] **********************************************
ok: [localhost] => {
"changed": false,
"msg": "dbg 1 AAA"
}
TASK [debug msg=dbg 2 {{ parm }}] **********************************************
ok: [localhost] => {
"changed": false,
"msg": "dbg 2 AAA"
}
PLAY RECAP *********************************************************************
localhost : ok=4 changed=0 unreachable=0 failed=0
What am I missing? There are no errors or failures, and the two lines in the include file are nearly identical. Why does having more than one line in the first include file cause the second include to be skipped?
If I add more debug lines to the playbook:
site.yml:
---
- tasks:
- include: test.yml parm=AAA
- debug: msg="1"
- include: test2.yml parm=BBB
- debug: msg="2"
- debug: msg="3"
The debug messages are output only if the include file that preceeds them have exactly one line.
I am running Ansible from git://github.com/ansible/ansible.git devel branch, updated immediately before testing this.