Reference a puppet class parameter in template?

How would I reference a puppet class parameter in my kickstart template?
For instance, I have the 'ntp' module installed and would like to add a
'server <%= ?class.ntp['server'] %>' but I cannot figure out how to
reference it. This is an example BTW, I know there may be a better way to
manage NTP specifically, I just want to know the mechanics of what I'm
trying to do. Thanks!

In your template for your ntp class something like will help. Beyond that
Google is your friend :wink:

<% @ntp_servers.each do |ntp_server| -%>
server <%= ntp_server %>
<% end -%>

··· On Friday, October 24, 2014 12:29:42 PM UTC-4, lawre wrote:

How would I reference a puppet class parameter in my kickstart template?
For instance, I have the ‘ntp’ module installed and would like to add a
’server <%= ?class.ntp[‘server’] %>’ but I cannot figure out how to
reference it. This is an example BTW, I know there may be a better way to
manage NTP specifically, I just want to know the mechanics of what I’m
trying to do. Thanks!

There's no easy way to access smart class parameters stored in Foreman in
the templates - we've been meaning to add a helper for that. In the
meatime, you can access the whole ENC object via:

<%= @host.info %>

Which you could then drill into, eg @host.info
['classes']['ntp']['ntpserver']

This is a relatively expensive operation (as it calculates all the data
sent to Puppet, something what would normally happen only once every
30mins, by default), so use it sparingly.

As an alternative from the trenches, I go the other way. I have Parameter
set on my hostgroup naming the ntp server, which is then referenced in the
smart class parameters as <%= @host.params['ntpserver'] %>

HTH,
Greg

··· On 24 October 2014 17:29, lawre wrote:

How would I reference a puppet class parameter in my kickstart template?
For instance, I have the ‘ntp’ module installed and would like to add a
’server <%= ?class.ntp[‘server’] %>’ but I cannot figure out how to
reference it. This is an example BTW, I know there may be a better way to
manage NTP specifically, I just want to know the mechanics of what I’m
trying to do. Thanks!

Ahh, yes I was able to find the @host.info object, however this is only
good for overrides. What if I did not override my NTP server? It does not
show up in @host.info.

··· On Monday, October 27, 2014 12:51:09 PM UTC-5, Greg Sutcliffe wrote: > > There's no *easy* way to access smart class parameters stored in Foreman > in the templates - we've been meaning to add a helper for that. In the > meatime, you can access the whole ENC object via: > > <%= @host.info > > %> > > Which you could then drill into, eg @host.info > ['classes']['ntp']['ntpserver'] > This is a relatively expensive operation (as it calculates all the data > sent to Puppet, something what would normally happen only once every > 30mins, by default), so use it sparingly. > As an alternative from the trenches, I go the other way. I have Parameter > set on my hostgroup naming the ntp server, which is then referenced in the > smart class parameters as <%= @host.params['ntpserver'] %> >

If I understand the question, you mean "can i get a default value from my
puppet manifests?" in which case the answer is no. If Foreman isn't aware
of the value, it can't use it in the templates.

I'd suggest checking the Override flag on the ntpserver parameter, and
filling in a sensible default. Then it will always be in the ENC output,
even if no further, more specific, overrides exists for the host in
question.

Greg

··· On 27 October 2014 19:56, lawre wrote:

On Monday, October 27, 2014 12:51:09 PM UTC-5, Greg Sutcliffe wrote:

There’s no easy way to access smart class parameters stored in Foreman
in the templates - we’ve been meaning to add a helper for that. In the
meatime, you can access the whole ENC object via:

<%= @host.info
http://www.google.com/url?q=http%3A%2F%2Fhost.info&sa=D&sntz=1&usg=AFQjCNFyKaJ336nbvzeVGk5eyWvncfPOqA
%>

Which you could then drill into, eg @host.info[‘classes’][‘ntp’][‘
ntpserver’]
This is a relatively expensive operation (as it calculates all the data
sent to Puppet, something what would normally happen only once every
30mins, by default), so use it sparingly.
As an alternative from the trenches, I go the other way. I have Parameter
set on my hostgroup naming the ntp server, which is then referenced in the
smart class parameters as <%= @host.params[‘ntpserver’] %>

Ahh, yes I was able to find the @host.info object, however this is only
good for overrides. What if I did not override my NTP server? It does not
show up in @host.info.