All-

Is there a canonical way to access hierarchical facts like
$facts['os']['release']['major'] or $facts['networking']['fqdn'] from
an ERB template?  I've been searching for a best practice answer and
so far I've only found conflicting advice.

I'm specifically asking about facts, not variables from other
classes/scope.

I've found recommendations suggesting each of these:

        <%= $facts['os']['release']['major'] %>
        <%= @facts['os']['release']['major'] %>
        <%= $facts.dig("os","release","major") %>
        <%= @facts.dig("os","release","major") %>

as well as suggestions to use scope[] or scope.lookupvar() or use dotted
fact notation, but I haven't figured out how to make either the scope or
dotted route work in ERB.

The "$facts.dig()" suggestion comes directly from the Puppet 8
compatibility wiki entry:

        https://github.com/puppetlabs/puppet/wiki/Puppet-8-Compatibility

but it doesn't seem to work for me.  Using the @facts.dig() does, though.

So far the two methods I've found that work are

        <%= @facts['os']['release']['major'] %>

or

        <%= @facts.dig("os","release","major") %>

Is there any reason to prefer one over the other, or some other method
that I haven't found yet?

I don't want to convert our existing ERB templates to EPP.

I know I could set local variables in a puppet class like

        $osreleasemajor = $facts['os']['release']['major']
        $fqdn           = $facts['networking']['fqdn']

and then access the local variables in the template, but if possible I
would like to avoid that approach.

Thanks,

Tim
--
Tim Mooney                                             tim.moo...@ndsu.edu
Enterprise Computing & Infrastructure /
Division of Information Technology    /                701-231-1076 (Voice)
North Dakota State University, Fargo, ND 58105-5164

--
You received this message because you are subscribed to the Google Groups "Puppet 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/puppet-users/3334ffcd-fa00-de56-408f-09d5019fce87%40ndsu.edu.

Reply via email to