Puppet Notes

Modules

Install module on Puppet Server

/opt/puppetlabs/bin/puppet module install <name of module>

Uninstall module on Puppet Server

/opt/puppetlabs/bin/puppet module uninstall <name of module>

Resource: https://www.puppetcookbook.com/posts/installing-modules-from-the-puppet-forge.html

List installed Modules

puppet module list

Resource: https://puppet.com/docs/puppet/5.3/modules_installing.html

Change module install path

By default, puppet module install installs modules into the first directory in the Puppet modulepath, which defaults to $codedir/environments/production/modules.

To change this, set the modulepath in /etc/puppetlabs/code/environments/{environment_name}/environment.conf

Resource: https://serverfault.com/questions/705623/install-a-puppet-module-to-the-global-modules-directory-by-default

List all agents connected to server

puppetserver ca list --all

Golang code to get the agents and dedup (if there's dns info):

Use a regex like this: (\\w+\\.\\w+\\.\\w+) with your chosen language to grab the hostnames (don't forget to dedup if there's DNS info that comes back from the initial command).

Remove agent from server

puppetserver ca clean --certname <name of node>

Install multiple dependencies

init.pp:

class base (){
  class{'::base::config':}
}

packages.pp:

class base::packages inherits base {
 [
    'cmake',
    'jdk',
    'vim',
  ].each |$pkg| {
    package { $pkg:
      ensure   => latest,
      name     => $pkg,
      provider => 'yum'
    }
  }
}

Output machine info

notify { 'Machine Information':
  name     => 'mach_info',
  message  => "Running on ${::hostname} in the ${::environment} environment",
  withpath => true,
}