Brian Pitts
2010-Apr-27 01:54 UTC
[Puppet Users] Setting Variable in Class or Node and Using in Included Module
Should the following approach to optionally including site-specific information in modules work? It''s the third pattern documented at http://serialized.net/2009/07/puppet-module-patterns/ In my case, I have modules/manifests/ntp/init.pp import "classes/*" if ($ntp_servers) { $servers = $ntp_servers } else { $servers = ["0.rhel.pool.ntp.org", "1.rhel.pool.ntp.org", "2.rhel.pool.ntp.org"] notice("ntp: ntp_servers not set. Using red hat''s by default.") } modules/manifests/ntp/classes/ntp.pp class ntp { package { "ntp": ensure => installed; } service { "ntpd": enable => true, ensure => running, subscribe => File["/etc/ntp.conf"]; } # template iterates over values in $servers array file { "/etc/ntp.conf": ensure => file, owner => "root", group => "root", mode => "644", content => template("ntp/ntp.conf.erb"); } } And then in different classes [0] I set the ntp servers and include the module like: $ntp_servers = ["timeserver1.example.edu", "timeserver2.example.edu"] include ntp I often receive the error message "Failed to parse template ntp/ntp.conf.erb: Could not find value for ''servers'' at /etc/puppet/modules/ntp/manifests/classes/ntp.pp:19 on node foo.example.edu" or my own notice() from the manifest above during runs. I tried moving setting $ntp_servers from a class into a node, but that did not make a difference. Can anyone point out what I''m doing wrong or why this approach won''t work? I''ve read quite a bit on variable scope on the mailing list and wiki, but I could still be missing something. I''m running puppet 0.24.8 on RHEL5. [0] I have various nodes defined by function (e.g. database server) that inherit from a base node. One thing the base node does is check a fact that returns the location of the client. It then includes a module with the location-specific configuration, such as the ntp server. -- Brian Pitts Systems Administrator | EuPathDB Bioinformatics Resource Center 706-542-1447 | bdp@uga.edu | http://eupathdb.org -- 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Peter Meier
2010-Apr-27 07:52 UTC
Re: [Puppet Users] Setting Variable in Class or Node and Using in Included Module
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1> [0] I have various nodes defined by function (e.g. database server) that > inherit from a base node. One thing the base node does is check a fact > that returns the location of the client. It then includes a module with > the location-specific configuration, such as the ntp server.so you include in the base the ntp module and set the $ntp_servers variable in the sub-node? Yes, this will not work as when the ntp class is included the ntp_servers are not yet set. The best practice is to either go with an external node tool for complexe node definitions or at least not to use any includes in super-nodes which behavior you want to tweak with variables in sub-nodes, as inheritance in nodes don''t work the way most people expect it. cheers pete -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkvWl7YACgkQbwltcAfKi3/cQgCeIiiI7BrLadADj/nN60wn5vNe 9LkAn2v4r6jBgChk0HsI2/kCZUU24SH6 =uiQL -----END PGP SIGNATURE----- -- 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Bernd Adamowicz
2010-Apr-27 08:40 UTC
AW: [Puppet Users] Setting Variable in Class or Node and Using in Included Module
Sounds pretty much like the problem I posted yesterday. You may have a look at it here: http://groups.google.com/group/puppet-users/browse_thread/thread/336a6c1d941acca8/b50faf7711b7bf41?hl=en&lnk=gst&q=adamowicz#b50faf7711b7bf41. It seems that external node definitions and different environments are the solution for our problems. Just search the Puppet-Wiki and you''ll get the information on theses topics. Bernd> -----Ursprüngliche Nachricht----- > Von: puppet-users@googlegroups.com [mailto:puppet- > users@googlegroups.com] Im Auftrag von Brian Pitts > Gesendet: Dienstag, 27. April 2010 03:54 > An: puppet-users@googlegroups.com > Betreff: [Puppet Users] Setting Variable in Class or Node and Using in > Included Module > > Should the following approach to optionally including site-specific > information in modules work? It''s the third pattern documented at > http://serialized.net/2009/07/puppet-module-patterns/ > > In my case, I have > > modules/manifests/ntp/init.pp > > import "classes/*" > > if ($ntp_servers) { > $servers = $ntp_servers > } else { > $servers = ["0.rhel.pool.ntp.org", "1.rhel.pool.ntp.org", > "2.rhel.pool.ntp.org"] > notice("ntp: ntp_servers not set. Using red hat''s by default.") > } > > modules/manifests/ntp/classes/ntp.pp > > class ntp { > package { "ntp": > ensure => installed; > } > service { "ntpd": > enable => true, > ensure => running, > subscribe => File["/etc/ntp.conf"]; > } > # template iterates over values in $servers array > file { "/etc/ntp.conf": > ensure => file, > owner => "root", > group => "root", > mode => "644", > content => template("ntp/ntp.conf.erb"); > } > } > > And then in different classes [0] I set the ntp servers and include the > module like: > > $ntp_servers = ["timeserver1.example.edu", "timeserver2.example.edu"] > include ntp > > I often receive the error message "Failed to parse template > ntp/ntp.conf.erb: Could not find value for ''servers'' at > /etc/puppet/modules/ntp/manifests/classes/ntp.pp:19 on node > foo.example.edu" or my own notice() from the manifest above during > runs. > > I tried moving setting $ntp_servers from a class into a node, but that > did not make a difference. > > Can anyone point out what I''m doing wrong or why this approach won''t > work? I''ve read quite a bit on variable scope on the mailing list and > wiki, but I could still be missing something. I''m running puppet 0.24.8 > on RHEL5. > > [0] I have various nodes defined by function (e.g. database server) > that > inherit from a base node. One thing the base node does is check a fact > that returns the location of the client. It then includes a module with > the location-specific configuration, such as the ntp server. > > -- > Brian Pitts > Systems Administrator | EuPathDB Bioinformatics Resource Center > 706-542-1447 | bdp@uga.edu | http://eupathdb.org > > -- > 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+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en.-- 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Dan Carley
2010-Apr-27 09:48 UTC
Re: [Puppet Users] Setting Variable in Class or Node and Using in Included Module
On 27 April 2010 08:52, Peter Meier <peter.meier@immerda.ch> wrote:> The best practice is to either go with an external node tool for > complexe node definitions or at least not to use any includes in > super-nodes which behavior you want to tweak with variables in > sub-nodes, as inheritance in nodes don''t work the way most people expect > it. >Or similarly move the configuration data out of your manifests using RIP''s extlookup[0]. I use the precedence to set NTP servers on a default, per-domain or per-host (less common) basis. [0] http://code.google.com/p/extlookup/ -- 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Brian
2010-Apr-27 13:09 UTC
[Puppet Users] Re: Setting Variable in Class or Node and Using in Included Module
On Apr 27, 3:52 am, Peter Meier <peter.me...@immerda.ch> wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > > [0] I have various nodes defined by function (e.g. database server) that > > inherit from a base node. One thing the base node does is check a fact > > that returns the location of the client. It then includes a module with > > the location-specific configuration, such as the ntp server. > > so you include in the base the ntp module and set the $ntp_servers > variable in the sub-node? Yes, this will not work as when the ntp class > is included the ntp_servers are not yet set. >I think I understand why that wouldn''t work, but that''s not what I tried. I set the variable and include the module at the same level, as in the example I posted. These two lines are always in the same file. In my first attempt, the way it worked was I had this in my base node. case $location { foo: { include foo::base } bar: { include bar::base } default: { error("Cannot determine at what university $fqdn is located") } } and then in foo::base I had include ntp since that location was using the default value, and in bar::base I had $ntp_servers = ["timeserver1.example.edu", "timeserver2.example.edu"] include ntp since it was using a custom value. However, the value of $ntp_servers wasn''t being set properly for hosts at location bar, hence my post. In my second attempt I moved everything related to ntp out of foo::base and bar::base modules and into the base node, like so include ntp case $location { foo: { include foo::base } bar: { $ntp_servers = ["timeserver1.example.edu", "timeserver2.example.edu", "timeserver3.bar.edu"] include bar::base } default: { error("Cannot determine at what location $fqdn is located") } } However, that still did not work. Should either of these have worked? Why or why not? Could either be tweaked to work? All the best, Brian Pitts -- 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.