Title: Learn puppet terminology
Course: CIS 208: Linux/UNIX III: Intermediate System Administration, Networking, and Security ~ For IGNITE Review > Section: Learning Modules

Resources:
an atomic unit for configuring a system
resources can vary in size, complexity and lifespan
resources are grouped into types, such as user, group, file, package, etc.

puppet resource --help
like a man page
puppet resource --type
lists resource types
user, group, yumrepo, package, service, file
puppet resource user
lists for all users
puppet resource user root
lists a single user
password_max_age, password_min_age
puppet resource user adm
has groups, which root didn't
puppet resource user h4x0r
this user doesn't exist
puppet resource group
lists all groups
puppet resource group root
lists a single group
puppet resource group adm
are members listed?
grep ^adm: /etc/group
puppet resource group h4x0r
this group doesn't exist
puppet resource yumrepo centos
installed and enabled
puppet resource yumrepo contrib
installed, but not enabled
puppet resource yumrepo testing
not installed
puppet resource package ntp
ensure => '4.2.6p5-2.el6.centos',
ensure => 'installed',
ensure => 'latest',
puppet resource service ntpd
running, and on by default
puppet resource service restorecond
not running, and not on by default
puppet resource file /etc/ntp.conf
content => ...
https://docs.puppetlabs.com/puppet_core_types_cheatsheet.pdf

Resource types:
puppet describe
man page for describe
puppet describe -l
list available resource types
puppet describe -s user
give short description of type user
puppet describe user
give longer description of type user
puppet describe -s file
give short description of type file
puppet describe file
give longer description of type file

Manifests:
a puppet program file, with the extension .pp
contains one or more "resource declarations"
the "puppet resource" command shows a "resource declaration"
the "puppet apply" command runs a local manifest manually
the top-level manifest is /etc/puppet/manifests/site.pp
the "puppet agent" command runs the site.pp manifest from the master
the "puppet agent --test --noop" command checks the site.pp
the "puppet agent --test" command runs the site.pp

puppet resource user tux
cat > no_tux.pp <<EoT
user {'tux':
ensure => absent,
}
EoT

puppet apply no_tux.pp

Ordering:
puppet will automatically select the right order for most operations
you can't declare a file in a directory before the directory exists
you can even declare the file and the directory in separate manifests
however, the order can be declared using before, require, notify and subscribe
below is the classic package/file/service declaration

cat >> /etc/puppet/manifests/site.pp <<EoT
package { 'openssh-server':
ensure => present,
before => File['/etc/ssh/sshd_config'],
}
file { '/etc/ssh/sshd_config':
ensure => file,
mode   => 600,
#source => 'to be added later',
}
service { 'sshd':
ensure     => running,
enable     => true,
subscribe  => File['/etc/ssh/sshd_config'],
}
EoT
puppet parser validate /etc/puppet/manifests/site.pp
puppet agent --test --noop
chmod 700 /etc/ssh/sshd_config
puppet agent --test --noop
service sshd status
puppet agent --test
service sshd status
service sshd stop
puppet agent --test --noop
puppet agent --test
service sshd status

Variables, Facts, and Conditionals:
variables can store strings, numbers, booleans, etc. or the value undef
if a variable has not been assigned a value, its value is undef
a variable can only be assigned a value once, so really it's a constant
we'll ignore scopes for now
facts are pre-defined variables that contain system information
the "facter" command will list available facts on a system
the "if", "case", and "selector" statements make decisions based on variables

in site.pp
$firstmsg = "This host is managed by puppet running on $servername."
notify { "$firstmsg":}
puppet agent --test --noop
in site.pp
if $is_virtual == 'true' {
notify { "This is a virtual machine.": }
}
else {
notify { "This is real hardware.": }
}
puppet parser validate /etc/puppet/manifests/site.pp
puppet agent --test --noop