Thanks for the Reply Valdo

I get error 

TASK [debug] 
*********************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "'str object' has no attribute 
'guest_name'"}




On Saturday, April 11, 2020 at 10:02:06 PM UTC-7, Vladimir Botka wrote:
>
> On Sat, 11 Apr 2020 21:26:28 -0700 (PDT) 
> Kiran Kumar <[email protected] <javascript:>> wrote: 
>
> > In jason query how can i add regular expression ? eg if have vm1, 
> vm2,vm3 
> > below query can be adjusted ? eg       query: "[?guest_name == 'vm*' ]" 
> , 
> > seems does not work in below case 
> > 
> > >   tasks: 
> > >   - 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 }}" 
> > >     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 }}" 
>
> I'm not aware of regex in JMESPath. 
> https://jmespath.readthedocs.io/en/latest/ 
>
> HTH, 
>
>         -vlado 
>

-- 
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/f8d929f8-116c-4574-a782-29fbe6639240%40googlegroups.com.

Reply via email to