Assign DHCP to network interfaces on a vmware template

All,

I have successfully deployed a Windows VM template image using Foreman with
the below network configuration in the user_data template:

nicSettingMap:
<% @host.interfaces.each do |interface| %>
  - adapter:
      gateway: [<%= interface.subnet.gateway %>]
      ip: <%= interface.ip %>
      subnetMask: <%= interface.subnet.mask %>
      dnsDomain: <%= interface.domain %>
      dnsServerList: [<%= interface.subnet.dns_primary %>, <%=
interface.subnet.dns_secondary %>]
<% end %>
globalIPSettings:
  dnsServerList:
    - <%= @host.subnet.dns_primary %>
    - <%= @host.subnet.dns_secondary %>
  dnsSuffixList:
    - <%= @host.domain %>

But many of our deployments utilize DHCP reservations and I cannot figure
out for the life of me how to edit the user_data template to have foreman
use DHCP for the interfaces. I have done some extensive googling and read
the Foreman manual, template writing guide and VMware API guide to no
avail. What am I missing here?

Any help would be appreciated greatly.

David,

Foreman’s architecture is based on working with reservations. It cannot currently use leases, although Smart Proxy DHCP API has been recently modified to return active leases. Technically it should be possible tho to create helper function to return lease for particular MAC address and Subnet.

Normally interface.ip would be coming from DHCP anyway - Foreman would be asking the DHCP server for a free IP (via the Proxy) during the host creation. Have you changed that to static IP allocation (i.e. you’re providing the IPs)? Or is there something else preventing you from using the DHCP function of the Foreman Proxy?

First off, thanks for the reply. Maybe it is my ignorance here but the issue is not during provisioning. Foreman creates the DHCP reservation and the VM initially gets it. The issue is that the user_data template creates a vNIC with a static IP address. Is there a way to have a user_data template translate in FOG for a dynamic IP address? I would keep the reservation the Foreman creates, just need the VM to use it instead of setting the interface to static with the IP from the reservation.

Ah so IP allocation is working? Perfect.

So I think this goes one of two ways. One option is to figure out the right config in the user_data to get a dynamic NIC - sadly, I’m not familiar enough with VMware customization spec for that. Hopefully someone else has an idea for that.

The other option I can think of is to fix it after the install is done. If you’re using Puppet or similar config management, presumably you could change the NIC config to dynamic after the first boot?

The second option is what we are currently doing using MDT for the windows and scripting for Linux. Just not ideal. Would definitely prefer the first option if anyone can provide the correct config line in the user_data.

Much appreciated the replies and help.

1 Like

I quickly looked into this.
The good news is, that this is definitely possible with VMWare. Unfortunately, a library we use (fog-vsphere) is somewhat more limited.

You can try something like the following, but I haven’t tried if that resolved correctly all the way down. Especially with safe mode rendering, this won’t work:

---
customization_spec:
  nicSettingMap:
  - adapter:
      ip: !ruby/object:RbVmomi::VIM::CustomizationDhcpIpGenerator
        props: {}

I’d suggest opening a feature request on our Redmine issue tracker so we can look into that. Basically, we’d have to extend this code.

I know this is an old post. I figured by now someone would have come up with a resolution to the issue. I haven’t been able to find one.

Any information would be nice.