Differences between Resource Defaults statement and per block default?

18 views
Skip to first unread message

Tobias Koeck

unread,
Dec 13, 2017, 8:46:21 AM12/13/17
to Puppet Users
Hi,

I am wondering what the difference between a Resource Default statement like

Exec {
  path        => '/usr/bin:/bin:/usr/sbin:/sbin',
  environment => 'RUBYLIB=/opt/puppetlabs/puppet/lib/ruby/site_ruby/2.1.0/',
  logoutput   => true,
  timeout     => 180,
}

and

using a per block default like described in

https://puppet.com/docs/puppet/5.3/lang_data_default.html#per-block-resource-defaults

is?

Greetings
Tobias

R.I.Pienaar

unread,
Dec 13, 2017, 10:05:30 AM12/13/17
to puppet...@googlegroups.com


On Wed, 13 Dec 2017, at 14:46, Tobias Koeck wrote:
> Hi,
>
> I am wondering what the difference between a Resource Default statement
> like
>
> Exec {
> path => '/usr/bin:/bin:/usr/sbin:/sbin',
> environment =>
> 'RUBYLIB=/opt/puppetlabs/puppet/lib/ruby/site_ruby/2.1.0/',
> logoutput => true,
> timeout => 180,
> }
>

this one applies to all execs in the code below it

> and
>
> using a per block default like described in
>
> https://puppet.com/docs/puppet/5.3/lang_data_default.html#per-block-resource-defaults

this one applies only to the resources in the group.

Johan Fleury

unread,
Dec 13, 2017, 10:08:45 AM12/13/17
to puppet...@googlegroups.com
Le mercredi 13 décembre 2017 à 14:46 +0100, Tobias Koeck a écrit :
> Hi,
>
> I am wondering what the difference between a Resource Default statement like
>
> Exec {
> path => '/usr/bin:/bin:/usr/sbin:/sbin',
> environment => 'RUBYLIB=/opt/puppetlabs/puppet/lib/ruby/site_ruby/2.1.0/',
> logoutput => true,
> timeout => 180,
> }
>

This will apply to all the Exec in the scope where it is declared and all the
nested scopes while resource defaults will only apply to the resource block.

--
Johan Fleury
PGP Key ID : 0x5D404386805E56E6
signature.asc

Henrik Lindberg

unread,
Dec 13, 2017, 10:31:54 AM12/13/17
to puppet...@googlegroups.com
On 13/12/17 14:46, Tobias Koeck wrote:
> Hi,
>
> I am wondering what the difference between a Resource Default statement like
>
> |Exec { path => '/usr/bin:/bin:/usr/sbin:/sbin', environment =>
> 'RUBYLIB=/opt/puppetlabs/puppet/lib/ruby/site_ruby/2.1.0/', logoutput =>
> true, timeout => 180, }
>
>

What the others said is not quite accurate.

This sets the defaults for all Exec resources that are declared in the
same scope, or in any scope that is included from this scope. This is
known as Dynamic Scoping and it is a horribly bad idea that is removed
from modern puppet for everything except Resource Defaults (what the
example construct is known as). The less you use this the better.
Others correctly pointed out that this is a local defaults only.
Use this if you can as you do not risk unintentionally changing the
defaults for code that appears to be far away from yours.

Best,
- henrik

--

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

R.I.Pienaar

unread,
Dec 13, 2017, 11:41:02 AM12/13/17
to puppet...@googlegroups.com


On Wed, 13 Dec 2017, at 16:31, Henrik Lindberg wrote:
> On 13/12/17 14:46, Tobias Koeck wrote:
> > Hi,
> >
> > I am wondering what the difference between a Resource Default statement like
> >
> > |Exec { path => '/usr/bin:/bin:/usr/sbin:/sbin', environment =>
> > 'RUBYLIB=/opt/puppetlabs/puppet/lib/ruby/site_ruby/2.1.0/', logoutput =>
> > true, timeout => 180, }
> >
> >
>
> What the others said is not quite accurate.
>
> This sets the defaults for all Exec resources that are declared in the
> same scope, or in any scope that is included from this scope. This is
> known as Dynamic Scoping and it is a horribly bad idea that is removed
> from modern puppet for everything except Resource Defaults (what the
> example construct is known as). The less you use this the better.

There's been a very unfortunate puppet 5 behaviour change here:

class bar {
notify{"three": }
}

class foo {
include bar

notify{"one": }
Notify{message => "default"}
notify{"two": }
}

include foo

In 4 this would do as you say, both would use "default", but in 5...

Notice: three
Notice: /Stage[main]/Bar/Notify[three]/message: defined 'message' as
'three'
Notice: one
Notice: /Stage[main]/Foo/Notify[one]/message: defined 'message' as
'one'
Notice: default
Notice: /Stage[main]/Foo/Notify[two]/message: defined 'message' as
'default'

The positioning of the 'include' here would also change the behavior of
the 'three' resource

Bug or feature? Don't care personally, no-one should use this awful
feature.

Though I thought we killed the dynamic scope stuff wrt this :(

Henrik Lindberg

unread,
Dec 13, 2017, 12:01:13 PM12/13/17
to puppet...@googlegroups.com
Unfortunately that was not a deliberate change. It just means that the
testing for how defaults are supposed to work has holes in it.
I don't want it back though, and we have no error reports regarding
this. I hope it stays that way and that we can drop the resource
defaults or make them sane.

R.I.Pienaar

unread,
Dec 13, 2017, 12:02:14 PM12/13/17
to puppet...@googlegroups.com
came up a few times in slack and irc, selfishly did not ask for them to
make tickets :P

--
R.I.Pienaar / www.devco.net / @ripienaar
Reply all
Reply to author
Forward
0 new messages