Ask Your Question

copy module, setup with foreman [closed]

asked 2015-07-10 13:16:31 -0600

HannibalRex gravatar image

Hi all! Disclaimer, VERY NEW USER to Puppet.

Was hoping someone might be able to point me to some documentation (or tell me how) with regards to adding a custom module. Here's the thing, I'm working with an existing Puppet environment, which is using Foreman on the front end. I need to add three users to the sudoers file on three specific servers. What I THINK I can do is: 1) copy /etc/puppet/modules/sudo to /etc/puppet/modules/sudoWinTeam 2) edit /etc/puppet/modules/sudoWinTeam/files/sudoers.lx and add the three Windows admins that need sudo access on three of my RHEL servers. So now I've got this module sitting there, how do I get Puppet to see it as a new module? Is it with: puppet module install --modulepath /etc/puppet/modules/sudoWinTeam ? Given that's all there is, and that the module is "installed" I assume I just go to Foreman, find the host(s), edit, go to classes, remove the "sudo" module/class, and add the sudoWinTeam? Am I on the right path? Mostly my two big questions are how to get Puppet to recognize the new module (sudoWinTeam), and then how to associate it with the three servers in Foreman. Once all that is good, I think I just need to start the puppet service on the three servers, and run puppet agent -t Is that right? Thanks in advance for any help! Jason

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by HannibalRex
close date 2015-07-13 08:27:32.917172

1 Answer

Sort by ยป oldest newest most voted

answered 2015-07-11 14:36:56 -0600

domcleal gravatar image

So yes, you can copy the module and create a new version of it, but it's overkill. I will however address the problems you had with that first:

  1. The name you chose will be problematic as it contains capital letters - remove those. See Allowed Module Names.
  2. Ensure you rename everything inside the module directory (e.g. in sudoWinTeam/manifests/init.pp) as they have to match the module directory name. "sudo" becomes "sudoWinTeam" in classes, defines, resource references etc.
  3. No need to use "puppet module install", that just downloads the module from the internet and puts it into /etc/puppet. Once you put it on disk, you're done.
  4. Once in the right /etc/puppet modules directory, then go to Configure > Puppet Classes > Import in Foreman which should detect it.
  5. If it doesn't detect it, check you don't have any syntax errors with puppet parser validate init.pp etc.

Ideally though, you can have a single reusable module, with a common set of working code, and then pass different data in depending on where it's used - this is the focus of most modules on Puppet Forge.

With Foreman this is usually by adding a parameter onto the sudo class that would define the users to add. You could have it as a list of users, then use a template in the module to generate the file dynamically, or just a parameter for which sudoers file to deploy.

You could change your class to something like:

class sudo($file = "sudoers.lx") {
  file { "/etc/sudoers":
    ensure => present,
    source => "puppet:///modules/sudo/${file}",

(A very stripped down and simplistic example.)

Then when you next import classes in Foreman, the new $file parameter shows up. From the class edit page, tick Override and then you can add an override for (or from the Parameters tab on the host page) to change file to "sudoers.winteam" or similar.

Templating is more typical for this sort of thing, so you could pass in an array of users. See Templating for more information about writing these.

edit flag offensive delete link more


Can not thank you enough, got it going! Already in love with Puppet, spent the weekend reading up on it, I can see I'll be using this a LOT. Thanks again!

HannibalRex gravatar imageHannibalRex ( 2015-07-13 08:27:10 -0600 )edit

Question Tools



Asked: 2015-07-10 13:16:31 -0600

Seen: 1,015 times

Last updated: Jul 11 '15