get item from nested loop item

18 views
Skip to first unread message

Vaishnave M

unread,
Nov 1, 2023, 9:35:35 AM11/1/23
to Ansible Project
Hi,

I have list of items in configuration files as variable

hostenv:
   - env: test
   Serverconf:
        Resource:
          - mem:
        Interface:
          - { name: eth0, address: 10.0.10.2}
          - {eth1: .....}
 
Now, I would like to fetch and print the values from interface {{ item.address }} 

I tried to loop  multiple usecase, but failed with object undefined error

Playbook:
task:
  - debug:
      msg: {{ item.address }}
    loop: {{ hostenv.Serverconf.Interface }}
      loop_var: item

Thanks


Todd Lewis

unread,
Nov 1, 2023, 10:13:28 AM11/1/23
to Ansible Project
It's hard to tell from this platform's poor support of indentation, but it appears "hostenv" is a list. Try
    loop: "{{ hostenv[0].Serverconf.Interface }}"
Reply all
Reply to author
Forward
0 new messages