Set a Hostname different to the name

Hi,

I want to create a vm with a name a little bit different of his hostname

like below and use the variable hostname in my methods

hostname

So this is what i’m trying to do but it’s isn’t working and i suppose the name is the same element as the hostname ?

and if i play the method inspectMe on this VM, the field hostname is empty and i don’t know why

hostname1

Another solution but i don’t know how i can do that, it’s to find the parameter linux_domain_name but not during the provisioning but at any time like when i want to perform an ansible job and populate the inventory like that : name.linux_domain_name

Hi Gregoire

You need to set prov.options[:vm_target_hostname], but you also need some kind of firstboot script to set this, such as a cloud-init script, or VMware customization specification.

Hope this helps,
pemcg

Hi @pemcg ,

I found something in vmware_CustomizeRequest for setting hostname, i already provide some adjustment

Unfortunately, i got errors and i don’t understand why.

ERROR – : Q-task_id([r107_miq_provision_262]) MiqAeServiceModelBase.ar_method raised: MiqException::MiqProvisionError: <Customization Specification [mytemplate] does not exist.>

MiqAeServiceModelBase.ar_method raised: : <Locking a record with unpersisted changes is not supported. Use save to persist the changes, or reload to discard them explicitly.>

Between this two i see the update of linux hostname and it’s fine.

The second error seems to be raised by the update vm_target_hostname

I can’t use this method ? I need a firstboot script ?

That first section of code is trying to find a VMware customization specification with the same name as the template that you’ve provisioned from. It looks like the template name was “mytemplate”, which is why you’re getting the error:

<Customization Specification [mytemplate] does not exist.>

Setting the operating system’s hostname is something that needs to be done by some kind of firstboot script, and for VMware this is usually a customization specification. You can either create one with the same name as the template to let this auto-selection logic work, or pre-select the customization spec when you create the service catalog item.

Hope this helps,
pemcg

Okay, i’m gonna explore that,

there is a way to retrieve linux_domain_name after the provisioning ? Like when i want run a Ansible play, i already tried somethings but without success

If the VM was provisioned by MIQ, then you’ll be able to access all of the options that were used for the provision via the options hash. You should be able to get this (from Ruby as an example) using $evm.root['vm'].miq_provision.options

pemcg

Thanks !