The original playbook is like this:
- debug:
msg:
- "{{ intvlan.results[0].cde }}"
- "{{ intvlan.results[1].cde }}"
- "{{ intvlan.results[2].cde }}"
- "{{ intvlan.results[3].cde }}"
And I want to change it into a loop.
So, I changed the code as below:
vars:
package:
- { iterations: '1'}
- { iterations: '2'}
- { iterations: '3'}
- { iterations: '4'}
tasks:
- debug:
msg:
- "{{ intvlan.results[{{ item.iterations }}].cde }}"
- "{{ intvlan.results[{{ item.iterations }}].cde }}"
- "{{ intvlan.results[{{ item.iterations }}].cde }}"
- "{{ intvlan.results[{{ item.iterations }}].cde }}"
loop: "{{ package }}"
And I've got the msg as below:
The error was: 'list object' has no attribute '{{item.iterations}}
What is the problem?