Introduction to Puppet Scripting


Published on

Shawn Smiley, Lead Architect, for Achieve Internet explains Puppet Scripting for SANDCamp 2013

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Startup an AWS instance and run puppet apply to show what puppet does.
  • Default modulepath: /etc/puppet/modules:/usr/share/puppet/modules
  • Show the File Structure and examples of some modules.
  • Defining an item is called a “Resource Declaration”
  • Demo a simple module: The Lynx module.
  • Introduction to Puppet Scripting

    1. 1. Introduction to PuppetScriptingShawn S. SmileyLead ArchitectAchieve
    2. 2. 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:
    3. 3. 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:
    4. 4. Quick DemoImage source:
    5. 5. 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.
    6. 6. 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.
    7. 7. What are the pieces?• Puppet Software• Module Library• Node configuration file• [optional] Puppet Master
    8. 8. ModulesWhat 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://github.comWhere do I put them?• /usr/share/puppet/modules• /etc/puppet/modules
    9. 9. File Organization• manifests • site.pp • nodes.pp• modules • module1 • manifests  init.pp • files • templates • module2
    10. 10. Demo: Folder StructureImage source:
    11. 11. 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: To execute an item:type title($arg1) { include “title” description of resource state} type {“title”: } type {“title”: arg1 => ‘hello’ }
    12. 12. Demo: Simple scriptImage source:
    13. 13. 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 • notifyFull list:
    14. 14. FacterWhat are facts?• Global variables with information about the system that the script is running on.How do I see the available variables?• facter -pHow do I use them?• $::variable_name
    15. 15. 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, }
    16. 16. Relationships• Package[“ntp”] -> File[„ntp.conf‟] ~> Service[„ntpd‟]• “before”, “require”• “subscribe”, “notify”
    17. 17. 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: }
    18. 18. ReferencesBooks• Managing Infrastructure with Puppet (ISBN: 978-1-4493-0763-9)• Pro Puppet (ISBN: 978-1-4302-3057-1)Websites•••
    19. 19. Q&A