SlideShare a Scribd company logo
1 of 62
Download to read offline
PUPPET FUNDAMENTALS
About Puppet
• Puppet is an infrastructure automation and
configuration management tool
• Created by Luke Kanies in 2003 using Ruby.
• First commercial product released by
PuppetLabs in 2011
• 4000+ community members
• 50000+ nodes managed by largest deployments.
• Support for RedHat, ubuntu, Debian, Suse,
Solaris 10, Windows, MacOSX
WHY PUPPET ?
Common issues in traditional IT Ops
• Manually configure new nodes (servers)
• Custom scripts are written for specific OS,
environments
• Managing packages, patches across large
infrastructure.
• Configuration consistency across all nodes.
• Managing large infrastructure becomes
expensive.
Using puppet
• Enforces a defined state of the infrastructure
• Manages, automate tasks on 1000s of nodes
• Enable Infrastructure as a code
• Configuration consistency
• Increased productivity.
• Visibility of the infrastructure changes.
• Operational efficiency.
• Scalability
How Puppet works
Example: define
Pa kage { sshd :
Ensure => installed.
}
file { /et /sshd/sshd_config :
ensure => file,
owner => root,
group => root,
}
“e i e { sshd :
ensure => running.
enable => true.
}
Use Case
• You need to manage an user max
> verify user exist ?
> what is the primary group
> what is the secondary group
> what is the home directory
Existing Tools in *nix
• useradd
• usermod
• groupadd
• groupmod
• mkdir
• chmod
• chgrp
• chown
Command line concerns
• Do I have to use useradd or adduser
• What are the options to use ( -l or –L )
• If I run the same command again, does it
work?
Use a script
#! /bin/sh
USER=$1; GROUP=$2; HOME=$3
If [ 0 –ne $(getent passwd $USER > /dev/null)$? ]
then useradd $USER –home $HOME –gid $GROUP –n; fi
OLDGID=`getent passwd $USER | awk –F: {p i t $ } `
OLDGROUP=`getent group $OLDGID | awk –F: {p i t $ } `
OLDHOME=`getent passwd $USER | awk –F: {p i t $ } `
If [ $G‘OUP != $OLDGID ] && [ $G‘OUP != $OLDG‘OUP ]
then usermod –gid $GROUP $USER; fi
if [ $HOME != $OLDHOME ]
then usermod –home $HOME $USER; fi
But What about
• Readability
• What if Windows & other OS support
• Robust error checking and logging
• How about other complex tasks
Puppet way
user { max :
ensure => present,
gid => admin,
home => /data/max ,
managehome => true,
}
Desired State
Desired State
Use { elmo :
Ensure => present,
Gid => staff ,
Home => /mnt/home/elmo ,
...
}
Convergence
gid => sysadmin ,
home => /mnt/home/elmo ,
Drift
Node State
Use { elmo :
Ensure => present,
Gid => staff ,
Home => /ho e/elmo ,
}
Desired State
• Any convergence are reported back to the
server
• Provision a node, pupet configure it and
maintain the state.
• Puppet enforce the desired state in an
idempotent way.
Resource Abstraction Layer
File Package Service User
Ruby Apt
Yum
Gems
Dev
RPM
Redhat
Launched
SMF
Debian
Useradd
Ldap
Netinfo
Resource abstraction Layer
Facter
• Puppet uses facter to gather information
about node.
• Run $facter to know what are the facters on
your system
• The returned key-value pairs are called facts
• You can use these facts in your puppet
manifest.
Catalog compilation
Module structure
[root@master puppet]# tree modules/
modules/
`-- hello_world
|-- files
| `-- hello_world
|-- manifests
| `-- init.pp
|-- templates
`-- tests
`-- init.pp
Puppet Classes
Classes define a collection of resources that are managed together as a single Unit.
# /etc/puppetlabs/puppet/modules/ssh/manifests/init.pp
Class ssh {
Pa kage { openssh- lie ts :
Ensure => present,
}
File { /et /ssh/ssh_config :
O e => oot ,
G oup => oot ,
Mode => ,
‘e ui e => pa kage [ openssh- lie ts ],
“ou e => puppet:/// odules/ssh/ssh_ o fig ,
}
“e i e { sshd :
Ensure => stopped,
Enable => false,
}
}
Node Definition
Multiple classes are declared together to represent a Role
node agent.example.com {
include ssh
include mysql
include apache
}
Note: You can also use like below
class { ssh : }
include ssh
include ha_proxy_mbr
include apache
include web_app
include ssh
include ha_proxy
include ssh
include mysql
Node
web1.example.com
Node
lb.example.com
Node
db.example.com
Classes can be re-used
Class Naming Convention
• Class name must be unique
• Can be used only once on a given node
• Classes cannot be re-declared
• Ex – class hello_world
class apache::virtual_host
class myusers::group::finance
• Validate a class
puppet parser validate init.pp
Class Auto loading
• Classes load as per the modulepath
Read #man 5 puppet.conf for more details
Your First Module: Exercise
• Create a module for managing your user
account
• Steps:
> Create the module structure & support files
> Validate the syntax of your class
> Test the class on one of the agent node
Resources
• File
• Package
• User
• Service
#puppet resource file /etc/passwd
#puppet resource service sshd
#puppet describe user
Resource Abstraction Layer
File Package Service User
Ruby Apt
Yum
Gems
Dev
RPM
Redhat
Launched
SMF
Debian
Useradd
Ldap
Netinfo
Providers
•Providers are the interface between underlying OS and
resources.
Resource Relationship
• require
• subscribe
• notify
• before
(2) Containing Resource
(1) Reference
^
|
|
|
|
|
|
|
|
|
require
|
|
|
|
|
|
|
|
|
A containing resource can require a referenced resource to be applied first
require
Example
Pa kage { openssh :
Ensure => present,
}
“e i e { sshs :
Ensure => running,
Enable => true,
‘e ui e => Pa kage[ openssh ],
}
(1) Containing Resource
(2) Reference
A containing resource can request to be applied before a referenced resource
|
|
|
|
|
|
|
|
|
|
before
^
|
|
|
|
|
|
|
|
before
Example
Pa kage { openssh :
Ensure => present,
Befo e => se i e[ sshd ],
}
“e i es { sshd :
Ensure => running,
Enable => true,
}
Refresh Events
• Resource changes can refresh other events
• A change in configuration file must refresh
the service associated to it
• The subscribe and notify meta-parematers
can do it.
subscribe
(1) Reference
^
|
|
|
|
|
|
|
subscribe
|
|
|
|
|
|
|
|
|
(2) Containing Resource
refresh
Example:
Pa kage { ntp :
Ensure => present,
}
File { /et /ntp.conf :
O e => oot ,
G oup => oot ,
Mode => ,
“ou e => puppet:/// odules/ tp/ tp. o f ,
‘e ui e => Pa kage[ ntp ],
}
“e i es { ntpd :
Ensure => running,
Enable => true,
“u s i e => File[ /et /ntp.conf ],
}
notify
(1) Reference
^
|
|
|
|
|
|
|
notify
|
|
|
|
|
|
|
|
|
(2) Containing Resource
refresh
Common Use Case
• Package | File | Service
• One of the common design pattern used in
production
• Reasonable workflow
> Install a package
> configure one or more config files
> Enable the service
Language Constructs (DSL)
• How variables are used in Puppet
• How to use Arrays
• Conditional logic options in DSL
• Create a puppet manifest that works in
multiple OS
Variables
• Variables are prefixed with $
Ex: $application =
/var/tmp/prodevans.war
$confdir = /etc/httpd/conf.d
You can use double quote while using a string.
$string = My httpd config directory is
$confdir
Variable Example
$httpd_dir = /et /httpd/conf.d
File {
O e => oot ,
G oup => oot ,
Mode => ,
}
Scope
• Scope is a specific area of the code which is
isolated from other area
Ex:
Class example
Class example::other
Local scope locally override the variables
defined in the parent.
Global variables
• All facts are global variables
• :: is the scope operator for top scope facts
Ex:
$string = This is the home page for ${::hostname}
• Variables are constants, cannot be
reassigned.
Namevar
• Each resource has a special attribute called namevar.
• It is the unique identifier for the resource
• When it is omitted, by default it is same as that of title.
Ex: user { Max Anderson :
ensure => present,
name => max ,
gid => wheel .
}
• For packages package name is the namevar
• For files the path is the namevar
• The title of the resource can be different from the namevar
Arrays
• Puppet support Simple array.
Ex: $sample_array = [ one , two , three ]
File { [ /tmp/o e , /tmp/o e/t o , /tmp/o e/t o/th ee ] :
Ensure => directory
O e => oot ,
G oup => oot ,
Mode => ,
}
Conditional statements
• Puppet supports three conditional
expression.
> The selector
> case statement
> if-else / elsif statements
• Selectors return a value
• If-else & case alter the logic flow of puppet
code
Selector Values
• The value returned by selector can be used
Ex: package { ssh :
ensure => present ,
name => $::operatingsystem ? {
Ubuntu => ssh ,
default => openssh ,
},
}
• Selectors return a value, but do not evaluate a block of code
• Ideal for setting a variable or an attribute.
Case statement
• Case statements can be used around resources or a
collection of resources or other logical constructs
case $::operatingsystem {
debian : { $ssh_name = ssh }
RedHat : { $ssh_name = sshd }
default: { warning ( OS not supported ) }
}
• Always use the default match to avoid compilation issues.
Example:
Case $::operatingsystem {
ubuntu : {
$ssh_pkg = ssh
}
solaris : {
$ssh_pkg = [ SUNWsshcu , SUNWsshdr , SSNWsshu ]
}
# default assumes CentOs, RedHat
Default: {
$ssh_pkg = [ openssh , openssh- lie t , openssh-se e ]
}
}
Package { $ssh_pkg:
Ensure => present,
}
If-else / elsif
• These conditions act on boolean expressions
• Following values return false
> Undefined or nil value
>
> false
• Ex: if $mailserver {
file { /etc/mail : ensure => present }
}
else {
file { /etc/mail : ensure => absent }
}
Conditional expressions
• Boolean expressions
and , or , not
• Comparison expressions
== , != , =~ , < , >, <= , >=
• Arithmetic expressions
+ , - , / , *, << , >>
Example:
$server = ProdDBlapp01
if $server =~ /ProdDB/ {
notify { This is a database instance : }
}
else {
notify { This is not a database instance : }
}
ERB Templates
• Manage configuration files with dynamic
contents
• Use this technique to manage configuration
file for apache or tomat or JBoss
Templates
• Templates are usually text files
• Inserting ERB tags allows you to display or act
on content of the variable
• Ex: The system IP address is <%= @ipaddress %>
• Can be assigned to an attribute
File { /et / a i g :
ensure => present,
content =>
te plate apa he / a i g.e ,
}
Example:
• ssh_config template, enable X11 forwarding
only for CentOS hosts
#Puppet managed ssh_config file
Host *
GSSAPIAuthentication yes
<% if @operatingsystem == Ce tO“ then -%>
ForwardX11 yes
forwardX11Trusted yes
# virtually no client support untrusted mode
<% else -%>
Forward X11 no
<%end -%>
SendEnv LANG LC_*
Puppet Forge
• Puppet modules shared by community
• Search modules in the forge
• Share modules with others using the forge
• forge.puppetlabs.com
• From command line search
#puppet module search <modulename>
• Install a module
#puppet module install <modulename>
• Verify installed modules
#puppet module list --tree
Custom facts
• Facts written in ruby programming language
• Usually shell commands are issued as part of
the fact to return value
• Environment variable FACTERLIB
• use pluginsync = true in the main section of
/etc/puppet/puppet.conf
Hiera
• Installed by default after pupet 3.0 or later
• Hiera is a key-value lookup tool to provide
node specific data
• Easy to configure data on per node basis
• Keep node configuration in one place and
managing the node specific variables/data
will be easy
• Hiera implies hierarchical data
Hiera configuration
• /etc/hiera.yaml
(Config file for puppet opensource )
• /etc/puppetlabs/puppet/hiera.yaml
( Config file for enterprise puppet )
• Use hiera command to find out specific data
from hiera
• Referred inside puppet module as
$package_name = hiera( package_name )
Troubleshooting & Best practice
Managing puppet certificates
• puppet cert list
• puppet cert list –a
• puppet cert sign <hostname>
• puppet cert sign all
• puppet cert clean <hostname>
debug
• Agent run with –debug –verbose
• Verify the classname
• Verify if you have proper node classification
in site.pp or nodes.pp
• Verify agent configuration
Best practice
• Follow Package | config | service model
• Each small components must be created as
module and include them in other classes.
• Use editor to avoid syntax issue

More Related Content

What's hot

Augeas, swiss knife resources for your puppet tree
Augeas, swiss knife resources for your puppet treeAugeas, swiss knife resources for your puppet tree
Augeas, swiss knife resources for your puppet treeJulien Pivotto
 
Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopLorin Hochstein
 
Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點William Yeh
 
Getting started with Ansible
Getting started with AnsibleGetting started with Ansible
Getting started with AnsibleIvan Serdyuk
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)Soshi Nemoto
 
Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Soshi Nemoto
 
Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Brian Schott
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansibleGeorge Shuklin
 
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpecTest-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpecMartin Etmajer
 
DevOps(2) : Vagrant - (MOSG)
DevOps(2) : Vagrant  -  (MOSG)DevOps(2) : Vagrant  -  (MOSG)
DevOps(2) : Vagrant - (MOSG)Soshi Nemoto
 
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2Yros
 
Ansible not only for Dummies
Ansible not only for DummiesAnsible not only for Dummies
Ansible not only for DummiesŁukasz Proszek
 
Challenges when building high profile editorial sites
Challenges when building high profile editorial sitesChallenges when building high profile editorial sites
Challenges when building high profile editorial sitesYann Malet
 
“warpdrive”, making Python web application deployment magically easy.
“warpdrive”, making Python web application deployment magically easy.“warpdrive”, making Python web application deployment magically easy.
“warpdrive”, making Python web application deployment magically easy.Graham Dumpleton
 
From Dev to DevOps - FOSDEM 2012
From Dev to DevOps - FOSDEM 2012From Dev to DevOps - FOSDEM 2012
From Dev to DevOps - FOSDEM 2012Carlos Sanchez
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with AnsibleRayed Alrashed
 
From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011Carlos Sanchez
 
Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Carlos Sanchez
 
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014Puppet
 

What's hot (20)

Augeas, swiss knife resources for your puppet tree
Augeas, swiss knife resources for your puppet treeAugeas, swiss knife resources for your puppet tree
Augeas, swiss knife resources for your puppet tree
 
Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptop
 
Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點
 
Getting started with Ansible
Getting started with AnsibleGetting started with Ansible
Getting started with Ansible
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)
 
Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)
 
Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansible
 
Intro to-puppet
Intro to-puppetIntro to-puppet
Intro to-puppet
 
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpecTest-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
 
DevOps(2) : Vagrant - (MOSG)
DevOps(2) : Vagrant  -  (MOSG)DevOps(2) : Vagrant  -  (MOSG)
DevOps(2) : Vagrant - (MOSG)
 
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2
 
Ansible not only for Dummies
Ansible not only for DummiesAnsible not only for Dummies
Ansible not only for Dummies
 
Challenges when building high profile editorial sites
Challenges when building high profile editorial sitesChallenges when building high profile editorial sites
Challenges when building high profile editorial sites
 
“warpdrive”, making Python web application deployment magically easy.
“warpdrive”, making Python web application deployment magically easy.“warpdrive”, making Python web application deployment magically easy.
“warpdrive”, making Python web application deployment magically easy.
 
From Dev to DevOps - FOSDEM 2012
From Dev to DevOps - FOSDEM 2012From Dev to DevOps - FOSDEM 2012
From Dev to DevOps - FOSDEM 2012
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with Ansible
 
From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011
 
Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012
 
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
 

Viewers also liked

Getting started with Puppet
Getting started with PuppetGetting started with Puppet
Getting started with Puppetjeyg
 
Puppet overview
Puppet overviewPuppet overview
Puppet overviewjoshbeard
 
Pro Puppet
Pro PuppetPro Puppet
Pro Puppetdsadas
 
Puppet for SysAdmins
Puppet for SysAdminsPuppet for SysAdmins
Puppet for SysAdminsPuppet
 
Introduction to puppet
Introduction to puppetIntroduction to puppet
Introduction to puppetHabeeb Rahman
 
PuppetConf 2016: Puppet as Security Tooling – Bill Weiss, Puppet
PuppetConf 2016: Puppet as Security Tooling – Bill Weiss, PuppetPuppetConf 2016: Puppet as Security Tooling – Bill Weiss, Puppet
PuppetConf 2016: Puppet as Security Tooling – Bill Weiss, PuppetPuppet
 
Advice on how to get started — and ahead — in a career in DevOps
Advice on how to get started — and ahead — in a career in DevOpsAdvice on how to get started — and ahead — in a career in DevOps
Advice on how to get started — and ahead — in a career in DevOpsPuppet
 
What's New in Puppet Enterprise 2016.5
What's New in Puppet Enterprise 2016.5What's New in Puppet Enterprise 2016.5
What's New in Puppet Enterprise 2016.5Puppet
 
Puppet overview
Puppet overviewPuppet overview
Puppet overviewMike_Foto
 
Diving Into Puppet Providers Development: The Puppet-Corosync Module
Diving Into Puppet Providers Development: The Puppet-Corosync ModuleDiving Into Puppet Providers Development: The Puppet-Corosync Module
Diving Into Puppet Providers Development: The Puppet-Corosync ModuleJulien Pivotto
 
Introduction to Hiera
Introduction to HieraIntroduction to Hiera
Introduction to HieraPuppet
 
PBISE : Installation and Administration Guide v7.5
PBISE : Installation and Administration Guide v7.5PBISE : Installation and Administration Guide v7.5
PBISE : Installation and Administration Guide v7.5Kumaran Balachandran
 
商用ミドルウェアのPuppet化で気を付けたい5つのこと
商用ミドルウェアのPuppet化で気を付けたい5つのこと商用ミドルウェアのPuppet化で気を付けたい5つのこと
商用ミドルウェアのPuppet化で気を付けたい5つのことNTT DATA OSS Professional Services
 
PuppetConf 2016: Puppet Troubleshooting – Thomas Uphill, Wells Fargo
PuppetConf 2016: Puppet Troubleshooting – Thomas Uphill, Wells FargoPuppetConf 2016: Puppet Troubleshooting – Thomas Uphill, Wells Fargo
PuppetConf 2016: Puppet Troubleshooting – Thomas Uphill, Wells FargoPuppet
 
Junos space seminar
Junos space seminarJunos space seminar
Junos space seminarKappa Data
 

Viewers also liked (20)

Getting started with Puppet
Getting started with PuppetGetting started with Puppet
Getting started with Puppet
 
Puppet overview
Puppet overviewPuppet overview
Puppet overview
 
Pro Puppet
Pro PuppetPro Puppet
Pro Puppet
 
Puppet for SysAdmins
Puppet for SysAdminsPuppet for SysAdmins
Puppet for SysAdmins
 
Introduction to puppet
Introduction to puppetIntroduction to puppet
Introduction to puppet
 
PuppetConf 2016: Puppet as Security Tooling – Bill Weiss, Puppet
PuppetConf 2016: Puppet as Security Tooling – Bill Weiss, PuppetPuppetConf 2016: Puppet as Security Tooling – Bill Weiss, Puppet
PuppetConf 2016: Puppet as Security Tooling – Bill Weiss, Puppet
 
Advice on how to get started — and ahead — in a career in DevOps
Advice on how to get started — and ahead — in a career in DevOpsAdvice on how to get started — and ahead — in a career in DevOps
Advice on how to get started — and ahead — in a career in DevOps
 
What's New in Puppet Enterprise 2016.5
What's New in Puppet Enterprise 2016.5What's New in Puppet Enterprise 2016.5
What's New in Puppet Enterprise 2016.5
 
Puppet overview
Puppet overviewPuppet overview
Puppet overview
 
Diving Into Puppet Providers Development: The Puppet-Corosync Module
Diving Into Puppet Providers Development: The Puppet-Corosync ModuleDiving Into Puppet Providers Development: The Puppet-Corosync Module
Diving Into Puppet Providers Development: The Puppet-Corosync Module
 
The New Network is Programmable with Junos
The New Network is Programmable with JunosThe New Network is Programmable with Junos
The New Network is Programmable with Junos
 
Puppet for Junos
Puppet for JunosPuppet for Junos
Puppet for Junos
 
Introduction to Hiera
Introduction to HieraIntroduction to Hiera
Introduction to Hiera
 
PBISE : Installation and Administration Guide v7.5
PBISE : Installation and Administration Guide v7.5PBISE : Installation and Administration Guide v7.5
PBISE : Installation and Administration Guide v7.5
 
Puppet
PuppetPuppet
Puppet
 
商用ミドルウェアのPuppet化で気を付けたい5つのこと
商用ミドルウェアのPuppet化で気を付けたい5つのこと商用ミドルウェアのPuppet化で気を付けたい5つのこと
商用ミドルウェアのPuppet化で気を付けたい5つのこと
 
PuppetConf 2016: Puppet Troubleshooting – Thomas Uphill, Wells Fargo
PuppetConf 2016: Puppet Troubleshooting – Thomas Uphill, Wells FargoPuppetConf 2016: Puppet Troubleshooting – Thomas Uphill, Wells Fargo
PuppetConf 2016: Puppet Troubleshooting – Thomas Uphill, Wells Fargo
 
Network Innovation with Open Software
Network Innovation with Open SoftwareNetwork Innovation with Open Software
Network Innovation with Open Software
 
Junos space seminar
Junos space seminarJunos space seminar
Junos space seminar
 
OpenFlow Overview
OpenFlow OverviewOpenFlow Overview
OpenFlow Overview
 

Similar to Puppet fundamentals

Puppet: What _not_ to do
Puppet: What _not_ to doPuppet: What _not_ to do
Puppet: What _not_ to doPuppet
 
PuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with PuppetPuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with PuppetWalter Heck
 
PuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with PuppetPuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with PuppetOlinData
 
Learning Puppet basic thing
Learning Puppet basic thing Learning Puppet basic thing
Learning Puppet basic thing DaeHyung Lee
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013grim_radical
 
20090514 Introducing Puppet To Sasag
20090514 Introducing Puppet To Sasag20090514 Introducing Puppet To Sasag
20090514 Introducing Puppet To Sasaggarrett honeycutt
 
Using Puppet on Linux, Windows, and Mac OSX
Using Puppet on Linux, Windows, and Mac OSXUsing Puppet on Linux, Windows, and Mac OSX
Using Puppet on Linux, Windows, and Mac OSXPuppet
 
Developing IT infrastructures with Puppet
Developing IT infrastructures with PuppetDeveloping IT infrastructures with Puppet
Developing IT infrastructures with PuppetAlessandro Franceschi
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012Carlos Sanchez
 
Puppet modules: An Holistic Approach
Puppet modules: An Holistic ApproachPuppet modules: An Holistic Approach
Puppet modules: An Holistic ApproachAlessandro Franceschi
 
Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...
Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...
Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...Puppet
 
Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014Puppet
 
From Dev to DevOps
From Dev to DevOpsFrom Dev to DevOps
From Dev to DevOpsAgile Spain
 
Dance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkDance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkMichael Peacock
 

Similar to Puppet fundamentals (20)

Puppet: What _not_ to do
Puppet: What _not_ to doPuppet: What _not_ to do
Puppet: What _not_ to do
 
PuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with PuppetPuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with Puppet
 
PuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with PuppetPuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with Puppet
 
Learning Puppet basic thing
Learning Puppet basic thing Learning Puppet basic thing
Learning Puppet basic thing
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013
 
20090514 Introducing Puppet To Sasag
20090514 Introducing Puppet To Sasag20090514 Introducing Puppet To Sasag
20090514 Introducing Puppet To Sasag
 
Puppet
PuppetPuppet
Puppet
 
Puppet
PuppetPuppet
Puppet
 
Using Puppet on Linux, Windows, and Mac OSX
Using Puppet on Linux, Windows, and Mac OSXUsing Puppet on Linux, Windows, and Mac OSX
Using Puppet on Linux, Windows, and Mac OSX
 
Developing IT infrastructures with Puppet
Developing IT infrastructures with PuppetDeveloping IT infrastructures with Puppet
Developing IT infrastructures with Puppet
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
 
Puppet @ Seat
Puppet @ SeatPuppet @ Seat
Puppet @ Seat
 
Puppet modules: An Holistic Approach
Puppet modules: An Holistic ApproachPuppet modules: An Holistic Approach
Puppet modules: An Holistic Approach
 
Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...
Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...
Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...
 
Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014
 
Configuration management with Chef
Configuration management with ChefConfiguration management with Chef
Configuration management with Chef
 
From Dev to DevOps
From Dev to DevOpsFrom Dev to DevOps
From Dev to DevOps
 
Tutorial Puppet
Tutorial PuppetTutorial Puppet
Tutorial Puppet
 
Puppet - an introduction
Puppet - an introductionPuppet - an introduction
Puppet - an introduction
 
Dance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkDance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech Talk
 

Recently uploaded

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Recently uploaded (20)

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

Puppet fundamentals

  • 2. About Puppet • Puppet is an infrastructure automation and configuration management tool • Created by Luke Kanies in 2003 using Ruby. • First commercial product released by PuppetLabs in 2011 • 4000+ community members • 50000+ nodes managed by largest deployments. • Support for RedHat, ubuntu, Debian, Suse, Solaris 10, Windows, MacOSX
  • 4. Common issues in traditional IT Ops • Manually configure new nodes (servers) • Custom scripts are written for specific OS, environments • Managing packages, patches across large infrastructure. • Configuration consistency across all nodes. • Managing large infrastructure becomes expensive.
  • 5. Using puppet • Enforces a defined state of the infrastructure • Manages, automate tasks on 1000s of nodes • Enable Infrastructure as a code • Configuration consistency • Increased productivity. • Visibility of the infrastructure changes. • Operational efficiency. • Scalability
  • 7. Example: define Pa kage { sshd : Ensure => installed. } file { /et /sshd/sshd_config : ensure => file, owner => root, group => root, } “e i e { sshd : ensure => running. enable => true. }
  • 8. Use Case • You need to manage an user max > verify user exist ? > what is the primary group > what is the secondary group > what is the home directory
  • 9. Existing Tools in *nix • useradd • usermod • groupadd • groupmod • mkdir • chmod • chgrp • chown
  • 10. Command line concerns • Do I have to use useradd or adduser • What are the options to use ( -l or –L ) • If I run the same command again, does it work?
  • 11. Use a script #! /bin/sh USER=$1; GROUP=$2; HOME=$3 If [ 0 –ne $(getent passwd $USER > /dev/null)$? ] then useradd $USER –home $HOME –gid $GROUP –n; fi OLDGID=`getent passwd $USER | awk –F: {p i t $ } ` OLDGROUP=`getent group $OLDGID | awk –F: {p i t $ } ` OLDHOME=`getent passwd $USER | awk –F: {p i t $ } ` If [ $G‘OUP != $OLDGID ] && [ $G‘OUP != $OLDG‘OUP ] then usermod –gid $GROUP $USER; fi if [ $HOME != $OLDHOME ] then usermod –home $HOME $USER; fi
  • 12. But What about • Readability • What if Windows & other OS support • Robust error checking and logging • How about other complex tasks
  • 13. Puppet way user { max : ensure => present, gid => admin, home => /data/max , managehome => true, }
  • 14. Desired State Desired State Use { elmo : Ensure => present, Gid => staff , Home => /mnt/home/elmo , ... } Convergence gid => sysadmin , home => /mnt/home/elmo , Drift Node State Use { elmo : Ensure => present, Gid => staff , Home => /ho e/elmo , }
  • 15. Desired State • Any convergence are reported back to the server • Provision a node, pupet configure it and maintain the state. • Puppet enforce the desired state in an idempotent way.
  • 16. Resource Abstraction Layer File Package Service User Ruby Apt Yum Gems Dev RPM Redhat Launched SMF Debian Useradd Ldap Netinfo Resource abstraction Layer
  • 17. Facter • Puppet uses facter to gather information about node. • Run $facter to know what are the facters on your system • The returned key-value pairs are called facts • You can use these facts in your puppet manifest.
  • 19. Module structure [root@master puppet]# tree modules/ modules/ `-- hello_world |-- files | `-- hello_world |-- manifests | `-- init.pp |-- templates `-- tests `-- init.pp
  • 20. Puppet Classes Classes define a collection of resources that are managed together as a single Unit. # /etc/puppetlabs/puppet/modules/ssh/manifests/init.pp Class ssh { Pa kage { openssh- lie ts : Ensure => present, } File { /et /ssh/ssh_config : O e => oot , G oup => oot , Mode => , ‘e ui e => pa kage [ openssh- lie ts ], “ou e => puppet:/// odules/ssh/ssh_ o fig , } “e i e { sshd : Ensure => stopped, Enable => false, } }
  • 21. Node Definition Multiple classes are declared together to represent a Role node agent.example.com { include ssh include mysql include apache } Note: You can also use like below class { ssh : }
  • 22. include ssh include ha_proxy_mbr include apache include web_app include ssh include ha_proxy include ssh include mysql Node web1.example.com Node lb.example.com Node db.example.com Classes can be re-used
  • 23. Class Naming Convention • Class name must be unique • Can be used only once on a given node • Classes cannot be re-declared • Ex – class hello_world class apache::virtual_host class myusers::group::finance • Validate a class puppet parser validate init.pp
  • 24. Class Auto loading • Classes load as per the modulepath Read #man 5 puppet.conf for more details
  • 25. Your First Module: Exercise • Create a module for managing your user account • Steps: > Create the module structure & support files > Validate the syntax of your class > Test the class on one of the agent node
  • 26. Resources • File • Package • User • Service #puppet resource file /etc/passwd #puppet resource service sshd #puppet describe user
  • 27. Resource Abstraction Layer File Package Service User Ruby Apt Yum Gems Dev RPM Redhat Launched SMF Debian Useradd Ldap Netinfo Providers •Providers are the interface between underlying OS and resources.
  • 28. Resource Relationship • require • subscribe • notify • before
  • 29. (2) Containing Resource (1) Reference ^ | | | | | | | | | require | | | | | | | | | A containing resource can require a referenced resource to be applied first require
  • 30. Example Pa kage { openssh : Ensure => present, } “e i e { sshs : Ensure => running, Enable => true, ‘e ui e => Pa kage[ openssh ], }
  • 31. (1) Containing Resource (2) Reference A containing resource can request to be applied before a referenced resource | | | | | | | | | | before ^ | | | | | | | | before
  • 32. Example Pa kage { openssh : Ensure => present, Befo e => se i e[ sshd ], } “e i es { sshd : Ensure => running, Enable => true, }
  • 33. Refresh Events • Resource changes can refresh other events • A change in configuration file must refresh the service associated to it • The subscribe and notify meta-parematers can do it.
  • 35. Example: Pa kage { ntp : Ensure => present, } File { /et /ntp.conf : O e => oot , G oup => oot , Mode => , “ou e => puppet:/// odules/ tp/ tp. o f , ‘e ui e => Pa kage[ ntp ], } “e i es { ntpd : Ensure => running, Enable => true, “u s i e => File[ /et /ntp.conf ], }
  • 37. Common Use Case • Package | File | Service • One of the common design pattern used in production • Reasonable workflow > Install a package > configure one or more config files > Enable the service
  • 38. Language Constructs (DSL) • How variables are used in Puppet • How to use Arrays • Conditional logic options in DSL • Create a puppet manifest that works in multiple OS
  • 39. Variables • Variables are prefixed with $ Ex: $application = /var/tmp/prodevans.war $confdir = /etc/httpd/conf.d You can use double quote while using a string. $string = My httpd config directory is $confdir
  • 40. Variable Example $httpd_dir = /et /httpd/conf.d File { O e => oot , G oup => oot , Mode => , }
  • 41. Scope • Scope is a specific area of the code which is isolated from other area Ex: Class example Class example::other Local scope locally override the variables defined in the parent.
  • 42. Global variables • All facts are global variables • :: is the scope operator for top scope facts Ex: $string = This is the home page for ${::hostname} • Variables are constants, cannot be reassigned.
  • 43. Namevar • Each resource has a special attribute called namevar. • It is the unique identifier for the resource • When it is omitted, by default it is same as that of title. Ex: user { Max Anderson : ensure => present, name => max , gid => wheel . } • For packages package name is the namevar • For files the path is the namevar • The title of the resource can be different from the namevar
  • 44. Arrays • Puppet support Simple array. Ex: $sample_array = [ one , two , three ] File { [ /tmp/o e , /tmp/o e/t o , /tmp/o e/t o/th ee ] : Ensure => directory O e => oot , G oup => oot , Mode => , }
  • 45. Conditional statements • Puppet supports three conditional expression. > The selector > case statement > if-else / elsif statements • Selectors return a value • If-else & case alter the logic flow of puppet code
  • 46. Selector Values • The value returned by selector can be used Ex: package { ssh : ensure => present , name => $::operatingsystem ? { Ubuntu => ssh , default => openssh , }, } • Selectors return a value, but do not evaluate a block of code • Ideal for setting a variable or an attribute.
  • 47. Case statement • Case statements can be used around resources or a collection of resources or other logical constructs case $::operatingsystem { debian : { $ssh_name = ssh } RedHat : { $ssh_name = sshd } default: { warning ( OS not supported ) } } • Always use the default match to avoid compilation issues.
  • 48. Example: Case $::operatingsystem { ubuntu : { $ssh_pkg = ssh } solaris : { $ssh_pkg = [ SUNWsshcu , SUNWsshdr , SSNWsshu ] } # default assumes CentOs, RedHat Default: { $ssh_pkg = [ openssh , openssh- lie t , openssh-se e ] } } Package { $ssh_pkg: Ensure => present, }
  • 49. If-else / elsif • These conditions act on boolean expressions • Following values return false > Undefined or nil value > > false • Ex: if $mailserver { file { /etc/mail : ensure => present } } else { file { /etc/mail : ensure => absent } }
  • 50. Conditional expressions • Boolean expressions and , or , not • Comparison expressions == , != , =~ , < , >, <= , >= • Arithmetic expressions + , - , / , *, << , >>
  • 51. Example: $server = ProdDBlapp01 if $server =~ /ProdDB/ { notify { This is a database instance : } } else { notify { This is not a database instance : } }
  • 52. ERB Templates • Manage configuration files with dynamic contents • Use this technique to manage configuration file for apache or tomat or JBoss
  • 53. Templates • Templates are usually text files • Inserting ERB tags allows you to display or act on content of the variable • Ex: The system IP address is <%= @ipaddress %> • Can be assigned to an attribute File { /et / a i g : ensure => present, content => te plate apa he / a i g.e , }
  • 54. Example: • ssh_config template, enable X11 forwarding only for CentOS hosts #Puppet managed ssh_config file Host * GSSAPIAuthentication yes <% if @operatingsystem == Ce tO“ then -%> ForwardX11 yes forwardX11Trusted yes # virtually no client support untrusted mode <% else -%> Forward X11 no <%end -%> SendEnv LANG LC_*
  • 55. Puppet Forge • Puppet modules shared by community • Search modules in the forge • Share modules with others using the forge • forge.puppetlabs.com • From command line search #puppet module search <modulename> • Install a module #puppet module install <modulename> • Verify installed modules #puppet module list --tree
  • 56. Custom facts • Facts written in ruby programming language • Usually shell commands are issued as part of the fact to return value • Environment variable FACTERLIB • use pluginsync = true in the main section of /etc/puppet/puppet.conf
  • 57. Hiera • Installed by default after pupet 3.0 or later • Hiera is a key-value lookup tool to provide node specific data • Easy to configure data on per node basis • Keep node configuration in one place and managing the node specific variables/data will be easy • Hiera implies hierarchical data
  • 58. Hiera configuration • /etc/hiera.yaml (Config file for puppet opensource ) • /etc/puppetlabs/puppet/hiera.yaml ( Config file for enterprise puppet ) • Use hiera command to find out specific data from hiera • Referred inside puppet module as $package_name = hiera( package_name )
  • 60. Managing puppet certificates • puppet cert list • puppet cert list –a • puppet cert sign <hostname> • puppet cert sign all • puppet cert clean <hostname>
  • 61. debug • Agent run with –debug –verbose • Verify the classname • Verify if you have proper node classification in site.pp or nodes.pp • Verify agent configuration
  • 62. Best practice • Follow Package | config | service model • Each small components must be created as module and include them in other classes. • Use editor to avoid syntax issue