variable scoping and erb templates

45 views
Skip to first unread message

Matt Zagrabelny

unread,
Aug 15, 2016, 2:49:16 PM8/15/16
to puppet...@googlegroups.com
Greetings!

I am hitting a curious question and couldn't find an answer.

I can access variables from other classes when using an erb template.

Here is my minimal example:

# puppet apply variable_scope_test.pp
Notice: Compiled catalog for puppet.example.com in environment
production in 0.12 seconds
Notice: A variable from a different class:
Notice: /Stage[main]/Scope_example::Sub_class/Notify[A variable from a
different class: ]/message: defined 'message' as 'A variable from a
different class: '
Notice: Finished catalog run in 0.11 seconds

# cd /tmp
# head -n -0 variable_scope_test.pp template.erb template_output
==> variable_scope_test.pp <==
class scope_example {
$variable = "THIS IS A TEST!"
include scope_example::sub_class
}

class scope_example::sub_class {
file { '/tmp/template_output':
content => template('/tmp/template.erb'),
}
notify { "A variable from a different class: $variable": }
}

node 'puppet.example.com' {
include scope_example
}

==> template.erb <==
<%= @variable %>

==> template_output <==
THIS IS A TEST!

So why is the template allowed to see variables in other classes?

I would have ad expected to need to use the variable like:

<%= @scope_example::variable %>

But it clearly works without adjusting its namespace.

Thoughts?

Thanks!

-m

Lowe Schmidt

unread,
Aug 16, 2016, 2:31:16 AM8/16/16
to puppet...@googlegroups.com
What version of Puppet are you running?

--
Lowe Schmidt | +46 723 867 157


-m

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAOLfK3WBY9Hg%3DsaiHA2iAt4SRQjBX6XLsAJVj_qLGHJgjuugEg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Matt Zagrabelny

unread,
Aug 16, 2016, 8:06:28 AM8/16/16
to puppet...@googlegroups.com
Hi Lowe,

On Tue, Aug 16, 2016 at 1:31 AM, Lowe Schmidt <m...@loweschmidt.se> wrote:
> What version of Puppet are you running?

Debian Jessie:

3.7.2-4

-m
>> email to puppet-users...@googlegroups.com.
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/CAC-wWcSmcHxSC5h169UOBiqq0HJTRtN7C4WfRbmnW02rHgx_OA%40mail.gmail.com.

jcbollinger

unread,
Aug 16, 2016, 9:04:13 AM8/16/16
to Puppet Users


On Tuesday, August 16, 2016 at 7:06:28 AM UTC-5, Matt Zagrabelny wrote:
Hi Lowe,

On Tue, Aug 16, 2016 at 1:31 AM, Lowe Schmidt <m...@loweschmidt.se> wrote:
> What version of Puppet are you running?

Debian Jessie:

3.7.2-4



That looks like bug PUP-1220.  Note that although the ticket is marked as being fixed in Puppet 3.5, commentary on the ticket and details of the associated commit make me think that the fix only applies when you use the future parser.


John

Matt Zagrabelny

unread,
Aug 16, 2016, 9:08:00 AM8/16/16
to puppet...@googlegroups.com
On Tue, Aug 16, 2016 at 8:04 AM, jcbollinger <John.Bo...@stjude.org> wrote:
>>
>> On Tue, Aug 16, 2016 at 1:31 AM, Lowe Schmidt <m...@loweschmidt.se> wrote:
>> > What version of Puppet are you running?
>>
>> Debian Jessie:
>>
>> 3.7.2-4
>>
>
>
> That looks like bug PUP-1220. Note that although the ticket is marked as
> being fixed in Puppet 3.5, commentary on the ticket and details of the
> associated commit make me think that the fix only applies when you use the
> future parser.

Thanks for clearing my confusion, John!

Best,

-m

R.I.Pienaar

unread,
Aug 16, 2016, 9:23:25 AM8/16/16
to puppet-users
historically this is how puppet worked both in manifests and templates, that
got deprecated but for some reason templates didnt get the same treatment, 4
finished the job

>
> Best,
>
> -m
>
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/CAOLfK3W4DAqi9%3D63pwxGUO_jYQkcL6bnSMx_cePPN3z1dVyuyA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages