How to add ip and hostename through AcquireIPAddress _vm provision from template

automate

#1

Hi I’am trynig to automate acquisition of ip address through phpipam
but first I d’like to pass the ip and hostname from the ruby code in a static way to the provisiend vm
(RHEV )
I add this getip method to AcquireIPAddress state value

prov = $evm.root[“miq_provision”]
hostname = prov.get_option(:vm_name)
prov.set_option(:addr_mode, [“static”, “Static”])
prov.set_option(:ip_addr, “192.168.2.79”)
prov.set_option(:subnet_mask, “255.255.255.0”)
prov.set_option(:gateway, “192.168.2.44”)
prov.set_option(:vm_target_name, “#{hostname}”)
prov.set_option(:linux_host_name, “#{hostname}”)
prov.set_option(:vm_target_hostname, “#{hostname}”)

next I make a Test Provisioning (RHEV )
-rhel template.
-VM name testip
-In Environment, i chose Automatically box.
-Network none
-Customize tab:
Root Password: ****
Address Mode: DHCP
Script Name: Basic root pass template
should I use ovirt management as network I already tried and it didn’t work
I think taht may be a problem with the template
after the Provisioning the ip and hostename aren’t set


#2

Setting an IP address is a guest operating system function that normally happens when the guest first boots. Setting the IP details in the provisioning hash as you have done makes the details available for a cloud-init script to use, but you need to define your cloud-init script in Infrastructure -> PXE in the WebUI, and specify the script name as a provisioning customisation option.

Does your RHV template have cloud-init installed?

pemcg


#3

@pemcg Thanks for your reply, I have the same problem and I do have cloud-init installed in my template. But everytime I run the script only the hostname changes but the ifcfg-eth0 stays the same and set up to dhcp. I set up ifcfg-eth0 for my template to be static but everytime cloud-init runs the script it just switch it to dhcp and does not change the ip address.