Question

Creating new VM's using Ansible

  • 20 December 2018
  • API
  • 1 reply
  • 1375 views

We just got a lab Nutanix cluster purchased and I'm working on playing around with the Nutanix Prism Central API v3. I'm using Ansible to make calls to the API.

I'm sure this has been done many times before, so I want to make sure I'm not going about it incorrectly or illogically. I have an Ansible play written that created a new VM, uses an image I provide, and can add disks based on survey input through Ansible. It automatically powers on and comes online with an IP from the pool we have set up in Nutanix.

My question is, once I have this VM created, what's the best way to go about customizing the OS? The Ansible play is actually running locally on my Ansible Tower instance and making a uri call over to Prism Central's API. I'm not connected to the new VM that was created because it didn't exist when I first ran the play. In order to connect to it, I would have to get the IP from Nutanix somehow and then add it into the inventory.

I'm wondering if maybe I should be using a cloud-init script instead and can pass that in through the guest_customization parameter in the API during VM creation? I haven't played around with cloud-init at all yet, so maybe that's not the way to go.

Any suggestions on how to go about the OS customization once the VM is built? High level logical steps are what I'm looking for at this point.

1 reply

Badge
I think you almost have it already. We have playbooks for each aspect of a machine life cycle. One difference is that we query infoblox for an IP to assign to the new machine and use a VRA job that takes some input items from ansible. Our VRA build come out with a default username/pw, various disks attached, assigned IP, etc. We also wrote a bunch of custom modules to deploy a VM(before many of the vmware ones were available) to the specs we assigned at runtime outside of the VRA process,

We couple those deployment plays with configuration plays that do all things OS config related.

Since you already have the build steps down i'd next turn to a localhost play to add the machine to the ansible inventory file(could maybe query DNS for the IP of the new machine or just use the machine name itself if resolution is working).

Once added then you can call the rest of your config plays, DNS, NTP, local users, package installs, etc.

I'm not the linux guy so I don't know all the plays they created, but i've written a bunch of in-house modules for Active Directory and general windows OS tasks.

Our whole team's philosophy is to break the tasks down into the smallest segments and then build playbooks that might list off 20 different plays/roles from other areas. Separating the tasks that way makes everything more modular and easy to use going forward.

Don't know if all that was helpful or not, but it is what we do and it works really well for us.

Reply