I would do this in a simpler way -

- name: Gather all VMs information
vmware_vm_info:
hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}'
password: '{{ vcenter_password }}'
validate_certs: no
register: vm_facts
delegate_to: localhost

- debug:
msg: "{{ item.ip_address }}"
loop: "{{ vm_facts.virtual_machines }}"
when:
- item.guest_name | regex_search('^vm')


On Sun, Apr 12, 2020 at 5:26 PM Vladimir Botka <[email protected]> wrote:

> On Sun, 12 Apr 2020 00:26:39 -0700 (PDT)
> Kiran Kumar <[email protected]> wrote:
>
> >             {
> >                 "attributes": {},
> >                 "cluster": "xx",
> >                 "esxi_hostname": "xx",
> >                 "guest_fullname": "Microsoftxx",
> >                 "guest_name": "xx",
> >                 "ip_address": "xx",
> >                 "mac_address": [
> >                     "xx"
> >                 ],
> >                 "power_state": "poweredOn",
> >                 "tags": [],
> >                 "uuid": "xx",
> >                 "vm_network": {
> >                     "xx": {
> >                         "ipv4": [
> >                             "xx"
> >                         ],
> >                         "ipv6": []
> >                     }
> >
> > > fatal: [localhost]: FAILED! => {"msg": "'str object' has no attribute
>
> > > > 'guest_name'"}
> > > > >
> > > > >     - debug:
> > > > >         msg: "{{ item.ip_address }}"
> > > > >       loop: "{{ vm_facts|
> > > > >                 selectattr('guest_name', 'match', '^vm(.*)$')|
> > > > >                 list }}"
>
> There shouldn't be any problem with the dictionary "vm_facts" you posted.
> The
> attribute "guest_name" is in place. I can't explain the error. It's up to
> you
> to fix the JSON paths.
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/20200412135631.0fd34f5a%40gmail.com
> .
>


-- 
Thanks,
Abhijeet Kasurde

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAFwWkHpcMQjZMaioZ6v%3Dc-8t%3D%3DwsmvuiUZRmriAt-HEiVYFhGw%40mail.gmail.com.

Reply via email to