Setting and reading variables in provisioning snippets

Latest response

Please excuse me if it seems I'm quite ignorant of how dynamic templates are used. I am.

One of the tasks we perform when deploying is to determine who the upstream NTP servers for a host will be based on their domain name. In bash, simple case statement or parse the string. I am trying to take advantage of the dynamic nature of these templates with a snippet designed to create a customized ntp.conf file. I realize there are easier ways to do this, but this is the task I chose to learn how this works.

Below is a case statement that should set the variable NTP_POOL:

<%
NTP_POOL = case @host.domain 
    when "iexample.com" then "pool.iexample.com"
    when "vexample.com" then "pool.vexample.com"
    when "example.com" then "pool.example.com"
    when "foo.com" then "pool.foo.com"
    when "vfoo.com" then "pool.foo.com"
    when "amers.iexample.com" then "amers.pool.iexample.com"
    when "amers.vexample.com" then "amers.pool.vexample.com"
    when "apac.iexample.com" then "apac.pool.iexample.com"
    when "apac.vexample.com" then "apac.pool.vexample.com"
    when "eams.iexample.com" then "eams.pool.iexample.com"
    when "eams.vexample.com" then "eams.pool.vexample.com"
    else "stratum1.pool.iexample.com"
end
%>

Later on in the file I want to write NTP_POOL to the ntp.conf file:

pool <%= @NTP_POOL %> iburst

When I try to preview the snippet (neat feature!) I get this error message:
Warning! There was an error rendering the Snippet-NTP.conf template: Safemode doesn't allow to access 'cdecl' on NTP_POOL = case @host.to_jail.domain when "iexample.com" then "pool.iexample.com" when "vexample.com" then "pool.vexample.com" when "example.com" then "pool.example.com" when "becpsn.com" then "pool.becpsn.com" when "vbecpsn.com" then "pool.vbecpsn.com" when "amers.iexample.com" then "amers.pool.iexample.com" when "amers.vexample.com" then "amers.pool.vexample.com" when "apac.iexample.com" then "apac.pool.iexample.com" when "apac.vexample.com" then "apac.pool.vexample.com" when "eams.iexample.com" then "eams.pool.iexample.com" when "eams.vexample.com" then "eams.pool.vexample.com" else "stratum1.pool.iexample.com" end

The case statement was built from an example here: Techtopia

Does anyone have any pointers I can chase to figure out what's going on here?

Thank you
Doug

Responses

Hi Doug,

Looks like your template is trying to modify or alter foreman supplied parameter (probably NTP configuration). Do you mind share your full template ERB code here?

Regards

Hi Muhammad. Here is the full snippet.

<%#
kind: snippet
name: GIO-NTP-Snippet.conf
%>
<%
NTP_POOL = case @host.domain 
    when "iexample.com" then "pool.iexample.com"
    when "vexample.com" then "pool.vexample.com"
    when "example.com" then "pool.example.com"
    when "foo.com" then "pool.foo.com"
    when "vfoo.com" then "pool.vfoo.com"
    when "amers.iexample.com" then "amers.pool.iexample.com"
    when "amers.vexample.com" then "amers.pool.vexample.com"
    when "apac.iexample.com" then "apac.pool.iexample.com"
    when "apac.vexample.com" then "apac.pool.vexample.com"
    when "eams.iexample.com" then "eams.pool.iexample.com"
    when "eams.vexample.com" then "eams.pool.vexample.com"
    else "stratum1.pool.iexample.com"
end
%>
echo "BEGIN: Install NTP config."
cat << EOF_NTP > /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict -4 default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict -6 ::1
restrict -4 127.0.0.1
pool <%= @NTP_POOL %> iburst
tos minclock 3 minsane 3
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
logfile /var/log/ntpd.log
logconfig =all
EOF_NTP
echo "END: Install NTP config."

:BUMP: Any ideas?

did you find a solution to this ?

Sorry, no. I handled it after the reboot.

Doug