Puppet Reference

August 3, 2018

Applying configuration

  • sudo puppet agent -t --noop - Pull config from puppet master, pretend to make changes
  • sudo puppet agent -t - Pull config from puppet master, make changes

When did it last run?

  • date --date="@$(sudo cat /var/lib/puppet/state/last_run_summary.yaml | grep last_run | xargs | cut -f2 -d )"

Modules

  • puppet module list - list modules
  • puppet module install puppetlabs-postgresql --version 4.9.0 - install forge module into local puppet master
  • puppet job run --nodes pasture-db.puppet.vm - check specified nodes and bring them upto correct puppet config

Certificates

  • puppet cert list - list certificates on puppet master
  • puppet cert sign hostname - allow access from specified hostname

Writing Manifests and Classes

  • puppet config print modulepath - show the path that puppet looks for modules on
  • puppet parser validate init.pp - check the file syntax for basic errors

Simple Module

init.pp

class cowsay {
  package { 'cowsay':
    ensure   => present,
    provider => 'gem',
  }
  include cowsay::fortune
}

fortune.pp

class cowsay::fortune {
  package { 'fortune-mod':
    ensure => present,
  } 
}

Package, File, Service Example

class pasture {
  package { 'pasture':
    ensure   => present,
    provider => gem,
    before   => File['/etc/pasture_config.yaml'],
  }

  file { '/etc/pasture_config.yaml':
    source => 'puppet:///modules/pasture/pasture_config.yaml',
    notify => Service['pasture'],
  }

  file { '/etc/systemd/system/pasture.service':
    source => 'puppet:///modules/pasture/pasture.service',
    notify => Service['pasture'],
  }

  service { 'pasture':
    ensure => running,
  } 
}

Tags: puppet reference