Issues referencing a class from another module

36 views
Skip to first unread message

Daniel Sage

unread,
Oct 29, 2013, 1:23:02 AM10/29/13
to puppet...@googlegroups.com
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:


    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

Martin Alfke

unread,
Oct 29, 2013, 3:27:50 AM10/29/13
to puppet...@googlegroups.com
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
> --
> 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...@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.

Dan White

unread,
Oct 29, 2013, 9:08:51 AM10/29/13
to puppet...@googlegroups.com
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)


From: "Daniel Sage" <thehe...@sagestower.com>
To: puppet...@googlegroups.com
Sent: Tuesday, October 29, 2013 1:23:02 AM
Subject: [Puppet Users] Issues referencing a class from another module
--

Daniel Sage

unread,
Oct 29, 2013, 9:45:47 AM10/29/13
to puppet...@googlegroups.com
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

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

jcbollinger

unread,
Oct 29, 2013, 9:48:48 AM10/29/13
to puppet...@googlegroups.com


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

Daniel Sage

unread,
Oct 29, 2013, 6:44:07 PM10/29/13
to puppet...@googlegroups.com
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

jcbollinger

unread,
Oct 30, 2013, 9:16:33 AM10/30/13
to puppet...@googlegroups.com


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

Reply all
Reply to author
Forward
0 new messages