Professional Documents
Culture Documents
Puppet
by Luke Kanies
luke@reductivelabs.com
Presentation available at
git://github.com/reductivelabs/velocity_puppet_workshop_2009.git
Goals
Get an Introduction to Puppet
Build a simple Puppet Repository
Know how to use the tools
Introduction to Puppet
It's all about Resources
We've got a custom language
Some executables
Getting Help
#puppet on irc.freenode.net
http://groups.google.com/group/puppet-users
Support Contracts :)
Resources
1 ralsh package
2 ralsh user luke
3 ralsh user foo
4 ralsh user foo ensure=present shell=/bin/bash home=/Users/foo
5 ralsh user foo shell=/usr/bin/bash
6 ralsh user foo ensure=absent
examples/ralsh.sh
Language
1 file { "/tmp/example_file":
2 ensure => present
3 content => "This is a test\n",
4 mode => 640
5 }
examples/language.pp
Executables
puppet
ralsh
puppetd
puppetmasterd
puppetca
Produces:
Produces:
Puppet Classes
1 class foo {
2 file { "/tmp/foo": ensure => present }
3 }
examples/class_but_no_include.pp
Produces:
Including Classes
1 class foo {
2 file { "/tmp/foo": ensure => present }
3 }
4 include foo
examples/class_with_include.pp
Produces:
A Puppet Repository
Basic Repository Structure:
1 manifests/site.pp
2 modules/
3 modules/mymod/manifests/init.pp
4 modules/mymod/templates/mytemplate.erb
5 modules/mymod/plugins/puppet/parser/functions/myfunction.rb
repo/manifests/site.pp
Putting It Together
1 puppet --modulepath repo/modules repo/manifests/site.pp
Produces:
Server Arguments
--verbose: Provide extra logging
--no-daemonize: Do not background
--modulepath $PWD/repo/modules: Specify where to find our modules
--confdir /tmp/server: Use a non-standard configuration directory
--vardir /tmp/server: Use a non-standard state/var directory
--manifest $PWD/repo/manifests/site.pp: Specify the starting manifest to parse
--certdnsnames localhost: Configure localhost as an alias in the SSL Certificate
examples/default_server_arguments.sh
Produces:
1 /opt/rl/dist/apps/puppet/modules:/usr/share/puppet/modules
2 /etc/puppet
3 /var/puppet
Produces:
Agent Arguments
--test: Very helpful argument rollup
--confdir /tmp/server: Use a non-standard configuration directory
--vardir /tmp/server: Use a non-standard state/var directory
--server localhost: Specify the server to contact
Certificates
This is just Standard SSL(tm).
Produces:
1 No certificates to sign
On the server:
In repo/modules/sudo/manifests/init.pp:
1
2 class sudo {
3 file { "/usr/bin/sudo":
4 owner => root,
5 group => wheel,
6 mode => 4111
7 }
8 }
Managing Files
Create your sudoers file at repo/modules/sudo/files/sudoers, then add this to your
init.pp:
1 file { "/etc/sudoers":
2 owner => root,
3 group => wheel,
4 mode => 440,
5 source => "puppet:///sudo/sudoers"
6 }
Managing Heterogeneity
1 file { sudo:
2 path => $operatingsystem ? {
3 darwin => "/usr/bin/sudo",
4 default => "/usr/sbin/sudo",
5 },
6 owner => root,
7 group => 0,
8 mode => 4111
9 }
Facter
1 $ facter | wc -l
2 55
3 $ facter | grep name
4 hostname => phage
5 macosx_productname => Mac OS X
6 sp_local_host_name => phage
7 sp_machine_name => MacBook
8 sp_user_name => Luke Kanies (luke)
9 $
Relationships
1 class rels {
2 file { "/tmp/reltest": ensure => present }
3 exec { "/bin/echo got notified":
4 subscribe => File["/tmp/reltest"],
5 refreshonly => true
6 }
7 }
repo/modules/rels/manifests/init.pp
Produces:
Definitions
Can be considered a 'composite resource'
A simple way to model resources within Puppet's language
repo/modules/apache/manifests/vhost.pp
Note the qualified definition name. This is required for correct autoloading.
Using Definitions
1 class apache {
2 apache::vhost { 'reductivelabs.com':
3 docroot => "/var/www/reductivelabs.com"
4 }
5 apache::vhost { 'foo.com':
6 docroot => "/var/www/foo.com",
7 ensure => absent
8 }
9 }
repo/modules/apache/manifests/init.pp
repo/modules/apache/manifests/vhost2.pp
Things We Skipped
Reporting
Queueing
Inheritance
Storeconfigs
Export/Collect
Everything else we didn't cover
Obligatory Pitch
Reductive Labs provides support contracts, training, and custom development, and we use all of the
revenue to fund development, this kind of talk, and eating. Well, almost all.
Conclusion
luke@reductivelabs.com