Thanks Abhijeet !
On Friday, April 17, 2020 at 1:26:53 AM UTC-7, Abhijeet Kasurde wrote:
>
> ---
> - hosts: localhost
> vars_files:
> - vcenter_vars.yml
> vars:
> vm_list:
> - test01
> tasks:
> - name: Get information about the virtual machine
> vmware_guest_info:
> validate_certs: False
> hostname: '{{ vcenter_hostname }}'
> username: '{{ vcenter_username }}'
> password: '{{ vcenter_password }}'
> folder: /Asia-Datacenter1/vm/
> name: "{{ item }}"
> datacenter: Asia-Datacenter1
> register: vm_info
> with_items: "{{ vm_list }}"
>
> - name: Get Tools status
> set_fact:
> desired_vms: "{{ vm_info.results | json_query(jmesquery) }}"
> vars:
> jmesquery: "[?instance.guest_tools_status ==
> 'guestToolsNotRunning'].instance.hw_name"
>
> - name: Reboot the given VM
> vmware_guest_powerstate:
> validate_certs: False
> hostname: '{{ vcenter_hostname }}'
> username: '{{ vcenter_username }}'
> password: '{{ vcenter_password }}'
> folder: /Asia-Datacenter1/vm/
> name: "{{ item }}"
> state: 'reboot-guest'
> with_items: "{{ desired_vms }}"
>
>
>
> On Fri, Apr 17, 2020 at 1:00 PM Kiran Kumar <[email protected]
> <javascript:>> wrote:
>
>> Hi
>>
>>
>> I need to check status of VMware tools on vms & if VMware tools are not
>> running, then reboot the vm. I have below playbook which works fine to find
>> vm name & VMware tools status. Please help on how can i extract the vm name
>> & take action as per status.
>>
>> Note : i have to use the VMware modules as the OS typically will be in
>> hung status ( hence tools not running ) , hence avoid user OS level task (
>> and use VMware task )
>>
>> Thanks
>>
>> ---
>>> - hosts: localhost
>>> gather_facts: false
>>> connection: local
>>> collections:
>>> - community.vmware
>>> - community.general
>>> vars_files:
>>> - ./vars/vmware_vars.yml
>>> vars:
>>> vm_list:
>>> - vm1
>>> - vm2
>>> tasks:
>>> - name: Gather VM info
>>> vmware_guest_info:
>>> hostname: "{{ vcenter_server }}"
>>> username: "{{ vcenter_user }}"
>>> password: "{{ vcenter_pass }}"
>>> datacenter: "{{ vcenter_datacenter }}"
>>> validate_certs: no
>>> name: "{{ item }}"
>>> register: vm_info
>>> with_items: "{{ vm_list }}"
>>> - name: Tools status all
>>> debug:
>>> msg: "{{ vm_info.results | json_query(jmesquery) }}"
>>> vars:
>>> jmesquery: "[?instance.hw_name == '{{ item
>>> }}'].instance.guest_tools_status"
>>> with_items: "{{ vm_list }}"
>>
>>
>> --
>> 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] <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/3473c234-0db3-4808-b73d-d9ba8460b5ee%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/3473c234-0db3-4808-b73d-d9ba8460b5ee%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
> Thanks,
> Abhijeet Kasurde
>
--
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/8768fe59-44ab-45e4-a778-c3e60ac8a957%40googlegroups.com.