Anonymous block scope?

31 views
Skip to first unread message

Christian Flamm

unread,
Aug 27, 2015, 7:03:11 AM8/27/15
to Puppet Users
Hi,
is there a way to have anonymous block scope in puppet? In a couple of languages you can simply create limited scope by opening and closing curly braces {...}

I'd like to use this to limit the area of effect of e.g. resource default statements (https://docs.puppetlabs.com/puppet/latest/reference/lang_defaults.html).

Thanks in advance,
Christian

R.I.Pienaar

unread,
Aug 27, 2015, 7:07:44 AM8/27/15
to puppet-users
Puppet 4 address most of this, in 3 not so much.

Are you asking about 3?

Christian Flamm

unread,
Aug 27, 2015, 7:25:09 AM8/27/15
to puppet...@googlegroups.com

Yes

--
You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/7M61d84szdQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/1046405241.85644.1440673655277.JavaMail.zimbra%40devco.net.
For more options, visit https://groups.google.com/d/optout.

Christian Flamm

unread,
Aug 27, 2015, 7:35:41 AM8/27/15
to Puppet Users
Not proud of this idea, but...

if true {
...
}


?

jcbollinger

unread,
Aug 27, 2015, 9:40:20 AM8/27/15
to Puppet Users


On Thursday, August 27, 2015 at 6:03:11 AM UTC-5, Christian Flamm wrote:
Hi,
is there a way to have anonymous block scope in puppet? In a couple of languages you can simply create limited scope by opening and closing curly braces {...}


No, not the way you are thinking.  The scope rules for Puppet 3 are laid out pretty clearly in the manual.  There is a top scope visible everywhere, a node scope visible everywhere except at top scope, and local scopes established by classes and resources of defined type.  Node scope and defined-resource scope are anonymous; their contents can be accessed only via unqualified name.  No other Puppet 3 construct or syntax establishes a scope.

 


I'd like to use this to limit the area of effect of e.g. resource default statements (https://docs.puppetlabs.com/puppet/latest/reference/lang_defaults.html).



Scoping of resource defaults is its own little bundle of joy, as resource defaults are one of the very few aspects of Puppet that still use dynamic scoping.  This makes them tricky and even dangerous.  I strongly recommend that you declare resource defaults only at the very top and the very bottom of any dynamic scope nest: at top or maybe node scope, where they affect everything, or maybe in class and defined-resource scopes that do not themselves declare any classes or defined-type instances, where they affect only their static scope.  Consider avoiding resource defaults altogether.


John

jcbollinger

unread,
Aug 27, 2015, 9:41:29 AM8/27/15
to Puppet Users


The body of an if statement does not establish a separate scope.


John

Christian Flamm

unread,
Aug 28, 2015, 3:29:02 AM8/28/15
to Puppet Users
Thanks for clearing this up!

Reply all
Reply to author
Forward
0 new messages