On Sat, 11 Apr 2020 21:26:28 -0700 (PDT) Kiran Kumar <[email protected]> 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/20200412070147.05c65041%40gmail.com.
pgpGeHxUxSg7J.pgp
Description: OpenPGP digital signature
