On Tue, 2 Aug 2022 at 14:28, 'Pugazhendhi Ramakrishnan' via Ansible Project
<[email protected]> wrote:
> I'm using the "vmware_vm_info" module to fetch the VM name with the below
> playbook and it is working fine but if I try to add the
> ?guest_name=='vm_name' as variable it is not working. Can you please
> suggest how to generalize the play by adding the variable to the
> guestn_name?
> ---
> - name: Check if the VM existing the Vcenter
> hosts: localhost
> vars_files: 1credentials.yml
> vars:
> vm_name: server2
> tasks:
> - name: Checking VM details
> block:
> - name: Get virtual machine info
> vmware_vm_info:
> hostname: '{{ vcenter_hostname }}'
> username: '{{ vcenter_username }}'
> password: '{{ vcenter_password }}'
> validate_certs: no
> delegate_to: localhost
> register: vm_info
>
> - debug:
> msg: "{{ item.guest_name }}"
> with_items:
> - "{{ vm_info.virtual_machines | json_query(query) }}"
> vars:
> query: "[?guest_name=='server2']"
>
Try backticks:
query: "[?guest_name==`server2`]"
--
> 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/7291198e-2913-4dff-9aab-d8dba4a3d9f5n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/7291198e-2913-4dff-9aab-d8dba4a3d9f5n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
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/CAF8BbLbCe7tUoVbNESbGmNfgjDBgcREqBz3RrHKrxZ_rFwRaPQ%40mail.gmail.com.