Trying to configure Discovery Rule to set hostname that corresponds to known fact

Hey all,

A little stumped here and looking for a nudge in the right direction.

I’m trying to configure a Discovery Rule to automatically provision a host, and give it a specific hostname and IP address that corresponds to a known fact, like its IPMI hostname or IP address. More details…

I’ve got about 60 bare-metal servers I’m currently trying to provision. They all have OOB management – in this case IPMI – configured on a static IP with corresponding DNS record. So when they’re discovered by foreman, they have facts like:

ipmi_ptr =
ipmi_ipaddress =

Is there a way to configure a discovery rule that will automatically provision these with a specific IP & hostname that corresponds to that IPMI hostname/IP?

For example, if a discovered host has the following IPMI hostname…

Then configure it with the following hostname & IP:

In other words, I’m looking for a way to upload a set of facts. Right now, I have a spreadsheet for all 60 servers that has Mac address, IPMI hostname, IPMI IP address, server hostname and server IP address for each system. In short, I’m just looking for a way to get all that information into Foreman so that I don’t have to provision each host one by one.

For what it’s worth, I’m a sysadmin, not a developer. I have no ruby skills and I’m pretty new to Foreman. Go gentle on me…


Hey, you can use the fact but domain will be appended so you would end up with “”. In the hostname, you can use ERB so use Ruby gsub method to strip out the domain before the other gets appended:

<%= @host.facts['ipmi_ptr'].gsub("", "").to_s %>

The IP address is a problem tho, Foreman manages these and there is no way to set it explicitly. However if you make the DHCP server to give this lease to the server and the address is within the IP range of the Foreman subnet, then when host is provisioned Foreman DHCP module will keep this address and convert it from lease to reservation. However if the DHCP server is not managed by Foreman that is a problem - there is currently no way of setting up static IP address.

Oh wait you say its static all the way down, how you want to have your hosts discovered without DHCP? Discovery relies on DHCP, that’s the idea. You can create discovery ISO and attach it as CD or USB stick to your server where you can embed static network credentials but that’s not what you probably want to do.

Hey Izap, thanks for the reply.

That ERB method you mentioned is exactly one of the solutions I had considered for the hostname! I have zero ruby knowledge, though, so thanks a ton for spelling it out for me.

Unfortunately, on the IP front – I’m not doing DHCP through my Foreman server. DHCP is handled by another group at my company (it’s a big company), and I have very little control of it. Just getting a DHCP scope configured with the ‘next-server’ and ‘filename’ options was a major challenge, but I got it eventually. So now the DHCP server directs my hosts to Foreman Discovery, and upon provisioning I reassign them a static address with corresponding DNS A-Record.

I suppose I’ll keep brainstorming an IP solution, but thanks for the hostname solution!