Introduction

- name: Enterprise Nutanix VM Provisioning
hosts: localhost
gather_facts: false
collections:
- nutanix.ncp
vars_files:
- nutanix_credentials.yml
- enterprise_vm_config.yml
vars:
slack_webhook: "https://hooks.slack.com/services/XXXX/YYYY/ZZZZ"
tasks:TASK [Check VM health]
ok: [localhost] => {
"changed": false,
"msg": "analytics01 passed health check"
}


Run the Playbook

rescue:
- name: Notify Slack of failed VM deploy
uri:
url: "{{ slack_webhook }}"
method: POST
headers:
Content-Type: application/json
body_format: json
body:
text: ":x: Nutanix VM {{ vm.name }} failed to deploy properly."


Playbook: enterprise_vm_deploy.yml

Nutanix Repository on GitHubExternal Documentation:– name: Check VM health
assert:
that: “‘on’ in vm_status.vms[0].power_state”
fail_msg: “{{ vm.name }} is not powered on”
success_msg: “{{ vm.name }} passed health check”- name: Apply tags
loop: “{{ vm.tags }}”
loop_control:
loop_var: tag
nutanix.ncp.vms:
name: “{{ vm.name }}”
categories:
– name: “{{ tag.split(‘:’)[0] }}”
value: “{{ tag.split(‘:’)[1] }}”
state: update
cluster_name: “prod-cluster”In production environments, VM provisioning requires more than just spinning up a virtual machine. You must ensure the VM is validated, tagged correctly, and monitored for failures. This enterprise-grade Ansible playbook combines provisioning, tagging, verification, and notifications in a single flow.


Output Example

– name: Validate power state
nutanix.ncp.vms_info:
name: “{{ vm.name }}”
cluster_name: “prod-cluster”
register: vm_status

vms:
- name: analytics01
cpu: 4
memory: 16384
disk: 100
subnet: vlan20
tags:
- env:prod
- owner:analytics
- compliance:hipaa

- name: api01
cpu: 2
memory: 8192
disk: 50
subnet: vlan10
tags:
- env:prod
- owner:devops

Similar Posts