Introduction

app_vms:
- name: web01
memory: 4096
vcpus: 2
disk: 20
subnet: vlan10
category: "env:prod"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

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


Playbook: deploy_app_stack.yml

Nutanix Repository on GitHub


Run the Playbook

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.

- 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] }}"

Similar Posts