Ansible multiple include with multiple tasks? -


i have ansible playbook includes file twice , passes in parameter change behavior:

site.yml:

--- - tasks:   - include: test.yml parm=aaa   - include: test.yml parm=bbb 

the include file prints parameter value:

test.yml:

- debug: msg="dbg 1 {{ parm }}" 

the inventory file set run on localhost:

inventory:

localhost ansible_connection=local 

the result expect, include file runs twice, once parm=aaa , once parm=bbb:

>ansible-playbook -i inventory site.yml  play ***************************************************************************  task [setup] ******************************************************************* ok: [localhost]  task [include parm=aaa] ******************************************************** included: test.yml localhost  task [debug msg=dbg 1 {{ parm }}] ********************************************** ok: [localhost] => {     "changed": false,      "msg": "dbg 1 aaa" }  task [include parm=bbb] ******************************************************** included: test.yml 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. need second task in include file:

test.yml:

- debug: msg="dbg 1 {{ parm }}" - debug: msg="dbg 2 {{ parm }}" 

what expect include file executed twice, before, first doing original 'dbg 1 aaa' task , new 'dbg 2 aaa' task, , second doing original 'dbg 1 bbb' task , new 'dbg 2 bbb' task.

it instead:

>ansible-playbook -i inventory site.yml  play ***************************************************************************  task [setup] ******************************************************************* ok: [localhost]  task [include parm=aaa] ******************************************************** included: test.yml 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 second include. thought perhaps there problem including same file multiple times, duplicated include file new name:

test2.yml:

- debug: msg="dbg 1 {{ parm }}" - debug: msg="dbg 2 {{ parm }}" 

and adjust playbook include instead:

site.yml:

--- - tasks:   - include: test.yml parm=aaa   - include: test2.yml parm=bbb 

then if test.yml has 1 task, expected result:

play ***************************************************************************  task [setup] ******************************************************************* ok: [localhost]  task [include parm=aaa] ******************************************************** included: test.yml localhost  task [debug msg=dbg 1 {{ parm }}] ********************************************** ok: [localhost] => {     "changed": false,      "msg": "dbg 1 aaa" }  task [include parm=bbb] ******************************************************** included: test2.yml 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 2 tasks, skips second include:

play ***************************************************************************  task [setup] ******************************************************************* ok: [localhost]  task [include parm=aaa] ******************************************************** included: test.yml 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 missing? there no errors or failures, , 2 lines in include file identical. why having more 1 line in first include file cause second include skipped?

if add more debug lines 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 output if include file preceeds them have 1 line.

i running ansible git://github.com/ansible/ansible.git devel branch, updated before testing this.

the problem first appears in git here.

this optimization causes problem.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -