Need help with Ansible loop

Hi All,

I have following code to call another file find_elements.yaml from my current playbook.

calling from my current playbook

  • include: find_elements.yaml
    loop:
    -“{{ vardata.L2.0 }}”
    -“{{ vardata.L2.1 }}”
    –“{{ vardata.L2.1 }}”
    loop_control:
    loop_var: testing

My question is when I run this code I get expected out where the loop get executed 3 times.
However I want to put these 3 statements in a loop such as
-“{{ vardata.L2.[some variable]}}”
and increment counter until the condition is met which is 3 times if I have 3 elements in list , 10 times if I have 10 elements in list.
However when I do this this get executed only once and no way I can find to increment the counter and run the loop multiple times.
Not sure what will be the syntax for the variable inside the loop
Any body can help.

Thanks
Vikas.

Hi All,

I have following code to call another file find_elements.yaml from my current playbook.

calling from my current playbook
- include: find_elements.yaml
loop:
-"{{ vardata.L2.0 }}"
-"{{ vardata.L2.1 }}"
--"{{ vardata.L2.1 }}"
loop_control:
loop_var: testing

My question is when I run this code I get expected out where the loop get executed 3 times.
However I want to put these 3 statements in a loop such as
-"{{ vardata.L2.[some variable]}}"
and increment counter until the condition is met which is 3 times if I have 3 elements in list , 10 times if I have 10
elements in list.
However when I do this this get executed only once and no way I can find to increment the counter and run the loop
multiple times.
Not sure what will be the syntax for the variable inside the loop
Any body can help.

What about sharing the real playbook and explain why you need this loop setup? So far I can not see
the logic in your example and your description.

Regards
         Racke

Sure,

So i have excel file from where I am reading the file and populating the variables files called iterate.yaml which puts it in dictionary of list with each excel row values as a list of elements

Iterate.yaml

Sure,

So i have excel file from where I am reading the file and populating the variables files called iterate.yaml which puts
it in dictionary of list with each excel row values as a list of elements

Iterate.yaml
--
data:
- Name: person1
Age:20
description: test1
- Name: person2
Age:30
description: test2
- Name: person3
Age:40
description: test3

It looks to me that your playbook is way too complicated.

Getting to your output below should be as simple as follows (regardless of the number entries in data):

- debug:
     msg: |
       {{ item.Name }}
       {{ item.Age }}
       {{ item.description }}
   with_items: "{{ vardata.data }}"

Regards
         Racke

Thanks a lot as this fixed the issue.

Regards
Vikas.