No I mean, it is working if I give 'server2' but if I give the variable 
defined in the vars: section it is not working.

On Tuesday, August 2, 2022 at 9:17:18 PM UTC+5:30 [email protected] wrote:

> 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/a8f7e346-e94d-4dd4-a877-e916dd083e31n%40googlegroups.com.

Reply via email to