Problems with a resource default definition

33 views
Skip to first unread message

Christian Hase

unread,
Mar 5, 2015, 7:27:55 PM3/5/15
to puppet...@googlegroups.com

Hi folks,

i want to declare a resource default globally for all available classes. I searched google and found this site:


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.














The i created a class called "services::providerdefault" which had the same content like the site.pp in the above. Just the line "node.." was exchanged with "class services::providerdefault {" so to get a class.

I made a requirement in a class for autofs and i got this output.



































Now i get the notify in this run.... But the service wants to check with chkconfig and thats wrong. I'm asuming now that my default definition is not typed the right way or in a wrong place.

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 ?


Thanks in Advance

Christian Hase (Yes thats my real name ^-^ its german and means rabbit)

Henrik Lindberg

unread,
Mar 6, 2015, 9:31:38 AM3/6/15
to puppet...@googlegroups.com
On 2015-02-03 15:30, Christian Hase wrote:
> Hi folks,
>
> i want to declare a resource default globally for all available classes.
> I searched google and found this site:
>

Which version of puppet are you using?
Suspect that there is an issue with default values for meta parameters
(like provider). IIRC, there were issues fixed in this area - hence the
question about version.

- henrik


--

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

jcbollinger

unread,
Mar 6, 2015, 11:03:57 AM3/6/15
to puppet...@googlegroups.com


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:


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

Reply all
Reply to author
Forward
0 new messages