On Thursday, March 5, 2015 at 6:27:55 PM UTC-6, Christian Hase wrote:
>
> Hi folks,
>
> i want to declare a resource default globally for all available classes. I 
> searched google and found this site:
>
>
> https://ask.puppetlabs.com/question/396/howto-force-systemd-as-service-provider-globally/
>
> These guys suggest this solution:
>
> Service {
>     provider => systemd,
>   }
>
> *If you write this in a class, the resource default will only be valid 
>> within that class, so if you want to have a global default you should 
>> probably place that into your site.pp file.*
>
>
>
> So i tested it. I wrote in my "$environment/manifests/site.pp" under 
> default:
>
> *node default {*
> *  if $::operatingsystem == 'Sles12.0' {*
>      *Service {*
> *        provider => "systemd",*
> *     }*
> *     notify{"SLES 12: Systemd als Service-Provideer":}*
> *  }*
> *}*
>
>
> But i didn't see anything in the debug output on my testystem.
>


That suggests that either Puppet matched a different node definition to 
your test system, or that your test system reported a different 
$::operatingsystem value than 'Sles12.0' to Puppet.

In any event, that's not what is meant by putting the resource default in 
site.pp.  As usual in Puppet, scope is very important.  The answer on Ask 
should be more precise, suggesting putting the default *at top scope* in 
site.pp. The only reason to put the default specifically in site.pp is that 
it should be in a file that is certain to be evaluated for every (relevant) 
node.  If you are using a site manifest directory instead of a single site 
manifest file, then the declaration could go (at top scope) in any file in 
that directory.

By the way, this sense of "top scope" refers to *Puppet's* idea of scoping, 
in which (roughly) there is one top scope, and nested scopes are defined by 
node blocks, class definitions, and defined type definitions, but not by 
other block-like constructs.  In particular, putting the resource default 
declaration inside a conditional statement does not affect its scope, but 
putting it in a node block or class body *does*, regardless of the file in 
which that node block or class body appears.

 

> When i declare the provider directly in the resource declaration its 
> working.
>
> Can someone tell me how i have to declare a resource default that it is 
> working for i.e. 5 services wich i include in the nodedefinition ?
>
>

A resource default declared in the relevant node block *will* affect all 
resources declared in that node block, or by classes declared in that node 
block, or by classes declared by those classes, etc.  It *will not* affect 
resources or classes declared at top scope (in *any* file) or classes 
declared via an ENC, or any classes those declare, etc..  The trick is that 
those two sets are not necessarily disjoint, because classes can be 
declared more than once.  When a class is in both sets, it is not easily 
predictable whether a resource declared directly or indirectly by that 
class will be affected by defaults declared in the node block.  Similar 
issues arise with other placements of resource default declarations.

It is best practice is to avoid the possibility of any such uncertainty by 
careful choice of the scope of resource defaults.  Putting them at top 
scope is certain to avoid such uncertainty; putting them in narrower scopes 
is statistically riskier, but if you're careful, it can be done without 
introducing uncertainty for any resource about whether the defaults apply 
to it.


John

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/f0e17b31-0bed-4c7b-a3dc-f3d93b56cacd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to