Ansible Modules for Nutanix

  • 25 April 2019
  • 9 replies
  • 5386 views

Has anyone used Ansible for Automating Nutanix tasks. Can someone share some examples please.

9 replies

Userlevel 1
Badge +2
Hello,

I'm using Ansible to configure prism settings. DNS, NTP, Alerts, proxy, authentication, and stuff like that. I will try to clean up all my specific data and publish them on the nutanix git, or my own git portal.
Badge
Hey @itguyadam - I am trying to list VMs on specific cluster using ansible - Currently, I am listing all the VMs and then filtering based on cluster_name.

Is there better way where I could pass cluster_name as filter and get VMs only on that particular cluster ?

TIA
Userlevel 1
Badge +2
@hfg_nutanix I've uploaded an ansible role to git. There are a few tasks i'm still working on and getting ready to publish but the bones of everything is there.

https://github.com/AD-Code/Automation/tree/master/ansible/nutanix_cluster_baseline
Userlevel 1
Badge +2
@OkBeacon What commands are you using currently?
Badge
@itguyadam - Thanks for reply!
I eventually figured out how to do it (Couldn't find any documentation about filters)

code:
- import_tasks: get_session_cookie.yml

- name: Get VMS list
uri:
url: "{{ api_url_v3 }}/vms/list"
body:
kind: vm
sort_order: ASCENDING
offset: 0
length: 1000
sort_attribute: ''
filter: "cluster_name=={{ cluster_name }}"
method: POST
validate_certs: no
body_format: json
status_code: 200
headers:
Cookie: "{{ session_cookie }}"

register: vms_result
Userlevel 1
Badge +2
@OkBeacon I've also found some of the API documentation a bit lacking in areas like that. I will most likely steal your task and use it in some other playbooks i'm working on. thanks
Badge
I am reusing code from
https://github.com/mbach04/nutanix_vm_provisioner

Currently working on provisioning k8s cluster on nutanix - I will put it on github once I am happy with it.
Userlevel 1
Badge +2

I’ve just created an ansible role (https://galaxy.ansible.com/cybergavin/nutanix_vm_create) for bulk creation of VMs using different images and in different subnets. It also mounts and enables NGT.

Badge

@itguyadam

- Thanks for reply!
I eventually figured out how to do it (Couldn't find any documentation about filters)

 

The Filter specification was KILLING ME!    Thank you for sharing this.  It worked perfectly once I knew the context and syntax. 

Reply