Site icon Digital Thought Disruption

Managing VM Power State with Ansible

Introduction

Whether you’re scheduling routine maintenance, automating DR procedures, or managing lab environments, the ability to control VM power state is essential. With Ansible, you can automate VM power operations, start, stop, reboot, and validate, all from a single playbook.


My Personal Repository on GitHub

Nutanix Repository on GitHub


Diagram: VM Power Workflow


Use Case


Sample Variables: group_vars/all.yml

vm_power_map:
web01: poweron
db01: poweroff
test01: restart

Playbook: vm_power_control.yml

- name: Control Nutanix VM power states
hosts: localhost
gather_facts: false
collections:
- nutanix.ncp
vars_files:
- nutanix_credentials.yml
- group_vars/all.yml
tasks:

- name: Control power state of VMs
loop: "{{ vm_power_map | dict2items }}"
loop_control:
label: "{{ item.key }}"
nutanix.ncp.vms:
name: "{{ item.key }}"
state: present
power_state: "{{ item.value }}"
cluster_name: "prod-cluster"

Supported Power States


Run the Playbook

ansible-playbook vm_power_control.yml --ask-vault-pass -i inventory.yml

Optional Enhancements


Summary

Controlling VM power state with Ansible gives your team more reliable workflows, improved energy efficiency, and the ability to automate daily environment resets or DR responses. Use this playbook to enforce consistency across dev, test, and prod AHV clusters.

External Documentation:

Exit mobile version