This document provides an overview and agenda for a Puppet workshop. Puppet is an automated system configuration management tool. The workshop agenda includes installing and initializing Puppet, creating modules for user management and Apache site configuration, using templates, and setting up reporting and a dashboard. The document explains Puppet concepts like manifests, modules, templates, and functions. It also provides examples of Puppet configuration language and directory structures for modules.
Take control of your SAP testing with UiPath Test Suite
Automated System Configuration with Puppet
1. Puppet
Automated System Configuration Management
Martin Alfke <martin.alfke@buero20.org>
1
Wednesday, December 8, 2010
2. Agenda
• Part I - Puppet Basics
• General + Communication
• Manifests, Modules, Templates + Functions
• Part II - Puppet Workshop
• Part III - Working with Puppet
• GIT/SVN for Puppet
• Production / Test / Development
• Monitoring
2
Wednesday, December 8, 2010
3. General
• “Put simply, Puppet is a system for automating
system administration tasks”
• Puppet...
• is a declarative language for expressing system
configuration
• is a client-server distribution
• Requirements:
• Ruby > 1.8.1 < 1.9
• Facter
3
Wednesday, December 8, 2010
4. Communication
• Security
• SSL certificate based authentication
• manual signing of certificate requests
• Layers:
• Configuration Language
• Transaction layer
• Resource Abstraction Layer
4
Wednesday, December 8, 2010
5. Supported Platforms
• Linux
• Debian / Ubuntu / Fedora / CentOS / RHEL /
OEL / Mandriva / SuSE / Gentoo
• BSD
• FreeBSD / OpenBSD
• Other Unix
• OS X / Solaris / HP-UX
• Windows - coming in 2010
5
Wednesday, December 8, 2010
6. Functional Overview
• Clients connect to
Puppet Master
• Puppet Master send
clients description of
tasks
• Puppet Master stores
Clients reports
• Reports can be imported
into dashboard database
• Dashboard web interface
to reports
6
Wednesday, December 8, 2010
8. Puppet Configuration Language - 1-6
• manifests/site.pp
• Global file with node definitions
• modules/<name>/manifests/init.pp
• Module initialization
• Use lower case for names (modules, templates, functions,
defines, exec, resources,...)
8
Wednesday, December 8, 2010
9. Puppet Configuration Language - 2-6
• Resources
• user - create or remove users
• group - create or remove groups
• package install or remove distribution packages
• file - create directories, symlinks, copy files
• cron - add cron jobs
• service - run or stop services like daemons
9
Wednesday, December 8, 2010
10. Puppet Configuration Language - 3-6
• Classes
• aggregate resources for easier use
• subclasses (=nested classes) for modularity
• parameterised classes for more flexible handling
• classes support inheritance
10
Wednesday, December 8, 2010
11. Puppet Configuration Language - 4-6
• Definitions
• reusable objects
• Modules
• combine collections of resources, classes and
definitions
11
Wednesday, December 8, 2010
12. Puppet Configuration Language - 5-6
• Chaining resources
• make sure that a service is restarted after
filechange
• make sure that config file is copied prior
starting a service
• make sure that a package is installed prior
starting the service
12
Wednesday, December 8, 2010
13. Puppet Configuration Language - 6-6
• Nodes
• connect modules and clases to systems
• nodenames are short hostname, fqdn or
“default”
13
Wednesday, December 8, 2010
14. Manifests
• Define static resources
file { “/etc/passwd”: • Static resources have
owner => root, full path and name.
group => root,
mode => 644,
}
14
Wednesday, December 8, 2010
15. Manifests with facter Variables
• Using facter
variables inside
file { “sshconfig”:
a definition
name => $operatingsystem ? {
solaris => “/usr/local/etc/ssh/sshd_config”,
default => “/etc/ssh/sshd_config”,
},
owner => root,
group => root,
mode => 644,
}
15
Wednesday, December 8, 2010
16. Manifest with Sub-Classes
class mysql {
class client {
class packages {
package { "mysql-client": ensure => installed }
}
}
class server {
class packages {
package { "mysql-server": ensure => installed }
package { "mysql-common": ensure => installed }
16
Wednesday, December 8, 2010
20. Modules - Initialization Manifest
• init.pp manifest will be integrated
automatically when class name is
equal to module name
• modules/manifests/sshd/init.pp
class sshd {
file { “/etc/ssh/sshd_config”:
mode => 644,
source => “puppet:///modules/sshd/etc/ssh/sshd_config”,
}
}
20
Wednesday, December 8, 2010
23. Functions
• Directory structure e.g. read parameter
from configuration file using facter:
lib/
facter/
function.rb
• Content of library functions function.rb:
require ‘facter’
Facter.add(“PUPPET_FUNCTION”) do
%x{/bin/grep -E “^PUPPET_FUNCTION=” /etc/
puppet_function | sed -e ‘s/*.=//’ } .chomp
end
end
23
Wednesday, December 8, 2010
24. Agenda
• Part I - Puppet Basics
• General + Communication
• Manifests, Modules, Templates + Functions
• Part II - Puppet Workshop
• Part III - Working with Puppet
• GIT/SVN for Puppet
• Production / Test / Development
• Monitoring
24
Wednesday, December 8, 2010
25. Puppet Workshop
• Installation - Puppet master and client on puppet master only
• Initialization
• Installation - Puppet client on puppet client only
• Modules
• User Management
• Apache sites configuration
• Templating for /etc/hosts
• Setup Reporting and Dashboard
25
Wednesday, December 8, 2010
53. Puppet Workshop - Functions - 2-2
• including modules in manifests/site.pp
node default {
include <name>
}
53
Wednesday, December 8, 2010
54. Puppet Workshop - Facter Function - 1-4
• Facter Function
• provide additional fact
1. Module directories
mkdir -p modules/facter/lib/facter
54
Wednesday, December 8, 2010
55. Puppet Workshop - Facter Function - 2-4
2. function.rb
vi modules/facter/lib/facter/function.rb
require ʻfacterʼ
Facter.add(“PUPPET_FUNCTION”) do
! setcode do
! ! %x{/bin/grep -E “^PUPPET_FUNCTION=” /etc/puppet_function |
sed -e ʻs/.*=//ʼ}.chomp
! end
end
55
Wednesday, December 8, 2010
56. Puppet Workshop - Facter Function - 3-4
3. puppet.conf
section [main]
pluginsync = true
4. puppet run
puppetd --test
5. call facter puppet function
facter --puppet | grep puppet_function
56
Wednesday, December 8, 2010
57. Puppet Workshop - Facter Function - 4-4
3. use custom facts in manifests
case $puppet_function {
! “MYSQL”:! ! { include mysql }
! “APACHE”:!! { include apache }
! “PROXY”:! ! { include proxy }
...
}
57
Wednesday, December 8, 2010
59. Puppet Workshop - Dashboard - 2-5
• Configuration
• edit /usr/share/puppet-dashboard/config/database.yaml
• Create Database
• cd /usr/share/puppet-dashboard; rake RAILS_ENV
db:create or
• mysql -Ne ‘create database dashboard;’
59
Wednesday, December 8, 2010
60. Puppet Workshop - Dashboard - 3-5
• Initialize Database
• cd /usr/share/puppet-dashboard; rake
RAILS_ENV db:migrate
• Import Reports
• cd /usr/share/puppet-dashboard; rake
RAILS_ENV=production reports:import
60
Wednesday, December 8, 2010
61. Puppet Workshop - Dashboard - 4-5
• Start service
• cd /usr/share/puppet-dashboard; ./bin/server
-e production -d
• Review your Dashboard in browser
• http://<your puppetmaster ip>:3000/
61
Wednesday, December 8, 2010
62. Puppet Workshop - Dashboard - 5-5
• add error to manifest (e.g. point source to a
non existing file)
• run puppetd
• puppetd --test
• import data
• cd /usr/share/puppet-dashboard; rake
RAILS_ENV=production reports:import
• review dashboard
62
Wednesday, December 8, 2010
63. Agenda
• Part I - Puppet Basics
• General + Communication
• Manifests, Modules, Templates + Functions
• Part II - Puppet Workshop
• Part III - Working with Puppet
• GIT/SVN for Puppet
• Production / Test / Development
• Monitoring
63
Wednesday, December 8, 2010
64. Puppet into GIT/SVN
• Why revision control system?
• Co-working
• Branches
• Which RCS System?
• Which ever you prefer
64
Wednesday, December 8, 2010
65. Puppet Staging
• Production, Test and Development
• /etc/puppet/puppet.conf
• [main] - environment = ...
• [development] - modulepath=/etc/puppet/
development/modules
• [testing] - modulepath=/etc/puppet/testing/
modules
• [production] - modulepath=/etc/puppet/
production/modules
65
Wednesday, December 8, 2010
66. Puppet Monitoring
• Puppet Dashboard
• Configure puppet to store results
• [master] section: reports=http, store
• [agent] (v2.6) or [puppetd] section: report=true
• Configure Database (e.g. MySQL)
66
Wednesday, December 8, 2010