Solved

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

  • 12 October 2020
  • 5 replies
  • 2910 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!

icon

Best answer by Alona 14 October 2020, 06:54

View original

This topic has been closed for comments

5 replies

Userlevel 6
Badge +5

Hi justinl123,

 

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

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.

Userlevel 6
Badge +5

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.

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

Many Thanks!

Userlevel 6
Badge +5

Great! Glad that was helpful :)