when tools status "guestToolsNotRunning" , power off the vm.

Please suggest how can i add when clause in above, ie when tools status “guestToolsNotRunning” , power off the vm.

Hi Kiran,

Do you want to run this operation on specific VMs or all the VMs which are “guestToolsNotRunning” status?

Hi Kiran,

I did something like this -

Hi Abhijit

Thanks for your reply, Only Specific VMs where the status is guestToolsNotRunning

Best
Kiran

Hi Abhijit

Thanks for your reply. I did as per you note, How can i check the output & also then how can i use that in action block ie shutdown action.


  • 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
    debug:
    msg: “{{ vm_info.results | json_query(jmesquery) }}”
    vars:
    jmesquery: “[?instance.hw_name == ‘{{ item }}’].instance.guest_tools_status”
    with_items: “{{ vm_list }}”

  • name: Tools status
    set_fact:
    desired_vms: “{{ vm_info.results | community.general.json_query(jmesquery) }}”
    vars:
    jmesquery: “[?instance.guest_tools_status == ‘guestToolsNotRunning’].instance.hw_name”

Best,
Kiran