Daniel Sage
2013-Oct-29 05:23 UTC
[Puppet Users] Issues referencing a class from another module
Hi all, I''m currently experiencing an issue where a module cannot reference a class from another module. Currently, I''ve got two modules, workstation and nfs and I''m attempting to use a class from the nfs module inside the workstation module, like so: Workstation module: class acme_inc::workstation { # ensure the local acme user exists user { "acme": ensure => present, uid => ''1234'', gid => ''acme'', shell => ''/bin/bash'', home => ''/home/$user_name'', managehome => true, } ... SNIP ... # install and set up the nfs client class {''nfs'': class = "client", domain = "acme.example.com", } } NFS Module: class nfs ($class = ''client'', $domain = '''') { # install the class specific packages if $class == ''client'' { # install client NFS packages package { ''nfs-common'': ensure => installed, } } else { # install server NFS packages package { ''nfs-kernel-server'': ensure => installed, } } # make sure that idmapd is running service { ''idmapd'': name => $service_name, ensure => running, enable => true, subscribe => File[''idmapd.conf''], } # generate and send the config file file { ''idmapd.conf'': path => ''/etc/idmapd.conf'', ensure => file, require => Package[''nfs-common''], content => template("nfs/idmapd.conf.erb"), } } Is what I intend to do something supported by puppet? or do I have to load the NFS module in the site manifest? Because my end goal is to create a module for each of my clients, where each module can then load say nginx::vhost to build that clients nginx virtual host. That way my server entry in site.pp is just: node ''server.example.com'' { class {''ntp'': servers => [ "0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org", ], } include client1 include client2 } Again, is this possible in puppet, or do I have to scrap this idea and simply include all the client stuff inside the node definition? Any advise would be appreciated. Regards, Daniel Sage -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/cbdbfb44-643f-4eb4-bb73-f4db8c03c6c1%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Martin Alfke
2013-Oct-29 07:27 UTC
Re: [Puppet Users] Issues referencing a class from another module
Hi Daniel, including modules from other classes is fully supported. You only need to take care on proper module path. What you plan to do sound like the roles and profiles principle. http://www.craigdunn.org/2012/05/239/ hth, Martin On 29 Oct 2013, at 06:23, Daniel Sage <theheadsage@sagestower.com> wrote:> Hi all, > > I''m currently experiencing an issue where a module cannot reference a class from another module. > > Currently, I''ve got two modules, workstation and nfs and I''m attempting to use a class from the nfs module inside the workstation module, like so: > > Workstation module: > > class acme_inc::workstation { > > # ensure the local acme user exists > user { "acme": > ensure => present, > uid => ''1234'', > gid => ''acme'', > shell => ''/bin/bash'', > home => ''/home/$user_name'', > managehome => true, > } > > ... SNIP ... > > # install and set up the nfs client > class {''nfs'': > class = "client", > domain = "acme.example.com", > } > } > > NFS Module: > > class nfs ($class = ''client'', $domain = '''') { > > # install the class specific packages > if $class == ''client'' { > > # install client NFS packages > package { ''nfs-common'': > ensure => installed, > } > > } else { > > # install server NFS packages > package { ''nfs-kernel-server'': > ensure => installed, > } > } > > # make sure that idmapd is running > service { ''idmapd'': > name => $service_name, > ensure => running, > enable => true, > subscribe => File[''idmapd.conf''], > } > > # generate and send the config file > file { ''idmapd.conf'': > path => ''/etc/idmapd.conf'', > ensure => file, > require => Package[''nfs-common''], > content => template("nfs/idmapd.conf.erb"), > } > } > > Is what I intend to do something supported by puppet? or do I have to load the NFS module in the site manifest? Because my end goal is to create a module for each of my clients, where each module can then load say nginx::vhost to build that clients nginx virtual host. > > That way my server entry in site.pp is just: > > node ''server.example.com'' { > > class {''ntp'': > servers => [ "0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org", ], > } > > include client1 > include client2 > > } > > Again, is this possible in puppet, or do I have to scrap this idea and simply include all the client stuff inside the node definition? > > Any advise would be appreciated. > > Regards, > Daniel Sage > > -- > 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 view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/cbdbfb44-643f-4eb4-bb73-f4db8c03c6c1%40googlegroups.com. > 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 view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/BAE537E4-B799-40A2-9B90-C961810F4632%40gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Dan White
2013-Oct-29 13:08 UTC
Re: [Puppet Users] Issues referencing a class from another module
http://docs.puppetlabs.com/puppet/2.7/reference/lang_classes.html#declaring-a-class-with-require This might be what you are looking for. “Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.” Bill Waterson (Calvin & Hobbes) ----- Original Message ----- From: "Daniel Sage" <theheadsage@sagestower.com> To: puppet-users@googlegroups.com Sent: Tuesday, October 29, 2013 1:23:02 AM Subject: [Puppet Users] Issues referencing a class from another module Hi all, I''m currently experiencing an issue where a module cannot reference a class from another module. Currently, I''ve got two modules, workstation and nfs and I''m attempting to use a class from the nfs module inside the workstation module, like so: Workstation module: class acme_inc::workstation { # ensure the local acme user exists user { "acme": ensure => present, uid => ''1234'', gid => ''acme'', shell => ''/bin/bash'', home => ''/home/$user_name'', managehome => true, } ... SNIP ... # install and set up the nfs client class {''nfs'': class = "client", domain = "acme.example.com", } } NFS Module: class nfs ($class = ''client'', $domain = '''') { # install the class specific packages if $class == ''client'' { # install client NFS packages package { ''nfs-common'': ensure => installed, } } else { # install server NFS packages package { ''nfs-kernel-server'': ensure => installed, } } # make sure that idmapd is running service { ''idmapd'': name => $service_name, ensure => running, enable => true, subscribe => File[''idmapd.conf''], } # generate and send the config file file { ''idmapd.conf'': path => ''/etc/idmapd.conf'', ensure => file, require => Package[''nfs-common''], content => template("nfs/idmapd.conf.erb"), } } Is what I intend to do something supported by puppet? or do I have to load the NFS module in the site manifest? Because my end goal is to create a module for each of my clients, where each module can then load say nginx::vhost to build that clients nginx virtual host. That way my server entry in site.pp is just: node ''server.example.com'' { class {''ntp'': servers => [ "0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org", ], } include client1 include client2 } Again, is this possible in puppet, or do I have to scrap this idea and simply include all the client stuff inside the node definition? Any advise would be appreciated. Regards, Daniel Sage -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/cbdbfb44-643f-4eb4-bb73-f4db8c03c6c1%40googlegroups.com . 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 view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/85919935.4256496.1383052131837.JavaMail.root%40sz0126a.westchester.pa.mail.comcast.net. For more options, visit https://groups.google.com/groups/opt_out.
Daniel Sage
2013-Oct-29 13:45 UTC
Re: [Puppet Users] Issues referencing a class from another module
Hey all, Thanks for the links posted, I''ll take a look at them. My immediate problem however is if I run the code I included above, I get this error: Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find class acme_inc::workstation for puppet-agent.example.com on node puppet-master.example.com Now, if I comment out the following lines class {''nfs'': class = "client", domain = "acme.example.com", } Then the catalog will be applied successfully, so I know puppet knows where to find the acme_inc::workstation class. Is there a better way to reference the nfs class/module? Or is there a flaw with the acme_inc::workstation class that''s causing puppet to look for it in the wrong place when attempting to load the nfs module? Regards, Daniel Sage -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/1c1b2aa8-4116-4a51-a02e-32e025faca39%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Oct-29 13:48 UTC
[Puppet Users] Re: Issues referencing a class from another module
On Tuesday, October 29, 2013 12:23:02 AM UTC-5, Daniel Sage wrote:> > Hi all, > > I''m currently experiencing an issue where a module cannot reference a > class from another module. > >We''d be better able to diagnose the issue if you gave us the error message you receive, but my first guess is that you are not laying out your modules in the manner that enables the autoloader to find them.> Currently, I''ve got two modules, workstation and nfs and I''m attempting to > use a class from the nfs module inside the workstation module, like so: > > Workstation module: > > class acme_inc::workstation { > > [...] > > # install and set up the nfs client > class {''nfs'': > class = "client", > domain = "acme.example.com", > } > } > >That class definition ought to appear in <module_path>/acme_inc/manifests/workstation.pp. NFS Module:> > class nfs ($class = ''client'', $domain = '''') { > > [...] > } > >And that class definition ought to appear in <module_path>/nfs/manifests/init.pp. See http://docs.puppetlabs.com/puppet/2.7/reference/modules_fundamentals.html#module-layout for full details. 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 view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/f1507038-46ee-4bf7-a8bc-e583c4aa361e%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Daniel Sage
2013-Oct-29 22:44 UTC
[Puppet Users] Re: Issues referencing a class from another module
I just realised that there is a typo in my example. But the problem remains the same, if I''ve got the following code in acme_inc::workstation # install and set up the nfs client class {''nfs'': class => "client", domain => "acme.example.com", } then I get the following error Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find class acme_inc::workstation for puppet-agent-dev.example.com on node puppet-agent-dev.example.com The two classes are in the correct position, with acme_inc::workstation being /etc/puppet/modules/acme_inc/manifests/workstation.pp and the nfs class is in /etc/puppet/modules/nfs/manifests/init.pp -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/8ad31c90-a70d-431a-a3f1-20b4e6ca1699%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Oct-30 13:16 UTC
[Puppet Users] Re: Issues referencing a class from another module
On Tuesday, October 29, 2013 5:44:07 PM UTC-5, Daniel Sage wrote:> > I just realised that there is a typo in my example. But the problem > remains the same, if I''ve got the following code in acme_inc::workstation > > # install and set up the nfs client > class {''nfs'': > class => "client", > domain => "acme.example.com", > } > > then I get the following error > > Error: Could not retrieve catalog from remote server: Error 400 on SERVER: > Could not find class acme_inc::workstation for > puppet-agent-dev.example.com on node puppet-agent-dev.example.com > > The two classes are in the correct position, with acme_inc::workstation > being /etc/puppet/modules/acme_inc/manifests/workstation.pp and the nfs > class is in /etc/puppet/modules/nfs/manifests/init.pp > >It is conceivable that Puppet does not like you using ''class'' as a parameter name, since it is a Puppet keyword. If so, then this might work around the problem: # install and set up the nfs client class {''nfs'': ''class'' => "client", domain => "acme.example.com", } But if that indeed is successful, then you should take it merely as confirmation of the diagnosis. You should not allow such an issue to remain in your nfs module. If you do, it will bite you again. 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 view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/2596e6b3-5f6c-4a12-b2df-7cdecb092720%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.