On Friday, October 4, 2013 11:52:57 AM UTC-5, kay kay wrote: > > I would like to create one file with array, i.e.: > > $pkg_versions = { > soft1 => { prod => "0.0.6", test => "0.0.7" }, > soft2 => { prod => "1.1.4", test => "1.1.5" }; > } > > And "require" this file in several environments. > > I tried to use "require /var/lib/puppet/somedir/etc/file.inc", but puppet > can not find it. >
Puppet does not provide a mechanism for interpolating DSL files. The closest it comes is the 'import' feature, but that doesn't do quite what you're looking for; in fact, it has approximately one good use case. The 'require' function you are trying to use is a specialized version of the 'include' function, both of which ensure that the named *class* is included in the target node's catalog. Although that can trigger the autoloader to try to load a file it expects to contain the definition of the named class, that's basically a side effect. > > What solution should I use? Or maybe is it possible to put this array in > puppet class, include it in parent classe and get its values? > > You can absolutely put it in a class, or even put it at top level in site.pp. Puppet does not provide for data hiding, so you do not need to inherit from the data's host class to have access to the data. This would work, for example: <module_path>/site/manifests/versions.pp ---- class site::versions { $pkg_versions = { soft1 => { prod => "0.0.6", test => "0.0.7" }, soft2 => { prod => "1.1.4", test => "1.1.5" }; } } <module_path>/soft1/manifests/init.pp ---- class soft1 { # ensure that site::versions is evaluated so that # its variables are available include site::versions.pp $soft1_versions = $site::pkg_versions['soft1'] $my_version = $soft1_versions[$::environment] # ... } With all that said, however, I have to agree with Cory that this sort of problem is very well served by hiera, whether you actually use hiera automatically, as he demonstrates, or via explicit calls to the hiera() function. If you have only this particular problem to solve then it might not be worth setting up and learning Hiera, but in truth, you're likely to run into more such problems in the future. 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.