SlideShare a Scribd company logo
Dance for the puppet
master
An introduction to Puppet
Michael Peacock
So, what is puppet
Provisioning tool
  “Open source configuration management
  tool”
Used to automate server management
  Configuration
  Installs & upgrades
  etc
Internal development team presentation

          Ground Six Limited
Idempotent
Can be ran multiple times without changing the
server (unless the configuration changes)
Instead of doing things, it checks or ensures
things:
 Ensuring a package is installed only installs it if
 it hasn’t been installed. Execs only run if their
 create file isn’t found (and puppet doesn’t
 think they have been ran)
Configuration within
Vagrant

Tell puppet to run
Tell it where the manifests live
Tell it the default manifest
Tell it where modules live
config.vm.provision :puppet do |puppet|
    puppet.manifests_path = "provision/manifests"
    puppet.manifest_file = "default.pp"
    puppet.module_path = "provision/modules"
  end
What can it do?
cron: install and manage cron jobs (scheduled_task on
windows)
exec: runs shall commands
user: create and manage user accounts
group: create and manage groups
file: create and manage files, folders and symlinks
notify: log something
service: manage running services
And more...the items in bold are known as resources within
puppet
Require
Many / all puppet options support a “require”
configuration
Defines other puppet tasks which must have
been successfully checked / executed before
this can be ran
 We only want to install packages once we
 have updated aptitude
 We only want to install MySQL drivers once
 we have the MySQL client/server installed
Require example


require => [ Package['mysql-client'], Package['mysql-server'] ]




   notice when referencing other puppet
   configurations, the resource type is capitalised
exec
command: command (including full path unless path
is also defined) to be executed. The “name” will be
used if omitted
user & group: to run the command as
create: a file that the command creates. If found,
the exec is not run
cwd: directory to run the command from
path: if full path for command isn’t supplied, path
must point to location of the command
exec: a note

 We create lock files in some of our exec
commands to prevent repeated execution,
 e.g. after installing the default database,
download something or run anything which
           can only be ran once.
exec: example
exec{ "create-db":
           command => '/bin/gunzip -c
/vagrant/database/default.sql.gz > db.sql &&
/usr/bin/mysql < db.sql && /bin/rm db.sql &&
/bin/touch /vagrant/mysqlimport.lock',
      require => [ Package['mysql-client'],
Package['mysql-server'] ],
      creates => "/vagrant/mysqlimport.lock",
      timeout => 0
    }
exec: another example
exec{ "compose":
          command => '/bin/rm -rfv /vagrant/vendor/* && /bin/rm
-f /vagrant/composer.lock && /usr/bin/curl -s
http://getcomposer.org/installer | /usr/bin/php -- --install-
dir=/vagrant && cd /vagrant && /usr/bin/php
/vagrant/composer.phar install',
          require => [ Package['curl'], Package['git-core'] ],
          creates => "/vagrant/composer.lock",
     timeout => 0
     }
exec: what we use it for

Installing the default MySQL database content
Install pear projects
Note: we should probably use or write a puppet
module to install pear projects we need, our
approach is a bit of a hack
subscribe & refreshonly
Some commands need to be ran periodically after
other things have ran
  More so the case when puppet manages
  existing infrastructure (using it to manage whats
  already on a machine and installing new things)
subscribe: defines other events which should cause the
task to run (like require, but refreshes the task)
refreshonly: instructs the task to only run when the other
tasks are completed
Installing software


Package “type”
We need to apt-get update first...
We want to ensure some of our installed
software is running
Update aptitude


  exec { 'apt-get   update':
       command =>   '/usr/bin/apt-get update',
       require =>   Exec['preparenetworking'],
       timeout =>   0
       }
Install package
We just need to ensure the package is present


       package { "apache2":
           ensure => present,
           require => Exec['apt-get update']
         }
Run the service


    service { "apache2":
        ensure => running,
        require => Package['apache2']
      }
Files

ensure: type of file - symlink (link), directory
target: for symlinks - set the target file
source:file to be copied (if copying a file)
owner: user who should own the file
group: group associated with the file
mode: file permissions e.g. 777
file: copy apache config
    Set the source: source => ‘/path/to/file’


file { '/etc/apache2/sites-available/default':
          source =>
'/vagrant/provision/modules/apache/files/default',
          owner => 'root',
          group => 'root'
     }
file: create a symlink
ensure => ‘link’


        file { '/var/www/vendor':
                ensure => 'link',
                target => '/vagrant/vendor',
                require => Package['apache2']
        }
file: create a folder

 ensure => ‘directory’

       file{ "/var/www/uploads":
               ensure => "directory",
               owner => "www-data",
               group => "www-data",
               mode   => 777,
       }
file: create several
  folders

$cache_directories = [ "/var/www/cache/", "/var/www/cache/pages",
                  "/var/www/cache/routes",
"/var/www/cache/templates",
                ]
    file { $cache_directories:
        ensure => "directory",
        owner => "www-data",
        group => "www-data",
        mode   => 777,
    }
Add a cron

command: the command to run
user: user to run the cron as
hour, minute, month, monthday, weekday
 can be defined as hour => 1 or
 hour => [1,2,3,5] or
 hour => [1-10]
Create a user

     user { "developer":
               ensure => "present",
               gid => "wheel",
               shell => "/bin/bash",
               home =>
     "/home/developer",
               managehome => true,
               password =>
     "passwordtest",
               require =>
     Group["wheel"]
          }
Create a group


      group { "wheel":
               ensure =>
      "present",
           }
Make the group a
sudoer
   We probably want to stop this being ran
   multiple times!


exec { "/bin/echo "%wheel ALL=(ALL) ALL" >> /etc/sudoers":
         require => Group["wheel"]
     }
Stages
Running things in a specific order can often be
important
Require often makes this easy for us, however
Exec’s don’t seem to use this reliably
We can define “stages” with a specific order.
We can then put puppet modules into stages
Default stage is Stage[main]
Stages example


   stage { 'first': before => Stage[main] }
   class {'apache': stage => first}
Importing modules
Import the module (assuming it is in the right
folder)
Include the module to be executed


                 import "apache"
                 include apache
Image Credits



http://www.flickr.com/photos/stephen_wong/5
60079730/

More Related Content

PPT
Powerful and flexible templates with Twig
KEY
Phpne august-2012-symfony-components-friends
PDF
Phinx talk
KEY
CodeIgniter 3.0
PPTX
An introduction to Laravel Passport
PDF
What happens in laravel 4 bootstraping
PDF
Codeigniter : Two Step View - Concept Implementation
PDF
Codeigniter : Using Third Party Components - Zend Framework Components
Powerful and flexible templates with Twig
Phpne august-2012-symfony-components-friends
Phinx talk
CodeIgniter 3.0
An introduction to Laravel Passport
What happens in laravel 4 bootstraping
Codeigniter : Two Step View - Concept Implementation
Codeigniter : Using Third Party Components - Zend Framework Components

What's hot (20)

PDF
Flask - Backend com Python - Semcomp 18
PDF
Extending the WordPress REST API - Josh Pollock
PDF
Filling the flask
PDF
Getting to The Loop - London Wordpress Meetup July 28th
PPTX
Dealing with Continuous Data Processing, ConFoo 2012
PPT
Real time server
PPTX
Flask – Python
PDF
Introducing Assetic: Asset Management for PHP 5.3
PDF
Add loop shortcode
KEY
PyCon US 2012 - State of WSGI 2
PDF
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
KEY
Mojo as a_client
PDF
Power shell examples_v4
PDF
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
PDF
Databases and MySQL
KEY
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
PDF
Javascript Frameworks for Joomla
PDF
Kyiv.py #17 Flask talk
PDF
Python RESTful webservices with Python: Flask and Django solutions
Flask - Backend com Python - Semcomp 18
Extending the WordPress REST API - Josh Pollock
Filling the flask
Getting to The Loop - London Wordpress Meetup July 28th
Dealing with Continuous Data Processing, ConFoo 2012
Real time server
Flask – Python
Introducing Assetic: Asset Management for PHP 5.3
Add loop shortcode
PyCon US 2012 - State of WSGI 2
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Mojo as a_client
Power shell examples_v4
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Databases and MySQL
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
Javascript Frameworks for Joomla
Kyiv.py #17 Flask talk
Python RESTful webservices with Python: Flask and Django solutions
Ad

Similar to Dance for the puppet master: G6 Tech Talk (20)

PPTX
Learning Puppet basic thing
PDF
DevOps Series: Extending vagrant with Puppet for configuration management
PDF
Systems Automation with Puppet
PDF
20090514 Introducing Puppet To Sasag
PDF
Puppet fundamentals
PDF
What we Learned Implementing Puppet at Backstop
PDF
Puppet: Eclipsecon ALM 2013
KEY
20100425 Configuration Management With Puppet Lfnw
PDF
Puppet: What _not_ to do
PDF
PuppetCamp Ghent - What Not to Do with Puppet
PDF
PuppetCamp Ghent - What Not to Do with Puppet
KEY
Puppet for Java developers - JavaZone NO 2012
PDF
Intro to-puppet
KEY
From Dev to DevOps - ApacheCON NA 2011
PDF
Using Puppet on Linux, Windows, and Mac OSX
PDF
Creating a mature puppet system
PDF
Creating a Mature Puppet System
KEY
Puppet for dummies - ZendCon 2011 Edition
PDF
From Dev to DevOps
PDF
Security Testing Using Infrastructure-As-Code
Learning Puppet basic thing
DevOps Series: Extending vagrant with Puppet for configuration management
Systems Automation with Puppet
20090514 Introducing Puppet To Sasag
Puppet fundamentals
What we Learned Implementing Puppet at Backstop
Puppet: Eclipsecon ALM 2013
20100425 Configuration Management With Puppet Lfnw
Puppet: What _not_ to do
PuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with Puppet
Puppet for Java developers - JavaZone NO 2012
Intro to-puppet
From Dev to DevOps - ApacheCON NA 2011
Using Puppet on Linux, Windows, and Mac OSX
Creating a mature puppet system
Creating a Mature Puppet System
Puppet for dummies - ZendCon 2011 Edition
From Dev to DevOps
Security Testing Using Infrastructure-As-Code
Ad

More from Michael Peacock (20)

PPTX
Immutable Infrastructure with Packer Ansible and Terraform
PPTX
Test driven APIs with Laravel
PPTX
Symfony Workflow Component - Introductory Lightning Talk
PPTX
Alexa, lets make a skill
PPTX
API Development with Laravel
PDF
Refactoring to symfony components
PPT
Introduction to OOP with PHP
KEY
KEY
Evolution of a big data project
PPTX
Real time voice call integration - Confoo 2012
PPTX
Data at Scale - Michael Peacock, Cloud Connect 2012
PPTX
Supermondays twilio
PPTX
PHP & Twilio
PPTX
PHP Continuous Data Processing
PPTX
PHP North East Registry Pattern
PPTX
PHP North East - Registry Design Pattern
PPTX
Supermondays: Jenkins CI lightning talk
PPTX
Corporate Structures - September 2010
PPTX
PHP North-East - Automated Deployment
PPTX
Abstracting functionality with centralised content
Immutable Infrastructure with Packer Ansible and Terraform
Test driven APIs with Laravel
Symfony Workflow Component - Introductory Lightning Talk
Alexa, lets make a skill
API Development with Laravel
Refactoring to symfony components
Introduction to OOP with PHP
Evolution of a big data project
Real time voice call integration - Confoo 2012
Data at Scale - Michael Peacock, Cloud Connect 2012
Supermondays twilio
PHP & Twilio
PHP Continuous Data Processing
PHP North East Registry Pattern
PHP North East - Registry Design Pattern
Supermondays: Jenkins CI lightning talk
Corporate Structures - September 2010
PHP North-East - Automated Deployment
Abstracting functionality with centralised content

Dance for the puppet master: G6 Tech Talk

  • 1. Dance for the puppet master An introduction to Puppet Michael Peacock
  • 2. So, what is puppet Provisioning tool “Open source configuration management tool” Used to automate server management Configuration Installs & upgrades etc
  • 3. Internal development team presentation Ground Six Limited
  • 4. Idempotent Can be ran multiple times without changing the server (unless the configuration changes) Instead of doing things, it checks or ensures things: Ensuring a package is installed only installs it if it hasn’t been installed. Execs only run if their create file isn’t found (and puppet doesn’t think they have been ran)
  • 5. Configuration within Vagrant Tell puppet to run Tell it where the manifests live Tell it the default manifest Tell it where modules live
  • 6. config.vm.provision :puppet do |puppet| puppet.manifests_path = "provision/manifests" puppet.manifest_file = "default.pp" puppet.module_path = "provision/modules" end
  • 7. What can it do? cron: install and manage cron jobs (scheduled_task on windows) exec: runs shall commands user: create and manage user accounts group: create and manage groups file: create and manage files, folders and symlinks notify: log something service: manage running services And more...the items in bold are known as resources within puppet
  • 8. Require Many / all puppet options support a “require” configuration Defines other puppet tasks which must have been successfully checked / executed before this can be ran We only want to install packages once we have updated aptitude We only want to install MySQL drivers once we have the MySQL client/server installed
  • 9. Require example require => [ Package['mysql-client'], Package['mysql-server'] ] notice when referencing other puppet configurations, the resource type is capitalised
  • 10. exec command: command (including full path unless path is also defined) to be executed. The “name” will be used if omitted user & group: to run the command as create: a file that the command creates. If found, the exec is not run cwd: directory to run the command from path: if full path for command isn’t supplied, path must point to location of the command
  • 11. exec: a note We create lock files in some of our exec commands to prevent repeated execution, e.g. after installing the default database, download something or run anything which can only be ran once.
  • 12. exec: example exec{ "create-db": command => '/bin/gunzip -c /vagrant/database/default.sql.gz > db.sql && /usr/bin/mysql < db.sql && /bin/rm db.sql && /bin/touch /vagrant/mysqlimport.lock', require => [ Package['mysql-client'], Package['mysql-server'] ], creates => "/vagrant/mysqlimport.lock", timeout => 0 }
  • 13. exec: another example exec{ "compose": command => '/bin/rm -rfv /vagrant/vendor/* && /bin/rm -f /vagrant/composer.lock && /usr/bin/curl -s http://getcomposer.org/installer | /usr/bin/php -- --install- dir=/vagrant && cd /vagrant && /usr/bin/php /vagrant/composer.phar install', require => [ Package['curl'], Package['git-core'] ], creates => "/vagrant/composer.lock", timeout => 0 }
  • 14. exec: what we use it for Installing the default MySQL database content Install pear projects Note: we should probably use or write a puppet module to install pear projects we need, our approach is a bit of a hack
  • 15. subscribe & refreshonly Some commands need to be ran periodically after other things have ran More so the case when puppet manages existing infrastructure (using it to manage whats already on a machine and installing new things) subscribe: defines other events which should cause the task to run (like require, but refreshes the task) refreshonly: instructs the task to only run when the other tasks are completed
  • 16. Installing software Package “type” We need to apt-get update first... We want to ensure some of our installed software is running
  • 17. Update aptitude exec { 'apt-get update': command => '/usr/bin/apt-get update', require => Exec['preparenetworking'], timeout => 0 }
  • 18. Install package We just need to ensure the package is present package { "apache2": ensure => present, require => Exec['apt-get update'] }
  • 19. Run the service service { "apache2": ensure => running, require => Package['apache2'] }
  • 20. Files ensure: type of file - symlink (link), directory target: for symlinks - set the target file source:file to be copied (if copying a file) owner: user who should own the file group: group associated with the file mode: file permissions e.g. 777
  • 21. file: copy apache config Set the source: source => ‘/path/to/file’ file { '/etc/apache2/sites-available/default': source => '/vagrant/provision/modules/apache/files/default', owner => 'root', group => 'root' }
  • 22. file: create a symlink ensure => ‘link’ file { '/var/www/vendor': ensure => 'link', target => '/vagrant/vendor', require => Package['apache2'] }
  • 23. file: create a folder ensure => ‘directory’ file{ "/var/www/uploads": ensure => "directory", owner => "www-data", group => "www-data", mode => 777, }
  • 24. file: create several folders $cache_directories = [ "/var/www/cache/", "/var/www/cache/pages", "/var/www/cache/routes", "/var/www/cache/templates", ] file { $cache_directories: ensure => "directory", owner => "www-data", group => "www-data", mode => 777, }
  • 25. Add a cron command: the command to run user: user to run the cron as hour, minute, month, monthday, weekday can be defined as hour => 1 or hour => [1,2,3,5] or hour => [1-10]
  • 26. Create a user user { "developer": ensure => "present", gid => "wheel", shell => "/bin/bash", home => "/home/developer", managehome => true, password => "passwordtest", require => Group["wheel"] }
  • 27. Create a group group { "wheel": ensure => "present", }
  • 28. Make the group a sudoer We probably want to stop this being ran multiple times! exec { "/bin/echo "%wheel ALL=(ALL) ALL" >> /etc/sudoers": require => Group["wheel"] }
  • 29. Stages Running things in a specific order can often be important Require often makes this easy for us, however Exec’s don’t seem to use this reliably We can define “stages” with a specific order. We can then put puppet modules into stages Default stage is Stage[main]
  • 30. Stages example stage { 'first': before => Stage[main] } class {'apache': stage => first}
  • 31. Importing modules Import the module (assuming it is in the right folder) Include the module to be executed import "apache" include apache