There is a @host.facts defined in the foreman provisioning template guide (
TemplateWriting - Foreman). My
assumption would be that these facts can only be read after the host is
built which makes them a bit pointless to put in the provisioning template.
Here is the issue I am having:
My snippet has this in it:
Host productname: <%= @host.facts['productname'] %>
Host manufacturer: <%= @host.facts['manufacturer'] %>
Host ipaddress: <%= @host.facts['ipaddress'] %>
Host interface: <%= @host.facts['interface'] %>
Host mac: <%= @host.mac %>
<% if @host.facts['manufacturer'] == /HP/ -%>
…
And when I render the template for a new host I get most fields blank:
Host productname:
Host manufacturer:
Host ipaddress:
Host interface:
Host mac: d8:9d:67:1a:47:dc
Once the host is built I can re-render the template and get the output I expect but at this point it is too late. I have safemode_render set to true, it makes no difference if I set this to false.
Questions
-How can I access these facts at build time on the first build of the host?
-And if I can't then does anyone know where I can find something that will tell me the model/manufacturer of the host eg: HP or Proliant etc.
Foreman gets it's facts from Puppet so until Puppet has run at least once,
there's no facts to render. Even if Foreman receives facts during the
provisioning, the template has already been rendered, so that won't help.
I'd suggest changing your snippet to call facter directly, assuming it's
installed - eg "Productname: facter productname
"
Greg
Thanks Greg for the explanation - I tried your syntax and it doesn't seem
to work which makes sense if the facts are not available at host build
time. I shouldn't be surprised that the host data is not available until it
boots. It seems the only option is to move this to puppet or use an ENC to
read the data in.
Looking at it a different way, is there a variable that can read the
"hardware model" specified in the "Additional Information" section of the
host definition. I want it to be a safe variable i.e. one where I don't
have to set "safemode_render" to "false". Any idea's greatly received.
···
On Tuesday, 1 March 2016 13:02:42 UTC, Greg Sutcliffe wrote:
Foreman gets it’s facts from Puppet so until Puppet has run at least once,
there’s no facts to render. Even if Foreman receives facts during the
provisioning, the template has already been rendered, so that won’t help.
I’d suggest changing your snippet to call facter directly, assuming it’s
installed - eg "Productname: facter productname
"
Greg