Files and Directories

Puppet docs: https://puppet.com/docs/puppet/5.5/types/file.html

Directory

file { '$DIRECTORY':
  ensure => directory,
  owner  => 'uid',
  group  => 'gid',
  mode   => '0755', 
}

File from files

file { '$FILE':
  ensure => file,
  owner  => 'uid',
  group  => 'gid',
  mode   => '0644',
  source => 'puppet:///modules/$module/$file',
}

File from erb template

file { '$FILE':
  ensure  => file,
  owner   => 'uid',
  group   => 'gid',
  mode    => '0644',
  content => template('$module/$file'),
}

Symbolic link

file { '$FILE':
  ensure => link,
  owner  => 'uid',
  group  => 'gid',
  mode   => '0644',
  target => $destination_path,
}

Packages

Ensure a package is present, absent, purged, or version locked

package { '$PACKAGE':
  ensure => [present, absent, purged, '1.34'],
}

Services

Ensure a service is running, enabled, or stopped

service { '$SERVICE':
  ensure => [running, stopped, enabled],
}

Exec

Run a shell command

exec { '$TITLE':
  command => 'shell command',
  path    => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}

Use one of the following to ensure the command does not run everytime

creates => '$file',
onlyif => 'This shell command exits 0',
unless => 'This shell command exits not 0',

Classes

Define a new class

class $CLASS (
$variable = $value,
){
}

Include a class

include $CLASS

Call a class

class { '$CLASS':
variable => 'variable',
}

 

Defines

Create a new define

define $DEFINE {
}

Call a define

$DEFINE { '$TITLE':
}

Dependencies

Require a file or directory

require => File['$FILE'],

Require a package

require => Package['$PACKAGE'],

Require a class

require => Class['$CLASS'],

Require a define

require => $DEFINE['$TITLE'],

i.e.

require => python::pip['uwsgi'],

Class X comes before Class Y

class { '$CLASS_X': }
-> class { '$CLASS_Y': }

Leave a Reply

Your email address will not be published. Required fields are marked *