Question

How deploy VM from PrismCentral template with Ansible Nutanix module


Badge +1

I have just installed the module Nutanix for Ansible. The demo playbook works fine.

https://www.nutanix.dev/2022/08/05/getting-started-with-the-nutanix-ansible-module/

But I can’t find in the module documentation how to deploy VM  from a VM template just like we do with https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_guest_module.html ?

Thx


This topic has been closed for comments

13 replies

Userlevel 4
Badge +5

This is not supported yet. You can file an improvement on the official GitHub repo.

Badge +1

Done
https://github.com/nutanix/nutanix.ansible/issues/358

In waiting, what would be the workaround ?
Is there a way through CLI ?

thx

Userlevel 4
Badge +5

No workaround. 
 

IMO, if using Ansible, Terraform, NCM Self-Service or any other infrastructure as code software, templates don’t make much sense. They are designed for GUI usage where you click many times and it’s time consuming and prone to mistakes. 
 

When using Ansible, the playbook is your template, and your var files are the machine definitions. It’s kind to go against the principles of using IaC at the first place. 

Badge +1

If I understand you well, you advice to code the VM deployment in playbook so that it starts from installation ISO, right ?

Userlevel 4
Badge +5

Not from ISO, but from the DISK image you already have and use to deploy your VMs from the GUI.

Badge +1

Hello again.
I’m relatively new to Nutanix. What I found efficient on VMware was to create VM templates from ISO with packer when necessary, and use these templates to deploy and configure VMs with Ansible, which is really fast.
I just tried to apply the same way on Nutanix, I just understand it’s not the good one.
I will have a look on DISK image and how use them to deploy VM through Ansible.

Thx.

Userlevel 4
Badge +5

We have the same on Nutanix with AHV. You use Packer https://developer.hashicorp.com/packer/plugins/builders/nutanix/nutanix to create DISK images (OS image template). Then on your Ansible playbooks you consume that DISK image instead of an ISO (what Packer used to build the initial image).

It’s the same principle, just a different endpoint, AHV.

Badge +1

I followed your preconization and could deploy a new VM from a DISK image.
But how configure the hostname, and most important, the static IP while deploying ?

In VMWare ,when we deploy VMs with community.vmware.vmware_guest from a template, we just use network and customization  parameter section in playbook to set hostname, IP/mask/gateway , DNS config. And the resulting VM has the proper IP and can immediately be configured by Ansible. Now idea how community.vmware.vmware_guest does that.
I guess I have to use cloud-init, right ?
 

Userlevel 4
Badge +5

That’s right. At the end of this example you have more details. 

In addition, you can use ansible-doc nutanix.ncp.ntnx_vms_clone 

Badge +1

Hello.

I confirm that I succeeded to deploy  with networking setting using “guest_customization:” and cloud-init templating below.

The only annoying thing is an extra delay in cloud-init steps (between init-locale and init processus) : around 2 minutes.

Any idea why ? Should I contact cloud-init community ?

Thx again for your help.

I’m not far from deployment maturity as  I have reached with VMWare, making Nutanix a good candidate for the infra in our future factory.

 

 

 

Badge +1

I’m still confused : what is the real difference in the resulting VM between Disk image cloning method (with nutanix.ncp.ntnx_vms) and existing VM cloning (with  nutanix.ncp.ntnx_vms_clone,for which I have still pb, see https://next.nutanix.com/ahv-virtualization-27/failed-to-clone-a-vm-with-ansible-41823) ?

Which method should be used in which cases ?

Thx

Userlevel 4
Badge +5

Related to cloud-init, that’s something you’ll have to investigate between the Linux distribution you are using and cloud-init documentation. That delay isn’t something related to AHV.

 

About difference between modules, nothing different to what you can do on the GUI.

  • When you use ntnx_vms_clone, you need a VM as the source, same concept on Ansible than PC GUI, nothing changes. 
  • When you use ntnx_vms, you don’t need a VM source and can create VMs with empty disk or with an exiting image, same concept on Ansible than PC GUI, nothing changes.

At the end it comes up to what you prefer to follow that fits better on your operating model.

Badge +1

I understand.

But im my case, as I generate Disk Image from an existing VM, it’s one more step than clone this existing VM directly to create a new VM, especially if customization (cloud-init/sysprep) can be applied in cloning process as well.
I’ll give a try of this.

Thank you a lot for your help.