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.
1. Puppet
Automated System Conļ¬guration 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
conļ¬guration
ā¢ is a client-server distribution
ā¢ Requirements:
ā¢ Ruby > 1.8.1 < 1.9
ā¢ Facter
3
Wednesday, December 8, 2010
4. Communication
ā¢ Security
ā¢ SSL certiļ¬cate based authentication
ā¢ manual signing of certiļ¬cate requests
ā¢ Layers:
ā¢ Conļ¬guration 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 Conļ¬guration Language - 1-6
ā¢ manifests/site.pp
ā¢ Global ļ¬le with node deļ¬nitions
ā¢ modules/<name>/manifests/init.pp
ā¢ Module initialization
ā¢ Use lower case for names (modules, templates, functions,
deļ¬nes, exec, resources,...)
8
Wednesday, December 8, 2010
9. Puppet Conļ¬guration Language - 2-6
ā¢ Resources
ā¢ user - create or remove users
ā¢ group - create or remove groups
ā¢ package install or remove distribution packages
ā¢ ļ¬le - create directories, symlinks, copy ļ¬les
ā¢ cron - add cron jobs
ā¢ service - run or stop services like daemons
9
Wednesday, December 8, 2010
10. Puppet Conļ¬guration Language - 3-6
ā¢ Classes
ā¢ aggregate resources for easier use
ā¢ subclasses (=nested classes) for modularity
ā¢ parameterised classes for more ļ¬exible handling
ā¢ classes support inheritance
10
Wednesday, December 8, 2010
11. Puppet Conļ¬guration Language - 4-6
ā¢ Deļ¬nitions
ā¢ reusable objects
ā¢ Modules
ā¢ combine collections of resources, classes and
deļ¬nitions
11
Wednesday, December 8, 2010
12. Puppet Conļ¬guration Language - 5-6
ā¢ Chaining resources
ā¢ make sure that a service is restarted after
ļ¬lechange
ā¢ make sure that conļ¬g ļ¬le is copied prior
starting a service
ā¢ make sure that a package is installed prior
starting the service
12
Wednesday, December 8, 2010
13. Puppet Conļ¬guration Language - 6-6
ā¢ Nodes
ā¢ connect modules and clases to systems
ā¢ nodenames are short hostname, fqdn or
ādefaultā
13
Wednesday, December 8, 2010
14. Manifests
ā¢ Deļ¬ne static resources
ļ¬le { ā/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
ļ¬le { āsshconļ¬gā:
a deļ¬nition
name => $operatingsystem ? {
solaris => ā/usr/local/etc/ssh/sshd_conļ¬gā,
default => ā/etc/ssh/sshd_conļ¬gā,
},
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 {
ļ¬le { ā/etc/ssh/sshd_conļ¬gā:
mode => 644,
source => āpuppet:///modules/sshd/etc/ssh/sshd_conļ¬gā,
}
}
20
Wednesday, December 8, 2010
23. Functions
ā¢ Directory structure e.g. read parameter
from conļ¬guration ļ¬le 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 conļ¬guration
ā¢ 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
ā¢ Conļ¬guration
ā¢ edit /usr/share/puppet-dashboard/conļ¬g/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 ļ¬le)
ā¢ 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
ā¢ Conļ¬gure puppet to store results
ā¢ [master] section: reports=http, store
ā¢ [agent] (v2.6) or [puppetd] section: report=true
ā¢ Conļ¬gure Database (e.g. MySQL)
66
Wednesday, December 8, 2010