Thanks for your reply Valdo. This is a JSON output 

            {
                "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": []
                    }


I am reading about - selectattr - as i am new to this. 

Thanks 

On Sunday, April 12, 2020 at 12:01:30 AM UTC-7, Vladimir Botka wrote:
>
> On Sat, 11 Apr 2020 23:35:16 -0700 (PDT) 
> Kiran Kumar <esxi...@gmail.com <javascript:>> wrote: 
>
> > I get error 
> > TASK [debug] 
> ***********************************************************************************************************************>
>  
>
> fatal: [localhost]: FAILED! => {"msg": "'str object' has no attribute 
> > 'guest_name'"} 
>
> Take a look at the structure of "vm_fact" and fix it. If you still have 
> issues 
> post: 
>
>     - debug: 
>         var: vm_fact 
>
> > On Saturday, April 11, 2020 at 10:02:06 PM UTC-7, Vladimir Botka wrote: 
> > > > >   - debug: 
> > > > >       msg:  "{{ item.ip_address }}" 
> > > > >     with_items: 
> > > > >     - "{{ vm_facts.virtual_machines | json_query(query) }}" 
> > > > >     vars: 
> > > > >       query: "[?guest_name == 'vm1' ]"     
> > > 
> > > Filter "selectattr" should do the job. For example 
> > > 
> > >     - debug: 
> > >         msg: "{{ item.ip_address }}" 
> > >       loop: "{{ vm_facts| 
> > >                 selectattr('guest_name', 'match', '^vm1$')| 
> > >                 list }}" 
> > >     - debug: 
> > >         msg: "{{ item.ip_address }}" 
> > >       loop: "{{ vm_facts| 
> > >                 selectattr('guest_name', 'match', '^vm(.*)$')| 
> > >                 list }}" 
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/999e1b69-c255-473f-8cdc-d9ae33748195%40googlegroups.com.

Reply via email to