[ansible-project] Re: help on loop over list of dicts

2015-12-10 Thread Mgsz
Thank you Mike for the reply!
One of my co-worker helped me out. Basically, I was using nested with_items 
in two playbook.
I have playbook1 running with_items to include playbook2 with tasks which 
also trying to use with_items, so it failed in the 2nd playbook which the 
with_items are not looping using new value, still using the items in 
playbook1.

Ansible team, is what I described correct? I think I may need to redo the 
playbook with with_nested see if I can make it work. 


On Thursday, December 10, 2015 at 8:16:05 AM UTC-8, Mike Biancaniello wrote:

> 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=2changed=0unreachable=0failed=
> 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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ce5f9a1b-d805-4bdf-9330-57f36b76e784%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] help on loop over list of dicts

2015-12-09 Thread Mgsz
Error when try to iterate a list:
This is what I am using in the playbook:
...
  - debug: msg="{{ dev_interfaces[0].name }}"

  - name: debug message interface name
debug: msg="{{item.name}}"
with_items: "{{ dev_interfaces }}"
...

When executing, the loop always get error, any suggestion?

TASK [debug msg={{ dev_interfaces[0].name }}] 
ok: [10.3.146.113] => {
"changed": false,
"invocation": {
"module_args": {
"msg": "Ethernet0"
},
"module_name": "debug"
},
"msg": "Ethernet0"
}
TASK [debug message interface name] **
fatal: [10.3.146.113]: FAILED! => {"failed": true, "msg": "ERROR! dict 
object has no element {u'subnet': u'10.0.0.0/31', u'peer_addr': 
u'10.0.0.1', u'name': u'Ethernet0', u'mask': u'255.255.255.254', 
u'prefixlen': 31, u'addr': u'10.0.0.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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a25eb6e2-154f-4b4c-892c-e2304da50973%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] help on my loop issue

2015-12-09 Thread Mgsz
pretty new to Ansible, here is my problem, could anyone help?
Thanks!!

within my playbook, I have following tasks:

- debug: msg="{{ dev_interfaces[0].name }}"
- name: debug message interface name
  debug: var=item
  with_items: dev_interfaces

When run the playbook:
TASK [debug msg={{ dev_interfaces[0].name }}] 
ok: [10.3.146.113] => {
"changed": false,
"msg": "Ethernet0"
}
TASK [debug message interface name] **
fatal: [10.3.146.113]: FAILED! => {"failed": true, "msg": "ERROR! dict 
object has no element {u'subnet': u'10.0.0.0/31', u'peer_addr': 
u'10.0.0.1', u'name': u'Ethernet0', u'mask': u'255.255.255.254', 
u'prefixlen': 31, u'addr': u'10.0.0.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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/09561b31-79c3-45a7-bcfd-d3d90272d1ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.