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. 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? Thanks for help! -- 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+unsubscribe@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.
Cory Stoker
2013-Oct-06 08:45 UTC
Re: [Puppet Users] require one file from several environments
Data like this should probably go into hiera. Then write modules to use the data via parameterized classes or hiera() lookups. For example we use the "datadir" directive in hiera to split out hiera lookups to become environments aware. This would simplify your data structure to where you are just specifying the data for each environment to use instead of having to code your manifests to understand the data structure in a environmentally aware state. Example in your prod environment hiera yaml: software::soft1::version: 0.0.6 Example in your test environment hiera yaml: software::soft1::version: 0.0.7 Then in your class: class software::soft1($version) { package { ''soft1'': ensure => $version } Hiera would give your puppet clients the correct answer based on environment... However if you just want to use your data structure you referenced above you can place it into a module/class or even use import. However importing in a file like site.pp is not really recommended for various reasons. On Fri, Oct 4, 2013 at 10:52 AM, kay kay <kay.diam@gmail.com> 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. > > 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? > > Thanks for help! > > -- > 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+unsubscribe@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.-- 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+unsubscribe@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.
jcbollinger
2013-Oct-07 13:14 UTC
[Puppet Users] Re: require one file from several environments
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+unsubscribe@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.
jcbollinger
2013-Oct-07 13:17 UTC
[Puppet Users] Re: require one file from several environments
On Monday, October 7, 2013 8:14:52 AM UTC-5, jcbollinger wrote:> > $soft1_versions = $site::pkg_versions[''soft1''] > >Sorry, that should be $soft1_versions = $site::versions::pkg_versions[''soft1''] 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+unsubscribe@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.
kay kay
2013-Oct-07 14:37 UTC
[Puppet Users] Re: require one file from several environments
Thanks! That is what I need. понедельник, 7 октября 2013 г., 17:17:12 UTC+4 пользователь jcbollinger написал:> > > > On Monday, October 7, 2013 8:14:52 AM UTC-5, jcbollinger wrote: >> >> $soft1_versions = $site::pkg_versions[''soft1''] >> >> > Sorry, that should be > > $soft1_versions = $site::versions::pkg_versions[''soft1''] > > > 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+unsubscribe@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.