On Dec 21, 3:40 pm, Walter Heck <walterh...@gmail.com> wrote:
> Hello,
>
> a related question here on this list sparked me to write this question,
> which has been bugging me for a bit now:
>
> I use the following pattern inside my modules quite abit:
>
> class foo::params{
>
>   $bar = $::foo_bar ? {
>     '' => 'somedefaultvalue',
>     default => $::foo_bar
>   }
>
> }
>
> Then I can refer to the variable from my module by $foo::params::bar, which
> is quite nice.
>
> The problem is, I want to be able to set the value of $::foo_bar in a thrid
> module in my services folder, but that is not possible because $::foo_bar
> needs to be top-scope. I don't want to make module foo dirty by adding
> $s_yadda::foo_bar but I don't see a better way, can anyone enlighten me as
> to how they solve this problem? The only way I can think of is class
> parameters, but that is a lot less clean.
>
> I wish I could write to $::foo_bar from outside the top scope, even though
> that is kind of dirty too :) .


You're exactly right: the behavior you want is dirty, too.  Much
dirtier, in fact, than one module directly using class variables of
one of another module's classes.

Parameterizing foo::params would not be much better, because it would
still leave that class dependent on another module's variables (in
that it needs them to be passed to it as parameters to achieve your
desired result).  Parameterizing foo::params would also make it harder
to use, inasmuch as you would need to be much more careful about how
and where it is declared than you otherwise need to be.

The bottom line is that it doesn't matter how you communicate the
values of one class's variables to another class; any way you do it
produces a dependency of the variable consumer on the variable
provider.

To avoid such dependencies, you could consider having foo::params use
external data instead of Puppet variables of any scope.  Puppet has
long provided the extlookup() function for this purpose, and there is
now hiera as well.  You might even find that external data could
*replace* foo::params in some cases rather than merely supporting it.


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to