With foreman discovery the discovered hosts get a name based on their mac
address…
Is there a way to influence this? We have pre-provisioned our DNS with
hostnames for each IP in the range the DHCP server hands out. Is it
possible to have foreman discovery use these names when naming discovered
hosts?
There are two relevant settings to do this:
discovery_fact = which fact to use for the name (default is
discovery_bootif)
discovery_prefix = the prefix to the discovered host name (default is 'mac'
since a hostname must start with a letter)
The name has to include a value of one of the facts and can't be
dynamically set for each host.
···
On Mon, Jan 26, 2015 at 9:02 AM, Krist van Besien wrote:
Hello,
With foreman discovery the discovered hosts get a name based on their mac
address…
Is there a way to influence this? We have pre-provisioned our DNS with
hostnames for each IP in the range the DHCP server hands out. Is it
possible to have foreman discovery use these names when naming discovered
hosts?
I answered you about the names of the hosts while discovering them but not
while provisioning.
Using discovery 2.0 you can use auto-provision and create rules that also
influence your hostname during provision.
···
On Mon, Jan 26, 2015 at 9:43 AM, Ori Rabin wrote:
There are two relevant settings to do this:
discovery_fact = which fact to use for the name (default is
discovery_bootif)
discovery_prefix = the prefix to the discovered host name (default is
’mac’ since a hostname must start with a letter)
The name has to include a value of one of the facts and can’t be
dynamically set for each host.
With foreman discovery the discovered hosts get a name based on their mac
address…
Is there a way to influence this? We have pre-provisioned our DNS with
hostnames for each IP in the range the DHCP server hands out. Is it
possible to have foreman discovery use these names when naming discovered
hosts?
> I answered you about the names of the hosts while discovering them but not
> while provisioning.
>
> Using discovery 2.0 you can use auto-provision and create rules that also
> influence your hostname during provision.
To fill the gap here, with all that being said, you can easily use
existing fact for discovered or/and provisioned hostnames.
Unfortunately discovery image AFAIK ignores hostnames set by DHCP
because we want to prevent multiple DHCP leases. What you can do is you
can create a custom fact (via ZIP extensions) that would provide this
name. Then you can use the fact to get the hostname. You should find the
required info in /var/lib/dhclient/IFACE.lease (if I type it in
correctly).
If you do so, please share the fact with us and we will likely include
it in the basic image.
I also want my discovered host to register with their hostnames and implemented the following work around to make this happen for my CentOS hosts.
In Administer -> Settings -> Discovered set Hostname facts to discovery_bootip
Create a file named rc.local with the below contents and place it on a locally accessible webserver:
#!/usr/bin/bash
# Do reverse nslookup to determine hostname and set it
# TODO - make dynamic rather than hardcoding intf name....
export IP="$(ifconfig ens192 | awk '/inet / {split ($2,A,"."); print A[1]"."A[2]"."A[3]"."A[4]}')"
# echo $IP -- debug output
export TEST="$(nslookup $IP | awk '/name = / {split ($4,B,"."); print B[1]"."B[2]"."B[3]"."B[4]}')"
# echo $TEST -- debug output
hostnamectl set-hostname $TEST
# Make rc.local unexecutable so it doesn't run after first boot
chmod -x /etc/rc.d/rc.local
In my kickstart file:
include wget in the packages
Near the end insert the below:
If you are rebuilding the image, you don’t need to download the script, just put it into ./root/etc/rc.d/rc.local directory and it will be embedded on the image automatically, just make sure it’s executable.
There should be curl available, you do not need wget.
This might be useful, feel free to contribute the shell script. Put it in ./root/usr/local/bin and create a systemd service, run it only in case there is a kernel command line option something like fdi.hostnamefromdhcp=1. You can easily do this in systemd: