Skip to main content
Solved

cloud-init (Create VM > 'Custom Script') pass variables - define hostname

  • October 12, 2020
  • 5 replies
  • 3421 views

Hi All, 

Does anyone know if it’s possible to pass variables into the ‘Custom Script’ / cloud-init section, when creating a VM in AHV via Prism Element?

Ideally, I’d like to use the REST API to create (clone) a VM from a template, and pass a ‘Custom Script’ perhaps from an ADSF path, that is able to configure the guest’s Hostname / FQDN based off the VM’s name specified in the REST API call.

IPAM and some basic cloud-init config is working, just trying to determine the best way to set the hostname!

Best answer by Alona

Oh, I see! There is also this KB AHV: Ubuntu Cloud Image VM creation option 2 of which goes through creating and configuring a VM via REST API call through Prism Central using curl.

This topic has been closed for replies.

5 replies

Alona
Nutanix Employee
Forum|alt.badge.img+5
  • Nutanix Employee
  • 426 replies
  • October 14, 2020

Hi justinl123,

 

Have you seen this post? Was it helpful or is it not what you’re looking for?


  • Author
  • Voyager
  • 2 replies
  • October 14, 2020

Hey Alona, 

Kind of. I want to programmatically create a VM with name XYZ and also put that name XYZ in the hostname: field of your Custom Script (i.e. cloud-init). That way, we can call the script, say 10 times and increment the hostname i.e. XYZ01, XYZ02, XYZ03, … and the VM will be named appropriately, as well as the guest hostname.

That way we can stamp out n number of VMs in one go, by running one script passing in a hostname prefix.

This is more along the lines of what I want to do, but without the Calm integration. When I get a chance, I’ll look at scripting a REST API call that also builds, and base64 encodes the cloud-init ‘user data’ portion with matching hostnames.


Alona
Nutanix Employee
Forum|alt.badge.img+5
  • Nutanix Employee
  • 426 replies
  • Answer
  • October 14, 2020

Oh, I see! There is also this KB AHV: Ubuntu Cloud Image VM creation option 2 of which goes through creating and configuring a VM via REST API call through Prism Central using curl.


  • Author
  • Voyager
  • 2 replies
  • October 14, 2020

Ah yep, exactly that with a wrapper script around it to automate the steps, accepting a parameter for hostname!

Many Thanks!


Alona
Nutanix Employee
Forum|alt.badge.img+5
  • Nutanix Employee
  • 426 replies
  • October 14, 2020

Great! Glad that was helpful :)