I am using Foreman 2.1.1 and am creating CentOS installations from scratch (VM and bare metal).
When I create a new host from the GUI the system name does not match the Foreman host name.
For example:
I can not setup DNS records ahead of time and would like to set the hostname in kickstart.
I need an automated method which will make sure that the Foreman and system hostname is the same.
I have seen the solution of creating a script and including it in the kickstart file - I donât see an easy way of automating that. I am looking for a way to get Foreman to pass the hostname to the kickstart file which would then set the hostname in the ânetworkâ command.
This differs on platform, however including fix_hosts snippet, thatâs shipped by default, should help. You could also take an inspiration from this PR that was sadly never merged. However thatâs IMHO the best solution (Iâm biased
To use the existing snippet, add <%= snippet 'fix_hosts' %> to your kickstart %post section.
If you want to go with the second option, take just the set_hostname snippet, create the new template with such name and content from the PR and mark it as a snippet. Then do the same as mentioned in the first option, only chamge fix_hosts to the name of newly created snippet.
I tried adding the following to the kickstart file as well as in the provisioning template and still am not setting the hostname as expected. What do oyu think Iâm doing wrong?
That is weird, since you see the <%= tags in the /root/host-name file, it seems the template didnât get rendered at all. These tags should be replaced by the resulting value. E.g. <%= 1 + 1 %> should result in 2 in the rendered template. If you go to template form and click preview, do you see the tags or values, e.g. the hostname? If you see tags, make sure to type symbols yourself, instead of copying from the browser.
The documentation of all variables and functions was added in Foreman 2.3 and you would find the link on about page, but you have older version.
Oh wait, it seems you updated the wrong template. Donât modify the Kickstart default PXEGrub2 CentOS 8.2 but Kickstart default (or how you called that). The template of Provisioning template kind. Find the line %post --log=/mnt/sysimage/root/install.post.log and put the snippet somewhere after it.
The template you editted is for the booting over the network, you need to set the hostname during the OS installation. It does not explain why you see <%= @host.shortname %> in the file though.