accessing out of class/scope variables in template

7 views
Skip to first unread message

Matt Zagrabelny

unread,
Aug 16, 2019, 10:32:26 AM8/16/19
to puppet...@googlegroups.com
Hello,

I'm running puppet 5.5 OSE.

I've got a class foo:

class foo {
    $bar = 'hi'
}

class foo::configure {
    file { '/tmp/foo.conf':
        content => template('foo/foo.conf.erb'),
    }
}

and then in the template:

<%= scope['foo::bar'] %>

but suppose I want to access an out of class variable:

<%= scope['baz::qux'] %>

That does not seem to work. Is there any way to access out of class variables in a template?

Thanks for any help!

-m

Henrik Lindberg

unread,
Aug 16, 2019, 1:15:02 PM8/16/19
to puppet...@googlegroups.com
That should work as long as `baz::qux` has been evaluated before
you evaluate this template.

Can also highly recommend switching to EPP (templates in Puppet
Language) instead of ERB (tempaltes in Ruby).

Your template would then be:

<%= $foo::bar %>

Best
- henrik

--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

Reply all
Reply to author
Forward
0 new messages