Global scope variables and erb templates in puppet 2.7

3,500 views
Skip to first unread message

Matthias Saou

unread,
Jun 12, 2011, 10:20:01 AM6/12/11
to puppet...@googlegroups.com
Hi,

I'm starting to play with the latest puppet 2.7.0rc4, one of my goals
being to try and update all of my puppet related files to be compatible
with it, with no warnings at all.

I've read in detail this page :
http://docs.puppetlabs.com/guides/scope_and_puppet.html

There is no mention of anything special to do for global scope
variables inside templates, such as :

file { '/tmp/test': content => inline_template ('<%= fqdn %>') }

Yet when using <%= ::fqdn %> I get the following :

(err): compile error
(erb):1: syntax error, unexpected tIDENTIFIER, expecting tCONSTANT
_erbout = ''; _erbout.concat(( ::fqdn ).to_s); _erbout

How should these global scope variables (facts in this case) be used
inside erb templates? Maybe there's some obvious ruby syntax I'm
missing?

Matthias

Ken Barber

unread,
Jun 12, 2011, 12:08:31 PM6/12/11
to puppet...@googlegroups.com
Try:

inline_template('<%= scope.lookupvar("::fqdn") %>')

ken.

On Sun, Jun 12, 2011 at 3:20 PM, Matthias Saou
<th...@spam.spam.spam.spam.spam.spam.spam.egg.and.spam.freshrpms.net>
wrote:

> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
>
>

Matthias Saou

unread,
Jun 12, 2011, 3:01:45 PM6/12/11
to puppet...@googlegroups.com
Hi,

Thanks, using scope.lookupvar() in the templates does work. But will
this be the proper way to echo facts in puppet 2.7 and 2.8? Because it
does seem like quite an extra burden, and if it's not really decided
yet, I prefer sticking with the warnings for now ;-)

Matthias

Alessandro Franceschi

unread,
Jun 13, 2011, 5:26:31 AM6/13/11
to puppet...@googlegroups.com
scope.lookupvar() works also on Puppet 2.6 and 0.25 and maybe earlier versions, and AFAIK will keep on working in future versions.
Incidentally it has the benefit of not throwing an exception when the referred variables is not set (it just returns an empty field)
I find it useful to refer to fully qualified variables (ie apache::params::port) that are not usable in the traitional form (<%= apache::params::port %>

Al

Matthias Saou

unread,
Jun 13, 2011, 9:19:51 AM6/13/11
to puppet...@googlegroups.com
Hi,

Then I'm guessing the only other solution, which also works with 0.25
and any higher version would be :

$local_scope_fqdn = $::fqdn

Then :

<%= local_scope_fqdn %>

In order to use a local scope variable from within templates.

It's really too bad to not be able to use scoped variables from erb
templates directly, as it won't ever be as convenient as before for
facts and global scope variables.

Matthias

Reply all
Reply to author
Forward
0 new messages