Boudewijn Ector
2011-Nov-28 14:45 UTC
[Puppet Users] newbie question : How to use modules/external recipes properly
Hi Guys, At my company, we''ve been trying to get puppet to run properly for quite some time and it really looks great... except for using external recipes using parameters etc. Let me explain the problem: We''ve got a an environment with a puppetmaster and some hosts, and we''ve created about a dozen of homebrew recipes (in order to understand how to use puppet properly)... Okay, my current recipes all have a class in /etc/puppet/modules/ <modulename>/manifests/init.pp and look like this: <code> class nagios-nrpe-server { package { "nagios-nrpe-server": ensure => present, } file { "/etc/nagios/nrpe.cfg": owner => root, group => root, mode => 644, source => "puppet:///nagios-nrpe-server/nrpe.cfg", } file { "/etc/nagios/nrpe_local.cfg": owner => root, group => root, mode => 644, source => "puppet:///nagios-nrpe-server/nrpe_local.cfg", } service { ''nagios-nrpe-server'': ensure => running, enable => true, hasrestart => true, hasstatus => true, subscribe => [File[''/etc/nagios/nrpe.cfg''],File[''/etc/nagios/ nrpe_local.cfg'']], require => Package[''nagios-nrpe-server''], } } </code> Sometimes we use an ERB-style template, which is pretty cool too. Classes are applied to client-machines using this (simplified) manifests/nodes.pp file: <code> node basenode { include ntp include denyhosts include ssh include nrpe include apt include mailname include sudo include motd include be-ict-essentials include munin-node } node ''xs4all-host'' inherits basenode { include resolv } node ''www.foo.nl'' inherits xs4all-host { } node ''sql.foo.nl'' inherits basenode { # some more modules.... } node ''www2.foo.nl'' inherits xs4all-host { # some more modules.... } </code> That''s fine, but I''m very interested in using the parametrised modules/ classes which everybody seems to use . I do see how they work, but I don''t actually understand in what way they''re being deployed to clients (ie. I do not know how include them properly in my nodes.pp and whether to create a class OR a module for those). For example, please have a look at: http://bitfieldconsulting.com/puppet-and-mysql-create-databases-and-users They''re creating a mysql::server class. How should I incorporate it in the sql.foo.nl node aforementioned? We''ve put the class in /etc/puppet/modules/mysql/manifests/init.pp , and that''s the first question I have. What should be the path? I''m actually a bit puzzled by the :: in the class name, but since it declares the server class as part of the mysql module the aforementioned path should be correct (I presume!). Agree? Okay, the next part is telling the sql.foo node to become a mysql server. I tried several constructions, all of which fail due to name resolution problems. <code> node ''sql.foo'' inherits basenode { $mysql_password = "C6dDIls49ci3GEzl1vgwRUXT" include mysql::server } </code> I think it should be like this, but apparently this is incorrect. Would someone please be so kind to explain how to use that kind of recipe? Of point me to the relevant documentation about it (most is either about setting up the basic puppet, or creating very nifty recipes....but I''m currently missing the link between those). Cheers, Boudewijn Ector -- 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.
Phillip Frost
2011-Nov-28 17:21 UTC
Re: [Puppet Users] newbie question : How to use modules/external recipes properly
On Nov 28, 2011, at 9:45 AM, Boudewijn Ector wrote:> They''re creating a mysql::server class. > How should I incorporate it in the sql.foo.nl node aforementioned? > > We''ve put the class in /etc/puppet/modules/mysql/manifests/init.pp , > and that''s the first question I have. What should be the path? I''m > actually a bit puzzled by the :: in the class name, but since it > declares the server class as part of the mysql module the > aforementioned path should be correct (I presume!). Agree?Here''s a start: http://docs.puppetlabs.com/guides/modules.html http://docs.puppetlabs.com/guides/parameterized_classes.html -- 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.
jcbollinger
2011-Nov-28 18:22 UTC
[Puppet Users] Re: newbie question : How to use modules/external recipes properly
On Nov 28, 8:45 am, Boudewijn Ector <beh...@boudewijnector.nl> wrote:> At my company, we''ve been trying to get puppet to run properly for > quite some time and it really looks great... except for using external > recipes using parameters etc. > > Let me explain the problem: > > [...] I''m very interested in using the parametrised modules/ > classes which everybody seems to use .You do realize that "Everybody is doing it" is one of the stereotypically terrible reasons for doing anything, right? You should deploy parameterized classes only when and where you decide that they provide the best available solution to a specific problem you are facing. In making such evaluations, you should account for the following considerations: 1) Class parameterization''s key purpose is to solve an historical Puppet problem involving the (dynamic) scope of variable names. If you are running Puppet 2.7 now, and it is not warning you about resolving variable names via dynamic scope, then you do not have that problem. 2) Parameterized classes do not serve well in some capacities where unparameterized ones do: 2a) they cannot safely be included more than once in the same catalog 2b) they are usually unsuited for subclassing 2c) they are messy to use where one class includes another, especially when such inclusions are chained. 3) There are alternatives to parameterization for feeding data to your classes: 3a) global variables, including node facts 3b) (other-) class variables 3c) external data (i.e. extlookup() or hiera) 4) Contrary to your perception, not everybody uses or even likes class parameterization 5) On the other hand, if you intend to use run stages (another convenience feature for which there are alternatives), then you may as well give in to the dark side now. You will have many of the problems attending class parameterization for every class that you explicitly assign to a stage, whether those classes are explicitly parameterized or not. 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Boudewijn Ector ICT
2011-Nov-28 22:07 UTC
Re: [Puppet Users] newbie question : How to use modules/external recipes properly
Op 28/11/2011 18:21, Phillip Frost schreef:> On Nov 28, 2011, at 9:45 AM, Boudewijn Ector wrote: > >> They''re creating a mysql::server class. >> How should I incorporate it in the sql.foo.nl node aforementioned? >> >> We''ve put the class in /etc/puppet/modules/mysql/manifests/init.pp , >> and that''s the first question I have. What should be the path? I''m >> actually a bit puzzled by the :: in the class name, but since it >> declares the server class as part of the mysql module the >> aforementioned path should be correct (I presume!). Agree? > Here''s a start: > > http://docs.puppetlabs.com/guides/modules.html > http://docs.puppetlabs.com/guides/parameterized_classes.html >That''s indeed a goot start, thank you very much. But I''m still not being able to get it to work. I''ve changed: - put the mysql::server module in /etc/puppet/modules/mysql/manifests/server.pp - in nodes.pp: node ''sql.foo'' inherits basenode { $mysql_password = "C6dDIls49ci3GEzl1vgwRUXT" include mysql::server } This works fine, except for the $mysql_password not being passed properly to the class. Therefore I''ve tried to parametrize the class, and I think I should be using this syntax (according to the table in http://docs.puppetlabs.com/guides/modules.html) foo::params { "example": value => ''meow'' } So.... node ''sql.foo'' inherits basenode { mysql::server { "mysql_password":value => ''C6dDIls49ci3GEzl1vgwRUXT'' } } And more importantly, I''ve changed the heading of the server class to: class mysql::server ($mysql_password) { This still isn''t working, I''m getting erorrs such as: err: Could not retrieve catalog from remote server: Error 400 on SERVER: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type mysql::server at /etc/puppet/manifests/nodes.pp:21 on node sql.foo When I also add the include keyword I get: debug: catalog supports formats: b64_zlib_yaml dot marshal pson raw yaml; using pson err: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not parse for environment production: Syntax error at ''{''; expected ''}'' at /etc/puppet/manifests/nodes.pp:21 on node lsp-vp-db1.boudewijnector.nl Can you please tell me where I''m messing up despite reading the documentation? Cheers, Boudewijn -- 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.
Phil Frost
2011-Nov-28 23:25 UTC
Re: [Puppet Users] newbie question : How to use modules/external recipes properly
On 11/28/2011 05:07 PM, Boudewijn Ector ICT wrote:> Op 28/11/2011 18:21, Phillip Frost schreef: >> On Nov 28, 2011, at 9:45 AM, Boudewijn Ector wrote: >> >>> They''re creating a mysql::server class. >>> How should I incorporate it in the sql.foo.nl node aforementioned? >>> >>> We''ve put the class in /etc/puppet/modules/mysql/manifests/init.pp , >>> and that''s the first question I have. What should be the path? I''m >>> actually a bit puzzled by the :: in the class name, but since it >>> declares the server class as part of the mysql module the >>> aforementioned path should be correct (I presume!). Agree? >> Here''s a start: >> >> http://docs.puppetlabs.com/guides/modules.html >> http://docs.puppetlabs.com/guides/parameterized_classes.html >> > mysql::server { "mysql_password":value => > ''C6dDIls49ci3GEzl1vgwRUXT'' } > > This still isn''t working, I''m getting erorrs such as: > > err: Could not retrieve catalog from remote server: Error 400 on > SERVER: Puppet::Parser::AST::Resource failed with error ArgumentError: > Invalid resource type mysql::server at > /etc/puppet/manifests/nodes.pp:21 on node sql.fooWhat you are asking puppet to do is create a "mysql::server" with the name "mysql_password", passing it a parameter called "value" with the value "C6dD...". Probably not what you intended. You would use this syntax if you had defined a resource, with something starting with "define mysql::server" in server.pp. However, I assume mysql::server is a class, ie server.pp begins with "class mysql::server". So, the type of the resource is "class", and the name is "mysql::server". To declare it (ie, to say that your node is one of this class), you would put this in your node: class { "mysql::server": mysql_password => "...", other_parameter => "other_value", [etc...] } This is detailed here: http://docs.puppetlabs.com/guides/parameterized_classes.html#declaring-a-parameterized-class -- 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.