Difference between revisions of "Nested looping in ansible (loop inside loop)"
(Created page with "<yambe:breadcrumb>Ansible_tips_and_tricks|Ansible tips and tricks</yambe:breadcrumb> =Nested looping in ansible (loop inside loop)= For nested looping in ansible at least two...") |
m |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[System administration tools]] > [[Ansible|ansible]] > [[Ansible tips and tricks]] > [[Ansible lookup plugins]] > [[Nested looping in ansible (loop inside loop)]] | |||
For nested looping in ansible at least two lists are required. Then for each item of first list, one item from second list can be obtained. Thus if two lists have m and n values. Then total m*n operations can be performed. For nested looping use 'with_nested' similar to shown below: | For nested looping in ansible at least two lists are required. Then for each item of first list, one item from second list can be obtained. Thus if two lists have m and n values. Then total m*n operations can be performed. For nested looping use 'with_nested' similar to shown below: | ||
Line 20: | Line 19: | ||
- list2 | - list2 | ||
</pre> | </pre> | ||
Learned from ansible-examples github repo at https://github.com/ansible/ansible-examples/blob/master/language_features/loop_nested.yml | |||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[System administration tools]] > [[Ansible|ansible]] > [[Ansible tips and tricks]] > [[Ansible lookup plugins]] > [[Nested looping in ansible (loop inside loop)]] |
Latest revision as of 11:51, 28 July 2022
Home > CentOS > CentOS 6.x > System administration tools > ansible > Ansible tips and tricks > Ansible lookup plugins > Nested looping in ansible (loop inside loop)
For nested looping in ansible at least two lists are required. Then for each item of first list, one item from second list can be obtained. Thus if two lists have m and n values. Then total m*n operations can be performed. For nested looping use 'with_nested' similar to shown below:
--- - name: Demo of with_nested hosts: all remote_user: root vars: list1: [1, 2, 3] list2: [a, b, c, d] tasks: - name: Printing message debug: msg="Values are {{item[0]}} and {{item[1]}}" with_nested: - list1 - list2
Learned from ansible-examples github repo at https://github.com/ansible/ansible-examples/blob/master/language_features/loop_nested.yml
Home > CentOS > CentOS 6.x > System administration tools > ansible > Ansible tips and tricks > Ansible lookup plugins > Nested looping in ansible (loop inside loop)