Download - Introduction to Puppet Scripting
![Page 2: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/2.jpg)
What is puppet?
“Puppet is IT automation software that helps system administrators manage infrastructure throughout its lifecycle, from provisioning and configuration to patch management and compliance.”
Source: www.puppetlabs.com/puppet/what-is-puppet
![Page 3: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/3.jpg)
What does that mean?
• You can setup a new server in minutes vs. hours!
• You can be sure your server configurations are consistent.
• You can easily deploy configuration changes to multiple servers.
Image Source: http://www.forbes.com/sites/kenkrogue/2012/09/07/the-most-important-interview-question-never-asked/
![Page 4: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/4.jpg)
Quick Demo
Image source: http://gyaniji.blogspot.com/2011/12/demo-of-ad-posting-job.html
![Page 5: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/5.jpg)
What happened?
• Puppet analyzed the scripts to build a picture of what the server should look like.
• Puppet then compared that to what the server actually looks like.
• It then generates and executes scripts to make the server configuration match that in the puppet scripts.
![Page 6: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/6.jpg)
How vs. What
• Why is it better to describe what a system looks like rather than how to configure a system?
• When you describe what a system looks like, you can repeatedly rerun the process without fear of breaking the system.
• Can build platform independent scripts.
![Page 7: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/7.jpg)
What are the pieces?
• Puppet Software• Module Library• Node configuration file• [optional] Puppet Master
![Page 8: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/8.jpg)
Modules
What are they?• Self-contained packages that describe an aspect
of a system (e.g. “Apache” or “MySQL”)
Are there existing packages I can leverage?• http://forge.puppetlabs.com• http://github.com
Where do I put them?• /usr/share/puppet/modules• /etc/puppet/modules
![Page 9: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/9.jpg)
File Organization
• manifests• site.pp• nodes.pp
• modules• module1• manifests
init.pp
• files• templates• module2
![Page 10: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/10.jpg)
Demo: Folder Structure
Image source: http://gyaniji.blogspot.com/2011/12/demo-of-ad-posting-job.html
![Page 11: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/11.jpg)
Basic Syntax
• Follows basic Ruby language syntax.• Does not fully implement the Ruby language
though, only a subset is allowed in your puppet files.To define an item:
type title($arg1) { description of resource state}
To execute an item:
include “title”
type {“title”: }
type {“title”: arg1 => ‘hello’ }
![Page 12: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/12.jpg)
Demo: Simple script
Image source: http://gyaniji.blogspot.com/2011/12/demo-of-ad-posting-job.html
![Page 13: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/13.jpg)
Resource Types
• Are puppet libraries that are used to interact with the system.
• Puppet comes with a wide range of resource types:
• exec• package• file• service• notify
Full list: http://docs.puppetlabs.com/references/latest/type.html
![Page 14: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/14.jpg)
Facter
What are facts?• Global variables with information about the
system that the script is running on.
How do I see the available variables?• facter -p
How do I use them?• $::variable_name
![Page 15: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/15.jpg)
Templates
• Templates are files that use a simple markup language to insert dynamic values.
• Templates have an .erb extension• Typically used with the File resource. e.g.:
file {'ntp.conf': path => '/etc/ntp.conf', ensure => file, content => template('ntp/ntp.conf.erb'), owner => root, mode => 0644,}
![Page 16: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/16.jpg)
Relationships
• Package[“ntp”] -> File[‘ntp.conf’] ~> Service[‘ntpd’]
• “before”, “require” • “subscribe”, “notify”
http://docs.puppetlabs.com/puppet/2.7/reference/lang_relationships.html#relationship-metaparameters
http://docs.puppetlabs.com/puppet/2.7/reference/lang_relationships.html#chaining-arrows
![Page 17: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/17.jpg)
User-Defined Types
• Similar to functions in most languages.• Only way to do iterations currently.
• Call the Type with an array.
define apache::vhost() { $docroot = “/var/www/${name}”}
$sites = [‘site1’, ‘site2’]apache::vhost {$sites: }
![Page 18: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/18.jpg)
References
Books• Managing Infrastructure with Puppet
(ISBN: 978-1-4493-0763-9)• Pro Puppet (ISBN: 978-1-4302-3057-1)
Websites• http://www.puppetlabs.com• http://docs.puppetlabs.com/• http://forge.puppetlabs.com/
![Page 19: Introduction to Puppet Scripting](https://reader034.vdocuments.net/reader034/viewer/2022052307/554f8a37b4c9052a518b50e3/html5/thumbnails/19.jpg)
Q&A