Unable to set static ip on vSphere deployment


I’m trying to deploy virtual machines using foreman on vSphere.
I’m able to deploy vm’s on vSphere but foreman never set a static ip address.

Is anyone using foreman and vSphere in the same way, had the same problem and can help to solve mine?

Hi @marceau12

What does the subnet look like in the Foreman UI? Do you have a foreman-debug I can see? Is there a traceback or during anaconda/post boot does the VM just not come up with an IP?

There is probably a better way of doing this but here’s an example something I’ve done in the past for this. When using Spacewalk I just included it as a post install script. In Foreman it could be implemented as a snippet called towards the end of your provisioning template. This is for provisioning a CentOS host and works for baremetal or VMs. The gist is that it creates a script that runs when the host reboots after being provisioned. You’ll probably have to tweak it for your specific env.

# Create our command file and add execute permission
touch /root/setMgmtIP
chmod a+x /root/setMgmtIP

# Begin adding instructions to our command file
echo "#!/bin/bash" >> /root/setMgmtIP

# Make a copy of the Mgmt Intf config file for the following sed operation
echo "cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.ORIG" >> /root/setMgmtIP

# Disable DHCP in Mgmt Intf config file.  Have to use the newly copied file for searching b/c sed won't write to the same file.
echo "sed 's/dhcp/none/' </etc/sysconfig/network-scripts/ifcfg-eth0.ORIG >/etc/sysconfig/network-scripts/ifcfg-eth0" >> /root/setMgmtIP

# Get our IP address -- used for debugging
# echo "echo \"myIP=$(ifconfig eth0|awk '/inet addr/ {split ($2,A,":"); print A[2]}')\"" >> /root/setMgmtIP

# Get our MAC address -- used for debugging
# echo "echo \"myMAC=$(ifconfig eth0|awk '/HWaddr / {split ($5,A," "); print A[1]A[2]A[3]A[4]A[5]A[6]}')\"" >> /root/setMgmtIP

# Append our IP address, mask, gtwy & dns to Mgmt Intf config file
echo "echo IPADDR="$(ifconfig eth0|awk '/inet addr/ {split ($2,A,":"); print A[2]}')" >> /etc/sysconfig/network-scripts/ifcfg-eth0" >> /root/setMgmtIP

echo "echo PREFIX="24" >> /etc/sysconfig/network-scripts/ifcfg-eth0" >> /root/setMgmtIP
echo "echo GATEWAY="" >> /etc/sysconfig/network-scripts/ifcfg-eth0" >> /root/setMgmtIP
echo "echo DNS1="" >> /etc/sysconfig/network-scripts/ifcfg-eth0" >> /root/setMgmtIP

# Delete Mgmt Intf scratch config file
echo "rm /etc/sysconfig/network-scripts/ifcfg-eth0.ORIG" >> /root/setMgmtIP

# Restart network service
echo "service network restart" >> /root/setMgmtIP

# Make a backup of /etc/rc.d/rc.local
cp /etc/rc.d/rc.local /etc/rc.d/rc.local.bak

# Add a line to execute our command file to /etc/rc.d/rc.local
echo "/root/setMgmtIP" >> /etc/rc.d/rc.local

# We only want our logic to run upon the first reboot after the PXE boot so we restore the original untouched /etc/rc.d/rc.local
echo "mv /etc/rc.d/rc.local.bak /etc/rc.d/rc.local" >> /root/setMgmtIP
echo "chmod -x /root/setMgmtIP" >> /root/setMgmtIP

Here is the bad part of the logs.

2019-03-21T13:20:35 [E|app|e79d740e] Could not find a provider for cathy-perugini.xxxxx.net.                                                                                                                            Providers returned {"MediumProviders::Default"=>["REDHAT 7.6 medium was not set for host 'cathy                                                                                                                           -perugini.xxxxx.net.net'", "Invalid medium '' for 'REDHAT 7.6'"]}

In advance, thank you for your help

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.