Not sure what you're doing wrong. Maybe it's the way you define
dev_interfaces (yeah, it makes no sense why it would work in debug, but not
in with_items, but sometimes that happens).
This worked for me:
---
- name: stuff
connection: local
gather_facts: no
hosts: localhost
vars:
dev_interfaces:
- subnet: 10.0.0.0/31
peer_addr: 10.0.0.1
name: Ethernet0
mask: 255.255.255.254
prefixlen: 31
addr: 10.0.0.0
tasks:
- debug: msg="{{ dev_interfaces[0].name }}"
- name: debug message interface name
debug: msg="{{item.name}}"
with_items: "{{ dev_interfaces }}"
output:
PLAY [stuff]
******************************************************************
TASK: [debug msg="{{ dev_interfaces[0].name }}"]
******************************
ok: [localhost] => {
"msg": "Ethernet0"
}
TASK: [debug message interface name]
******************************************
ok: [localhost] => (item={'subnet': '10.0.0.0/31', 'peer_addr': '10.0.0.1',
'name': 'Ethernet0', 'prefixlen': 31, 'mask': '255.255.255.254', 'addr':
'10.0.0.0'}) => {
"item": {
"addr": "10.0.0.0",
"mask": "255.255.255.254",
"name": "Ethernet0",
"peer_addr": "10.0.0.1",
"prefixlen": 31,
"subnet": "10.0.0.0/31"
},
"msg": "Ethernet0"
}
PLAY RECAP
********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/858a36b5-6dc1-43ee-a6b8-43f8f974e0b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.