Select Your Language

Infrastructure and Management

Cloud Computing

Storage

Runtimes

Integration and Automation

  • Comments
  • Setting and reading variables in provisioning snippets

    Posted on

    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

    by

    points

    Responses

    Red Hat LinkedIn YouTube Facebook X, formerly Twitter

    Quick Links

    Help

    Site Info

    Related Sites

    © 2026 Red Hat