On Thursday, April 18, 2013 12:32:28 PM UTC-5, Gerard B wrote:
>
> Hi,
>
> I'm running into some trouble when trying to access some variables which 
> actually are a class parameter.
>
> The following works OK:
>
> node "common" {
>  $var='foo'
> }
>
> node "gratia-base" inherits common {
>
>   class {
>         'gratia':
>                 dbhost => 'server.mysite.net',
>   }
>
> }
>
> node "node1" inherits gratia-base  {
>
>   validate_re($::gratia::dbhost, '.mysite.net')
>
> }
>
>
>
> But if I move the 'common' node definition to a different .pp file, puppet 
> fails to read the value of $::gratia::dbhost.
>
> The way I've the nodes files structured is:
>
> manifests/nodes.pp
>   import "nodes.d/*.pp"
>
> manifests/nodes.d/common.pp
>     node common {....}
>
> manifests/nodes.d/gratia.pp
>    *The code I show before*
>
>
> Do you know why this is happening and/or how to prevent it?
>
>
First, make sure the behavior persists after you restart the Puppmaster.  
Changes to "import"ed manifests can otherwise be overlooked.

If the behavior does persist, then I find it surprising, and I can only 
speculate on why it may be occurring.  I suspect, however, that you may 
misunderstand the semantics of the 'import' statement.  In particular, it 
does not do text interpolation along the lines of the C preprocessor's 
"#include" directive, but rather it does something rather more like 
Python's "import": whole declarations appearing in another manifest are 
incorporated by reference into the importing file.  It nevertheless has its 
own semantic twist: Puppet's "import" is not scope- or namespace-relative, 
so the imported declarations remain in whatever namespace their manifest 
declares them in.

It could be that your problem arises because in the second form of your 
manifests, node "common" is not recognized by the parser when it parses 
node "gratia-base", whether because Puppet does not parse the manifests in 
the order you expect or for some other reason.  If that's the problem then 
you might be able to fix it by 'import'ing common.pp into gratia.pp.

Alternatively, you could stop using node inheritance, or flatten the tree 
to just two levels.  A lot of people seem to expect node inheritance to 
work differently than it actually does, so it may be better avoided if 
you're not certain you know exactly what you're doing with it.  Moreover, 
node inheritance imposes a single taxonomy on your nodes, and you are 
likely to eventually find that too constraining.


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 post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to