Deploying Nutanix AHV VMs with Ansible

Introduction

Once your Ansible control node is configured, deploying a virtual machine on Nutanix AHV is just a few lines of YAML away. This article walks through an enterprise-ready playbook to launch AHV VMs using the Nutanix Ansible collection. We’ll cover options for CPU, memory, networks, and storage, and how to make the playbook reusable.


My Personal Repository on GitHub

Nutanix Repository on GitHub


Diagram: VM Deployment Workflow


Step 1: Define Inventory

Use inventory.yml as in Part 1:

all:
hosts:
localhost:
ansible_connection: local

Step 2: Define Credentials File

Already encrypted from Part 1:

nutanix_pc_hostname: prism.example.com
nutanix_pc_port: 9440
nutanix_username: admin
nutanix_password: S3cure!
validate_certs: false

Step 3: Create Your VM Deployment Playbook

- name: Deploy AHV VM on Nutanix
hosts: localhost
gather_facts: false
collections:
- nutanix.ncp
vars_files:
- nutanix_credentials.yml
tasks:
- name: Deploy application VM
nutanix.ncp.vms:
state: present
name: app-server-01
cluster_name: prod-cluster
memory_size_mib: 8192
num_vcpus_per_socket: 2
num_sockets: 1
boot_type: UEFI
vm_disks:
- disk_size_mib: 20480
storage_container: default-container
vm_nics:
- subnet_name: vlan10
guest_tools:
agent_enabled: true

Step 4: Add Extra Configs (Optional)

        description: "App VM from Ansible"
categories:
- name: AppRole
value: Web
metadata:
created_by: ansible

Step 5: Run the Playbook

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

Tips for Production Readiness

  • Use tags for metadata control
  • Store template inputs in group_vars/ or host_vars/
  • Validate inputs with Ansible conditions or when:
  • Store VM specs in separate YAML vars for repeatability

Summary

This playbook demonstrates how to launch a production-grade Nutanix VM using Ansible. By defining resources declaratively, you’re able to standardize provisioning and reduce admin overhead. Future posts will focus on snapshotting, networking, and scaling VMs dynamically.

External Documentation:

Leave a Reply

Discover more from Digital Thought Disruption

Subscribe now to keep reading and get access to the full archive.

Continue reading