Where are you specifying the vm_name in vmware_vm_info? ansible-doc shows 
this is a required parameter.

*- name: Gather one specific VM*
*  community.vmware.vmware_vm_info:*
*    hostname: '{{ vcenter_hostname }}'*
*    username: '{{ vcenter_username }}'*
*    password: '{{ vcenter_password }}'*
*    vm_name: 'vm_name_as_per_vcenter'*
*  delegate_to: localhost*
*  register: vm_info*

In your example you would need to use "{{ vm_name }}" as the value of the 
vm_name parameter.

*- name: Gather one specific VM*
*  community.vmware.vmware_vm_info:*
*    hostname: '{{ vcenter_hostname }}'*
*    username: '{{ vcenter_username }}'*
*    password: '{{ vcenter_password }}'*
*    vm_name: '{{ vm_name }}'*
*  delegate_to: localhost*
*  register: vm_info*

--
Walter Rowe, Chief
Infrastructure Services
Office of Information Systems Management
National Institute of Standards and Technology
United States Department of Commerce
On Tuesday, August 2, 2022 at 11:55:51 AM UTC-4 [email protected] 
wrote:

> 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/8c826300-f0c1-4d30-927d-b072cdcc8b57n%40googlegroups.com.

Reply via email to