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.
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.