Professional Documents
Culture Documents
11 - Puppet
11 - Puppet
www.supinfo.com
Copyright © SUPINFO. All rights reserved
Puppet
Course objectives
By completing this course, you will:
Course topics
Course’s plan:
Configuration management.
Puppet, Chef and Cfengine
Puppet Installation. Install && setup
Puppetmaster. Puppetmaster said…
Puppet language basics. Nodes,
manifests and classes.
Puppet language advanced. Dive
into Puppet.
Puppet
Configuration management
Definition
— Puppet Labs
Configuration management
Why do we need it
Different solutions
3 ways for deploying software to the SI
Manually
Could take very long time
By scripts
Could be very hard
Multi-environment case
By configuration management software
Configuration management
Pros :
Centralized management
Automated management
Mass deployment
Configuration customization
Abstraction layer
Idempotence
“DevOps ready”
Configuration management
Principle
A client/server architecture.
The server has a reference
configuration.
The client queries the server.
The client makes change in
order to match the reference
configuration.
Configuration management
Principle
1. Pull Request
2. Reference configuration
3. Operations
4. (optionnal) Message code / error
Configuration management
Principle
Version control and security
Principle
What you can do
File transfer
File edition
Service management
Package management
Mount points management
Cron management
VLAN management
Command invocation
…
Configuration management
Comparison
3 major solutions :
Puppet
The most popular
Easiest solution
Chef
Puppet fork
Still young but very promising
CFEngine
The first CM software
The most resource-effective
More complex
Configuration management
Comparison
Timeline :
Configuration management
Comparison
Some differences
Comparison
Some similarities
Same origin
Specially designed for config
management
Client/server model
Standalone mode possible
CLI interface
Need to increase your skills
Configuration management
Stop-and-think
Stop-and-think
Which solution consumes less memory ?
Puppet
Cfengine
Chef
Configuration management
Stop-and-think
Which solution consumes less memory ?
Puppet
Cfengine
Chef
Puppet
Puppet Installation
Puppet
Some details and features
Puppet
Prerequisite and sources
Prerequisite
Existing DNS
Ruby
Installation sources :
Distribution repositories
RubyGem
Sources
Puppet Installation
Puppet
Client and server
Puppet server : Puppetmaster
Puppet client : Puppet (agent)
Note
u r e t h e
Ma k e s
g e n t is
e t A
Pupp U s e
nc h e d .
lau c r i p t .
i ni t s
the t a n
g e
If you f i r s t
r t h e
erro d i t …
m e , r e a
ti
Puppet Installation
Options Definitions
Stop-and-think
Stop-and-think
What do you need in order to run Puppet ?
Python
Ruby
Perl
PHP
Puppet Installation
Stop-and-think
What do you need in order to run Puppet ?
Python
Ruby
Perl
PHP
Puppet
Puppetmaster
Puppetmaster said…
Puppetmaster
Infrastructure is code.
Puppetmaster
Definition
puppet.conf
Global Puppetmaster settings
auth.conf
Global ACL
fileserver.conf
ACL for the Puppet fileserver
manifests directory
site.pp : global defaults
configuration
nodes.pp : manage hosts
Puppetmaster
modules directory
Contain one subdirectory per
module
manifests/init.pp
The module code
The best way to use Puppet
templates directory
The default directory which contains
templates.
Puppetmaster
[main]
logdir=/var/log/puppet
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet
factpath=$vardir/lib/facter
templatedir=$confdir/templates
server=debiantest.utopia.net
downcasefacts = true
Puppetmaster
Skeleton :
node basenode {
node ‘fqdn’ { include include ssh
module} include ntp
}
Node declaration
node 'test.utopia.net' inherits basenode {
Module inclusion include nagios
}
Inheritance
Puppetmaster
Stop-and-think
Stop-and-think
Where is the best place to write the code used for
managing a node configuration?
/etc/puppet/manifests/nodes.pp
/etc/puppet/manifests/site.pp
/etc/puppet/module/$module-name/manifests/
init.pp
/etc/puppet/puppet.conf
Puppetmaster
Stop-and-think
Where is the best place to write the code used for
managing a node configuration?
/etc/puppet/manifests/nodes.pp
/etc/puppet/manifests/site.pp
/etc/puppet/module/$module-name/manifests/
init.pp
/etc/puppet/puppet.conf
Puppetmaster
Stop-and-think
Where is the best place to write the actual puppet
code?
/etc/puppet/manifests/nodes.pp
/etc/puppet/manifests/site.pp
/etc/puppet/module/$module-name/manifests/
init.pp
/etc/puppet/puppet.conf
Puppetmaster
Stop-and-think
Where is the best place to write the actual puppet
code?
/etc/puppet/manifests/nodes.pp
/etc/puppet/manifests/site.pp
/etc/puppet/module/$module-name/manifests/
init.pp
/etc/puppet/puppet.conf
Puppetmaster
Stop-and-think
Where is the best place to specify which module a
node has to use?
/etc/puppet/manifests/nodes.pp
/etc/puppet/manifests/site.pp
/etc/puppet/module/$module-name/manifests/
init.pp
/etc/puppet/puppet.conf
Puppetmaster
Stop-and-think
Where is the best place to specify which module a
node has to use?
/etc/puppet/manifests/nodes.pp
/etc/puppet/manifests/site.pp
/etc/puppet/module/$module-name/manifests/
init.pp
/etc/puppet/puppet.conf
Puppet
Resources
File
Manage files
file { '/etc/passwd':
Content owner => 'root',
group => 'root',
Permissions mode => '0644',
source => ‘puppet:///base/passwd‘
Ownership }
Source attribute
Copy a file from the Puppetmaster to the node
puppet:/// followed by the relative source of the file
placed in /etc/puppet/modules/module-name/files/
Puppet language basics
Resources
Package
Resources
Service
Manage services
Wide provider support
Init service { ‘snmpd’:
ensure => running,
Systemd enable => true,
hasrestart => true,
Upstart hasstatus => true
}
And more…
Start, stop, restart, start on boot (enable) services
Puppet language basics
Stop-and-think
Stop-and-think
Puppet can copy a file from the Puppetmaster to the
node.
True
False
Puppet language basics
Stop-and-think
Puppet can copy a file from the Puppetmaster to the
node.
True
False
Puppet
Puppet language:
Advanced
Facter
The system profiler
Software used by Puppet ~ # facter
architecture => i386
Installed on nodes
domain => utopia.net
Collect various data, facterversion => 1.5.7
fqdn => debiantest.utopia.net
"facts", on node hardwaremodel => i686
Many facts already defined hostname => debiantest
id => root
by Facter […]
Possibility to create
your own facts
Puppet language advanced
Variables
Variables into classes
Begin by $
case $operatingsystem {
Can use facts or centos, redhat: { $service_name = 'ntpd' }
you own defined debian, ubuntu: { $service_name = 'ntp' }
}
variables
service { 'ntp':
Often used with
name => $service_name,
conditional ensure => running,
statements enable => true
}
Case statement
If statement
Puppet language advanced
Conditional statements
If/Elsif/Else Statement if $variable {
file { '/some/file': ensure => present }
Based on
} else {
the truth value of file { '/some/other/file': ensure =>
present }
a variable }
the value of an
if $server == 'mongrel' {
expression include mongrel
The truth of an } elsif $server == 'nginx' {
include nginx
arithmetic } else {
expression include thin
}
Expressions
Operators
Operators usable in if statements
Boolean expressions
And, or, not
Comparison expressions
== =! < > <= > >=
Arithmetic expressions
+ - / * >> (left shift) << (right shift)
Regular expressions
=~ !~
“in” expressions
allows to find if the left operand is in the right one.
Puppet language advanced
Templates
Custom text files
Per-node custom
configuration file {"hosts":
path => "/etc/hosts",
Use ERB language owner => root,
group => root,
Retrieve and use mode => 644,
facts content => template("base/hosts.erb")
}
Use file resource
ERB file placed <%=ipadress%> <%=fqdn%> <
in module %=hostname%>
template
directory
Puppet language advanced
Resources relationship
Relationship meta-parameters
before
Resource is applied before the target resource
require
Resource is applied after the target resource
notify
Like before + The target resource will refresh if the
notifying resource changes
subscribe
Like require + The subscribing resource will refresh if
the target resource changes.
Puppet language advanced
Resources relationship
Ordering relationship
package { 'openssh-server':
ensure => present,
before => File['/etc/ssh/sshd_config'],
}
file { '/etc/ssh/sshd_config':
ensure => file,
mode => 600,
source => 'puppet:///modules/sshd/sshd_config',
require => Package['openssh-server'],
}
Puppet language advanced
Resources relationship
Notification relationship
file { '/etc/ssh/sshd_config':
ensure => file,
mode => 600,
source => 'puppet:///modules/sshd/sshd_config',
notify => Service['sshd']
}
service { 'sshd':
ensure => running,
enable => true,
subscribe => File['/etc/ssh/sshd_config‘]
}
Puppet language advanced
Resources relationship
Chaining and refreshing
Ordering resources
The resource on the left is applied
before the resource on the right.
->
Refreshing
Kind of trigger
Restart a service after a file update
~>
# ntp.conf is applied first, and will notify the ntpd service if it changes:
File['/etc/ntp.conf'] ~> Service['ntpd']
Puppet language advanced
Stop-and-think
Stop-and-think
You want the service resource you’re writing refresh
when a configuration file is updated. You will use:
Before
After
Notify
Subscribe
Puppet language advanced
Stop-and-think
You want the service resource you’re writing refresh
when a configuration file is updated. You will use:
Before
After
Notify
Subscribe
Puppet
Course summary
Configuration Puppetmaster
Puppet
management
installation
The end