Stop a VMware vSphere Virtual Machine — Ansible module vmware_guest_powerstate

How to automate the gracefully use guest shutdown and forcefully power off to change the power state from Powered On to Powered Off of the virtual machine guest “myvm” using Ansible Playbook and vmware_guest_powerstate module.

Luca Berton


How to Stop a VMware vSphere Virtual Machine with Ansible?

I’m going to show you a live demo and some simple Ansible code.

I’m Luca Berton and welcome to today’s episode of Ansible Pilot

Ansible Stop a VMware vSphere Virtual Machine

  • `community.vmware.vmware_guest_powerstate`
  • Manages power states of virtual machines in vCenter

Let’s talk about the Ansible module `vmware_guest_powerstate`.

The full name is `community.vmware.vmware_guest_powerstate`, which means that is part of the collection of modules to interact with VMware, community-supported.

It manages the power states of virtual machines in vCenter.


  • hostname string / username string / password string / datacenter string / validate_certs boolean — connection details
  • state string — present / powered-off / powered-on / reboot-guest / restarted / shutdown-guest / suspended
  • force boolean — no/yes
  • answer string — A list of questions to answer, should one or more arise while waiting for the task to be complete.

The following parameters are useful in order to Start a VMware vSphere Virtual Machine using the module `vmware_guest_powerstate`.

First of all, we need to establish the connection with VMware vSphere or VMware vCenter using a plethora of self-explicative parameters: `hostname`, `username`, `password`, `datacenter`, and `validate_certs`.



Luca Berton

I help creative Automation DevOps, Cloud Engineer, System Administrator, and IT Professional to succeed with Ansible Technology to automate more things everyday