Puppet Workshop Overview Introduction #101 About Installation Syntax Module Introduction #101 Puppet configuration management tool The original definition comes from the military world. Where you try to define process to maintain complex system like weapons, vehicles. The goal was to revise capability; improve performance, reliability, or maintainability; extend life; reduce cost; reduce risk and liability; or correct defects. Why Puppet When I started to search for a good configuration tool, I was looking for more something simple. I were from the Python world and I dislike to writing Ruby Code. That's why I choose Puppet over Chef. I was afraid of getting to much in touch of ruby. But everyone make a mistake once in the while ;-) At this time Chef and Puppet was the good 'modern' configuration management tools. There are alternatives, but this were also not really option. For me it was a personal description that then make it through my work time. Nowadays I would choose maybe Chef. But Puppet is also about created in mind for admins. Chef has a stronger development background. So learning puppet can be less difficult then Chef. It always depends on the point of view you having. It was never any bad decision and both do there jobs good. I like to say more about the other tools. But I had much touch with them. In end I had something, that allows to define elements that puppet will transit to the Node. That is very awesome and helps a lot. Means we're going to define the desired state and puppet enforce it state on the Node for you. To be able to configure system only once. But begin able to deploy them as much as often. Further to ensure service running and don't mater about possible users configuration mistakes. What happend a lot with some of my developer and my boss ;-). Installation Torrent file or via my webserver: http://172.23.42.209:8080/ or via USB-Key Download VM PDFs (also print there) Virtualbox When you need it VM access: User: puppet Password: puppet Setup Goal: The goal is to have a simple module that allow you to create a Webserver Apache will be installed and should have at least two vhosts We're going only to use some basic elements. We're using the developer version of puppet from puppetlabs Some remarks: We're using puppet on Ubuntu 12.04.4 There are some issue with puppetlabs direct delivered packages Newer is better. So if possible try to use newer Ubuntu Verisons or Debian Let use some puppet Puppet Command puppet help puppet resource Syntax a manifest Example: user { 'afra': home => '/home/afra', ensure => 'present', shell => '/bin/zsh', } Syntax help puppet parser validate ./user.pp puppet-lint gem install puppet-lint Some detail about the things: user is a resource { starts the resource declaration 'afra' title of the resource home a attribute => sorting value to attribute '/home/afra' a value, with type of a string }ends the resource declaration resource can be use more often user { 'www-data': home => '/var/www', ensure => 'present', shell => '/bin/false', } user { 'afra': home => '/home/afra', ensure => 'present', shell => '/bin/zsh', } Wait..? How to use? root@workshop:~# puppet apply 002-create-users.pp Warning: Could not retrieve fact fqdn Notice: Compiled catalog for workshop in environment production in 0.08 seconds Notice: /Stage[main]/Main/User[afra]/ensure: created Notice: /Stage[main]/Main/User[www-data]/shell: shell changed '/bin/sh' to '/bin/false' Notice: Finished catalog run in 0.18 seconds Again? root@workshop:~# puppet apply 002-create-users.pp Warning: Could not retrieve fact fqdn Notice: Compiled catalog for workshop in environment production in 0.07 seconds Notice: Finished catalog run in 0.02 seconds So again user { 'www-data': home => '/var/www', ensure => 'present', shell => '/bin/false', } user { 'afra': home => '/home/afra', ensure => 'present', shell => '/bin/zsh', } user { 'afra': home => '/home/afra', ensure => 'present', shell => '/bin/zsh', } Warning: Could not retrieve fact fqdn Error: Duplicate declaration: User[afra] is already declared in file /root/003:12; cannot redeclare at /root/003:17 on node workshop Error: Duplicate declaration: User[afra] is already declared in file /root/003:12; cannot redeclare at /root/003:17 on node workshop Some more things # Command $name = "x" Create a variable with name notice Puppet function for display a message content = "Hello World" notice( "Some is in: $content") user { 'www-data': home => '/var/www', ensure => 'present', shell => '/bin/false', } user { 'afra': home => '/home/afra', ensure => 'present', shell => '/bin/zsh', } fix FQDN mistakes ... $hosts = " 127.0.0.1 localhost 127.0.1.1 workshop.test.vbox # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters " ... file { "/etc/hosts": ensure => file, content => $content, } Warning: Could not retrieve fact fqdn Notice: Scope(Class[main]): Some is in: Hello World Notice: Compiled catalog for workshop in environment production in 0.08 seconds Notice: Finished catalog run in 0.05 seconds Something is missing..... You need to restart hostname service service { "hostname": subscribe => File['/etc/hosts'] } Lets install apache package { "apache2": ensure => installed, } Test it curl http://192.168.56.150/ or in your web browser Let create a virtual host service { "apache2": enable => true, ensure => running, subscribe => File['/etc/apache2/sites-enabled/001-website'], } $vhost = " ServerAdmin 4k3nd0@gmail.com ServerName webserver.vbox ServerAlias www.webserver.vbox DocumentRoot /var/www/example.com/public_html " file { "/etc/apache2/sites-enabled/001-website": ensure => file, owner => 'www-data', group => 'www-data', content => $vhost } Don't forget the Hostname 127.0.1.1 workshop.test.vbox workshop webserver webserver.vbox Done? Lets go home! Nope Modules Lets finish it as we went: $vhost2 = " ServerAdmin 4k3nd0@gmail.com ServerName webserver2.vbox ServerAlias www.webserver2.vbox DocumentRoot /var/www/webserver/02 " file { "/etc/apache2/sites-enabled/002-website": ensure => file, owner => 'www-data', group => 'www-data', content => $vhost2 } Also need to update the service service { "apache2": enable => true, ensure => running, subscribe => File['/etc/apache2/sites-enabled/001-website'], } and the hostname webserver2 webserver2.vbox This is a lot of work How we can make this faster? Lets us a module! Lets install the module from puppetlabs puppet module install puppetlabs-apache Notice: Preparing to install into /etc/puppet/modules ... Notice: Downloading from https://forge.puppetlabs.com ... Notice: Installing -- do not interrupt ... /etc/puppet/modules └─┬ puppetlabs-apache (v0.11.0) ├── puppetlabs-concat (v1.0.1) └── puppetlabs-stdlib (v4.1.0) By default the packages are installed into /etc/ root@workshop:~# ls -l /etc/puppet/modules/ total 12 drwxr-xr-x 8 root root 4096 Feb 6 18:30 apache drwxr-xr-x 6 root root 4096 Feb 13 02:06 concat drwxr-xr-x 6 root root 4096 May 13 2013 stdlib First lets read the Documentation class { 'apache': } Classes: root@workshop:~# puppet module search apache Notice: Searching https://forge.puppetlabs.com ... class {...} Puppet and classes Classes can be understand as collection of resources They allow to be using parameters for defining the need. Apply the class class { 'apache': } Let build our vhosts class { 'apache': } apache::vhost { 'webserver.vbox': port => '80', docroot => '/var/www/webserver', docroot_owner => 'afra', docroot_group => 'afra', } apache::vhost { 'webserver2.vbox': port => '80', docroot => '/var/www/webserver2', docroot_owner => 'afra', docroot_group => 'afra', } root@workshop:~# puppet apply 010-apache-module.pp Notice: Scope(Class[main]): Some is in: Hello World Warning: Config file /etc/puppet/hiera.yaml not found, using Hiera defaults Error: Duplicate declaration: User[www-data] is already declared in file /root/010-apache-module.pp:23; cannot redeclare at /etc/puppet/modules/apache/manifests/init.pp:98 on node workshop.test.vbox Error: Duplicate declaration: User[www-data] is already declared in file /root/010-apache-module.pp:23; cannot redeclare at /etc/puppet/modules/apache/manifests/init.pp:98 on node workshop.test.vbox This class take care of all resource. So when we're facing a conflict puppet will complain. We need to remove the user { 'www-data':} resource. Exece. To allow to fetch some websites via wget Some more about the syntax Package installation via puppet puppet resource packages Service puppet notify, to allow to restart a service getting erb files what allow you to render virtual hosts Things that are missing: classes modules, puppet client server module, unittest, own pri Question? The End Thanks for listing