Automating Nutanix with Ansible: Foundations, Playbooks, and Best Practices
VMware News, virtual machine, vm, VMwareIntroduction
Nutanix and Ansible are a natural fit for enterprise automation. While Nutanix provides powerful APIs and CLI tools, Ansible brings repeatable, version-controlled orchestration to the datacenter. This guide helps you install, authenticate, and run your first playbook using the official Nutanix Ansible collection.
My Personal Repository on GitHub
Nutanix Repository on GitHub
Step 1: Prerequisites
Before starting, ensure:
- Python 3.8+ is installed
pipis available- Ansible 2.11+ is installed
- You have access to Prism Central or Prism Element
Install Ansible:
pip install ansible
Step 2: Install the Nutanix Ansible Collection
Install from Ansible Galaxy:
ansible-galaxy collection install nutanix.ncp
Verify:
ansible-galaxy collection list | grep nutanix
Step 3: Define Your Inventory
Create inventory.yml:
all:
hosts:
localhost:
ansible_connection: local
This setup runs tasks from the Ansible control machine, ideal for calling remote Nutanix APIs.
Step 4: Store Your Credentials
Create nutanix_credentials.yml and encrypt with ansible-vault:
nutanix_pc_hostname: "prism.example.com"
nutanix_pc_port: 9440
nutanix_username: "admin"
nutanix_password: "S3cure!"
validate_certs: false
Encrypt:
ansible-vault encrypt nutanix_credentials.yml
Step 5: Write Your First Playbook
Create create_vm.yml:
- name: Create a VM in Nutanix
hosts: localhost
collections:
- nutanix.ncp
vars_files:
- nutanix_credentials.yml
tasks:
- name: Launch a test VM
nutanix.ncp.vms:
state: present
name: "demo-vm"
cluster_name: "prod-cluster"
memory_size_mib: 2048
num_vcpus_per_socket: 1
num_sockets: 2
boot_type: UEFI
vm_disks:
- disk_size_mib: 10240
storage_container: "default-container"
vm_nics:
- subnet_name: "vlan10"
Step 6: Run the Playbook
ansible-playbook create_vm.yml --ask-vault-pass -i inventory.yml
You’ll be prompted for your Ansible Vault password.
Summary
You’re now equipped with a working Ansible setup for Nutanix! You installed the Nutanix collection, secured credentials, and launched a VM via a declarative YAML playbook. In upcoming posts, we’ll explore how to expand, delete, snapshot, and audit Nutanix resources using the same model.
External Documentation:
- Nutanix Ansible Collection (GitHub)
- Nutanix ncli Reference
Introduction Every environment faces moments of failure. Whether from guest corruption, misconfigurations, or broken updates, virtual machines sometimes need urgent rescue. This…
Next Post
Deploying Nutanix AHV VMs with Ansible
The post Automating Nutanix with Ansible: Foundations, Playbooks, and Best Practices appeared first on Digital Thought Disruption.