On Friday, August 23, 2013 7:08:21 AM UTC-5, François Lafont wrote:
>
> Hi, 
>
> I use Puppet 3.2 with Hiera. I would like to know the best practices 
> when you want to share one data between 2 classes or modules. 
>
> I take an example. I have: 
>
> - One "snmp" module which installs and configures snmpd in the hosts. 
> In this module, I must define the community password. 
>
> - One "monitoring" module which installs and configures any monitoring 
> software (by example Nagios if you want, it doesn't matter). In this 
> module, 
> I must define too the community password in order to the software 
> monitoring 
> runs valid snmp requests. 
>
> So, the "snmp" module and the "monitoring" module must share the same 
> data: the community password. Which are the best practice to do this? 
>
>
[...]
 

>
> Like this, my modules are independent but the same "community password" 
> data is duplicated in 2 different places. Ok, in my example, the data 
> is in the same file (default.yaml) but we can imagine more complex cases 
> where the same data is duplicated in 2 different files (because the data 
> hierarchy isn't limited to one "default.yaml" file etc). 
>
>
[...]
 

>
> Now, the "community password" data isn't duplicated, but my modules 
> aren't independent because the "monitoring" module depends on the 
> "snmp" module. And I suppose that's better to have independent modules. 
>
>

Your modules are not independent in any case.  The data dependency is a 
symptom, not the root issue.

To answer more generally, since you started by posing a rather general 
problem, where you have a bona fide configuration dependency, it is not 
wrong for one module to depend on another.  Real systems are composed of 
multiple interdependent pieces, so it is natural for your models of them to 
contain dependencies.  You can shift them around to various places and 
forms, but you cannot omit them and still have anything of much use.

One place you did not mention, to which you could shift the dependency 
modeling, is your data.  For example, lift your 'community' key to the top 
level of your YAML data, consolidating all copies of it.  Then have any 
class that needs that particular key just load it.

I don't think there is a clear, universal right answer here.  My best 
advice is to find where each datum belongs, and put it there.  Coincidental 
data duplication should not concern you overmuch, but do avoid duplicating 
data for the purpose of presenting a false semblance of independence.


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.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to