Deploying Multi-VM Applications on AHV with Ansible

Introduction

Many enterprise applications require multiple virtual machines, web frontends, app layers, and databases. With Ansible and Nutanix AHV, you can define entire application stacks in YAML and deploy them with a single command. This playbook demonstrates how to deploy and configure multiple VMs in a repeatable fashion.


My Personal Repository on GitHub

Nutanix Repository on GitHub


Diagram: Multi-VM Application Stack Flow


Use Case

  • Deploy 3-tier applications (Web, App, DB)
  • Assign networks, tags, and disks per VM
  • Configure post-provision settings like NICs or categories

YAML File: app_stack.yml

app_vms:
- name: web01
memory: 4096
vcpus: 2
disk: 20
subnet: vlan10
category: "env:prod"

- name: app01
memory: 8192
vcpus: 4
disk: 40
subnet: vlan20
category: "env:prod"

- name: db01
memory: 16384
vcpus: 8
disk: 100
subnet: vlan30
category: "env:prod"

Playbook: deploy_app_stack.yml

- name: Deploy Nutanix Application Stack
hosts: localhost
gather_facts: false
collections:
- nutanix.ncp
vars_files:
- nutanix_credentials.yml
- app_stack.yml
tasks:

- name: Launch each VM in app stack
loop: "{{ app_vms }}"
loop_control:
loop_var: vm
nutanix.ncp.vms:
name: "{{ vm.name }}"
state: present
cluster_name: "prod-cluster"
memory_size_mib: "{{ vm.memory }}"
num_vcpus_per_socket: "{{ vm.vcpus }}"
num_sockets: 1
vm_disks:
- disk_size_mib: "{{ vm.disk * 1024 }}"
storage_container: "default-container"
vm_nics:
- subnet_name: "{{ vm.subnet }}"
categories:
- name: "{{ vm.category.split(':')[0] }}"
value: "{{ vm.category.split(':')[1] }}"

Run the Playbook

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

Optional Enhancements

  • Add cloud-init or attach ISOs
  • Tag VMs by role (role:web, role:db)
  • Loop over clusters for DR deployment

Summary

This playbook showcases how Ansible can manage full-stack deployments on Nutanix AHV. By storing application VM definitions in YAML, you gain agility, auditability, and consistency across environments.

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