What is the difference between the following syntaxes?
=== 1st scenario
outside.yaml:
---
- include: inside.yaml
vars:
my_inner_item: "{{ item }}"
with_items:
- A
- B
- C
inside.yaml:
---
- debug: msg="{{my_inner_item}} with {{ item }} is defined"
with_items:
- 1
- 2
- 3
=== 2nd scenario
outside.yaml:
---
- include: inside.yaml
with_items:
- A
- B
- C
inside.yaml:
---
- set_fact
my_inner_item={{item}}
- debug: msg="{{my_inner_item}} with {{ item }} is defined"
with_items:
- 1
- 2
- 3
=== 3rd Scenario:
outside.yaml:
---
- include: inside.yaml my_inner_item={{item}}
with_items:
- A
- B
- C
inside.yaml:
---
- debug: msg="{{my_inner_item}} with {{ item }} is defined"
with_items:
- 1
- 2
- 3
… I do not list the old “loop_control” scenario…
By the way: there is an existing issue connected to this topic:
https://github.com/ansible/ansible/issues/14146
I think I messed up something
This way my examples are more easy to understand:
=== 1st scenario
outside.yaml:
---
- include: inside.yaml
vars:
my_outer_item: "{{ item }}"
with_items:
- A
- B
- C
inside.yaml:
---
- debug: msg="{{my_outer_item}} with {{ item }} is defined"
with_items:
- 1
- 2
- 3
=== 2nd scenario
outside.yaml:
---
- include: inside.yaml
with_items:
- A
- B
- C
inside.yaml:
---
- set_fact
my_outer_item={{item}}
- debug: msg="{{my_outer_item}} with {{ item }} is defined"
with_items:
- 1
- 2
- 3
=== 3rd Scenario:
outside.yaml:
---
- include: inside.yaml my_outer_item={{item}}
with_items:
- A
- B
- C
inside.yaml:
---
- debug: msg="{{my_outer_item}} with {{ item }} is defined"
with_items:
- 1
- 2
- 3
Sources:
http://docs.ansible.com/ansible/playbooks_loops.html#loops-and-includes-in-2-0
http://stackoverflow.com/questions/30785281/one-loop-over-multiple-ansible-tasks
https://github.com/ansible/ansible/issues/14146
But it would be good to get some clarification about the differences.
- július 7., csütörtök 10:04:03 UTC+2 időpontban Bence Takács a következőt írta:
Which one is the recommended way, and why?
- július 7., csütörtök 13:59:15 UTC+2 időpontban Bence Takács a következőt írta: