Manages power states of virtual machines in vCenter
- Power on / Power off / Restart a virtual machine.
Note
- All modules requires API write access and hence is not supported on a free ESXi license.
- name: Set the state of a virtual machine to poweroff
community.vmware.vmware_guest_powerstate:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
folder: "/{{ datacenter_name }}/vm/my_folder"
name: "{{ guest_name }}"
state: powered-off
delegate_to: localhost
register: deploy
- name: Set the state of a virtual machine to poweron using MoID
community.vmware.vmware_guest_powerstate:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
folder: "/{{ datacenter_name }}/vm/my_folder"
moid: vm-42
state: powered-on
delegate_to: localhost
register: deploy
- name: Set the state of a virtual machine to poweroff at given scheduled time
community.vmware.vmware_guest_powerstate:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
folder: "/{{ datacenter_name }}/vm/my_folder"
name: "{{ guest_name }}"
state: powered-off
scheduled_at: "09/01/2018 10:18"
schedule_task_name: "task_00001"
schedule_task_description: "Sample task to poweroff VM"
schedule_task_enabled: true
delegate_to: localhost
register: deploy_at_schedule_datetime
- name: Wait for the virtual machine to shutdown
community.vmware.vmware_guest_powerstate:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: "{{ guest_name }}"
state: shutdown-guest
state_change_timeout: 200
delegate_to: localhost
register: deploy
- name: Automatically answer if a question locked a virtual machine
block:
- name: Power on a virtual machine without the answer param
community.vmware.vmware_guest_powerstate:
hostname: "{{ esxi_hostname }}"
username: "{{ esxi_username }}"
password: "{{ esxi_password }}"
validate_certs: false
folder: "{{ f1 }}"
name: "{{ vm_name }}"
state: powered-on
rescue:
- name: Power on a virtual machine with the answer param
community.vmware.vmware_guest_powerstate:
hostname: "{{ esxi_hostname }}"
username: "{{ esxi_username }}"
password: "{{ esxi_password }}"
validate_certs: false
folder: "{{ f1 }}"
name: "{{ vm_name }}"
answer:
- question: "msg.uuid.altered"
response: "button.uuid.copiedTheVM"
state: powered-on
- Abhijeet Kasurde (@Akasurde) <[email protected]>