SlideShare uma empresa Scribd logo
1 de 55
Baixar para ler offline
Advanced Puppet
Topics
Ken Barber
Professional Services Engineer
Donnerstag, 14. April 2011
aka
My favourite
puppet features
Donnerstag, 14. April 2011
Topics
• Standalone Puppet
• Ruby DSL
• extlookup
• dotty output
• External Node Classification
• Puppetdocs
Donnerstag, 14. April 2011
Standalone Puppet
Donnerstag, 14. April 2011
Standalone Puppet
• The Puppet Domain Specific Language (DSL)
is a language that can be used standalone
• Works like any other script
• Requires no infrastructure
Donnerstag, 14. April 2011
Example 1
#!/usr/bin/env puppet
file { ‘/tmp/example1.out’:
content => “Example 1n”,
}
create_file.pp:
Donnerstag, 14. April 2011
Example 1
# chmod +x create_file.pp
# ./create_file.pp
notice: /Stage[main]//File[/tmp/example1.out]/ensure:
defined content as '{md5}8a0a86c394456fa1879929d8e1419f94'
notice: Finished catalog run in 0.08 seconds
# cat /tmp/example1.out
Example 1
#
Donnerstag, 14. April 2011
Example 2
#!/usr/bin/env puppet
package { 'mysql-server':
ensure => installed,
}
file { '/etc/my.cnf':
source => 'my.cnf',
notify => Service['mysql'],
}
service { 'mysql':
ensure => running,
enable => true,
require => Package['mysql-server'],
}
setup_mysql.pp:
Donnerstag, 14. April 2011
Example 2
# chmod +x setup_mysql.pp
# ./setup_mysql.pp
notice: /Stage[main]//Package[mysql-server]/ensure: ensure
changed 'purged' to 'present'
notice: /Stage[main]//File[/etc/mysql/my.cnf]/ensure:
defined content as '{md5}b82b1ec5fa04a2680403e94e5cda845e'
notice: /Stage[main]//Service[mysql]: Triggered 'refresh'
from 1 events
notice: Finished catalog run in 60.37 seconds
#
Donnerstag, 14. April 2011
Example 3
# puppet apply -e "file{'/tmp/foo':content=>"foon"}"
notice: /Stage[main]//File[/tmp/foo]/ensure: defined
content as '{md5}d3b07384d113edec49eaa6238ad5ff00'
notice: Finished catalog run in 0.08 seconds
# cat /tmp/foo
foo
#
Donnerstag, 14. April 2011
Use Cases
• Boot strapping Puppet on a machine that has
minimal facilities
• Development work
• Running Puppet in master-less mode
Donnerstag, 14. April 2011
Ruby DSL
Donnerstag, 14. April 2011
Why Puppet DSL?
• It’s declarative so its ideal for configuration
management
• We can constrain the behaviour to only
configuration management
• You don’t need to know ruby to start, and its
simpler to learn then most languages
Donnerstag, 14. April 2011
Why Ruby DSL?
• Allows you to extend Puppet beyond normal
Puppet DSL
• No constraints
• Prototype new ideas that can potentially
become Puppet DSL later
Donnerstag, 14. April 2011
How to use Ruby
DSL
• Puppet now recognises the ‘.rb’ extension
• standalone_script.pp -> standalone_script.rb
• manifests/site.pp -> manifests/site.rb
• <module>/manifests/init.pp -> <module>/
manifests/init.rb
• import “extras.pp” -> import “extras.rb”
Donnerstag, 14. April 2011
How to use the
Ruby DSL
#!/usr/bin/env puppet
hostclass :foo do
notice ["foo"]
end
node "default" do
include “foo”
end
standalone_script.rb:
Donnerstag, 14. April 2011
Ruby DSL - Nodes
# Puppet DSL
node "default" {
notice(“Default node”)
}
# Ruby DSL
node "default" do
notice[“Default node”]
end
Donnerstag, 14. April 2011
Ruby DSL - Classes
# Puppet DSL
class foo {
  notice("foo")
}
node "default" {
  include foo
}
# Ruby DSL
hostclass :foo do
  notice ["foo"]
end
node "default" do
  include “foo”
end
Donnerstag, 14. April 2011
Ruby DSL - Functions
# Puppet DSL
node "default" {
  notice("Function output")
}
# Ruby DSL
node "default" do
  notice ["Function output"]
end
# Ruby DSL - alternative
node "default" do
  call_function “notice”, ["Function output"]
end
Donnerstag, 14. April 2011
Ruby DSL - Resources
# Puppet DSL
define myresource() {
  notice($name)
}
node "default" {
  myresource {"resource_output": }
}
# Ruby DSL
define "myresource" do
  notice [@name]
end
node "default" do
  create_resource :myresource, "resource_output"
end
Donnerstag, 14. April 2011
Ruby DSL - Variables
# Puppet DSL
node "default" {
  $myvar = "value is here"
  notice($myvar)
}
# Ruby DSL
node "default" do
  scope.setvar("myvar", "value is here")
  a = scope.lookupvar("myvar")
  notice [a]
end
Donnerstag, 14. April 2011
Mysql Example
require 'mysql'
 
hostclass :packages do
# Connect to mysql
conn = Mysql.new('localhost', 'user', 'password', 'cmdb')
# Obtain a list of mysql packages (and versions)
pkgs = conn.query('select * from packages')
# Create a package resource for each package defining the version
# for each
pkgs.each_hash { |p| package p['name'], :ensure => p['version'] }
conn.close
end
 
node 'default' do
include 'packages'
end
Donnerstag, 14. April 2011
Ruby DSL - Further
Information
• Wiki Article:
• http://projects.puppetlabs.com/projects/1/wiki/
Ruby_Dsl
• Google ‘puppet ruby dsl’
Donnerstag, 14. April 2011
extlookup()
Donnerstag, 14. April 2011
Config vs Code
• Node Classifiers
• External Node Classifiers
• Large lookup tables in Puppet DSL
• External data like CSV tables
Donnerstag, 14. April 2011
Usage
# Configure extlookup data directory and precedence
$extlookup_datadir = "."
$extlookup_precedence = [
"%{fqdn}",
"location_%{location}",
"county_%{country}",
"common"
]
# Fetch extlookup and print the results
notice(extlookup("snmp_trap_host"))
Donnerstag, 14. April 2011
Example - common
snmp_trap_host,1.1.1.1
common.csv:
# ./example1.pp
notice: Scope(Class[main]): 1.1.1.1
notice: Finished catalog run in 0.01 seconds
#
Donnerstag, 14. April 2011
Example - country
snmp_trap_host,1.1.1.1
common.csv:
# ./example1.pp
notice: Scope(Class[main]): 1.1.2.1
notice: Finished catalog run in 0.01 seconds
#
snmp_trap_host,1.1.2.1
country_de.csv:
Donnerstag, 14. April 2011
Example - location
snmp_trap_host,1.1.1.1
common.csv:
# ./example1.pp
notice: Scope(Class[main]): 1.1.3.1
notice: Finished catalog run in 0.01 seconds
#
snmp_trap_host,1.1.2.1
country_de.csv:
snmp_trap_host,1.1.3.1
location_holidayinn.csv:
Donnerstag, 14. April 2011
dotty output
Donnerstag, 14. April 2011
dotty output
• Puppet defines every artifact as a resources
• Resources are related to each other through
dependency
• Internally, these dependencies are mapped as
a graph
• These graphs can be output in dotty format
Donnerstag, 14. April 2011
dotty: Tools
• Graphviz - open source, very flexible,
widely used
• Gephi - free, java based, powerful graph
support
• Omnigraffle - commercial, more then just
graphs
Donnerstag, 14. April 2011
dotty output
Traditional Way:
With new Puppet Interfaces:
puppet --noop --graph --graphdir /vagrant/graphs relationships.pp
puppet catalog --format dot find localhost > ~/Desktop/catalog.dot
Donnerstag, 14. April 2011
dotty Example 1
file { '/files':
ensure => directory
}
file { '/files/001.txt':
ensure => file,
content => '001',
require => File['/files'],
}
Donnerstag, 14. April 2011
dotty Example 1
Donnerstag, 14. April 2011
dotty Example 2
package { ‘myapp’:
ensure => installed
}
file { ‘/etc/myapp.cfg’:
content => template(‘myapp/myapp.cfg’),
require => Package[‘myapp’],
}
service { ‘myapp’:
ensure => running,
require => File[‘/etc/myapp.cfg’],
}
Donnerstag, 14. April 2011
dotty Example 2
Donnerstag, 14. April 2011
dotty Example 3
package { 'myapp':
ensure => installed,
}
file { '/etc/myapp1.cfg':
content => 'myapp1',
require => Package['myapp'],
}
file { '/etc/myapp2.cfg':
content => 'myapp2',
require => Package['myapp'],
}
service { 'myapp':
ensure => running,
}
Donnerstag, 14. April 2011
dotty Example 3
Donnerstag, 14. April 2011
dotty Example 3
package { 'myapp':
ensure => installed,
}
file { '/etc/myapp1.cfg':
content => 'myapp1',
require => Package['myapp'],
notify => Service[‘myapp’],
}
file { '/etc/myapp2.cfg':
content => 'myapp2',
require => Package['myapp'],
notify => Service[‘myapp’],
}
service { 'myapp':
ensure => running,
}
Donnerstag, 14. April 2011
dotty Example 3
Donnerstag, 14. April 2011
dotty - big example
Donnerstag, 14. April 2011
External Node
Classification
Donnerstag, 14. April 2011
Nodes - normally
node “app1” {
$snmp_trap_host = “traps.puppetlabs.com”
$dns_server = “1.1.1.1”
include tomcat
include myapp
include resolver
include snmpd
}
node “db1” {
$snmp_trap_host = “traps.puppetlabs.com”
$dns_server = “1.1.1.1”
$mysql_dbs = [“db1”]
include mysql
include resolver
include snmpd
}
Donnerstag, 14. April 2011
Why ENC?
• Allows you to store node definitions outside of
Puppet
• Provides Configuration / Code separation
• You can provide information from another
information store such as a CMDB or asset
database
Donnerstag, 14. April 2011
Configuration
[main]
external_nodes = /usr/local/bin/puppet_node_classifier
node_terminus = exec
/etc/puppet/puppet.conf:
Donnerstag, 14. April 2011
API
• First argument passed to the external script is the
hostname
• The script must return valid YAML on standard out
• The script returns 0 for success or non-zero to
indicate the node is ‘not found’
Donnerstag, 14. April 2011
YAML Returnednode “app1” {
$snmp_trap_host = “traps.puppetlabs.com”
$dns_server = “1.1.1.1”
include tomcat
include myapp
include resolver
include snmpd
}
---
environment: production
parameters:
snmp_trap_host: traps.puppetlabs.com
dns_server: 1.1.1.1
classes:
- tomcat
- myapp
- resolver
- snmpd
Text
Puppet:
YAML:
Donnerstag, 14. April 2011
Good ENC’s
• Puppet Dashboard
• The Foreman
Donnerstag, 14. April 2011
Puppetdocs
Donnerstag, 14. April 2011
Puppetdocs
• Works in a similar way to ruby docs or
Perl docs
• Documentation should be close to code
• Can be setup to auto-generate code
from VCS using CI tools like Jenkins
• Supports markdown format
Donnerstag, 14. April 2011
Format - Class
# Description of class.
#
# ==Variables
#
# None
#
# == Examples
#
# include myclass
#
# == Authors
#
# Ken Barber <ken@puppetlabs.com>
#
# == Copyright
#
# Copyright© 2011 Puppetlabs Inc, unless otherwise noted.
#
class myclass {
....
}
Donnerstag, 14. April 2011
Format - Resource# Description of resource.
#
# == Parameters
#
# [param1]
# Parameter 1 does something magical
#
# == Examples
#
# myresource { ‘myname’:
# param1 => ‘value’,
# }
#
# == Authors
#
# Ken Barber <ken@puppetlabs.com>
#
# == Copyright
#
# Copyright (C) 2011 Puppetlabs Inc, unless otherwise noted.
#
define myresource($param1) {
....
}
Donnerstag, 14. April 2011
Example
• Webserver: http://localhost:8888/
puppetdoc
Donnerstag, 14. April 2011
Any
Questions?
Donnerstag, 14. April 2011

Mais conteúdo relacionado

Mais procurados

Developing IT infrastructures with Puppet
Developing IT infrastructures with PuppetDeveloping IT infrastructures with Puppet
Developing IT infrastructures with PuppetAlessandro Franceschi
 
Puppet control-repo 
to the next level
Puppet control-repo 
to the next levelPuppet control-repo 
to the next level
Puppet control-repo 
to the next levelAlessandro Franceschi
 
Puppet Systems Infrastructure Construction Kit
Puppet Systems Infrastructure Construction KitPuppet Systems Infrastructure Construction Kit
Puppet Systems Infrastructure Construction KitAlessandro Franceschi
 
Acceptance & Integration Testing With Behat (PHPNw2011)
Acceptance & Integration Testing With Behat (PHPNw2011)Acceptance & Integration Testing With Behat (PHPNw2011)
Acceptance & Integration Testing With Behat (PHPNw2011)benwaine
 
From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...Yury Bushmelev
 
Virtual Bolt Workshop - April 28, 2020
Virtual Bolt Workshop - April 28, 2020Virtual Bolt Workshop - April 28, 2020
Virtual Bolt Workshop - April 28, 2020Puppet
 
Whirlwind Tour of Puppet 4
Whirlwind Tour of Puppet 4Whirlwind Tour of Puppet 4
Whirlwind Tour of Puppet 4ripienaar
 
Puppet Virtual Bolt Workshop - 23 April 2020 (Singapore)
Puppet Virtual Bolt Workshop - 23 April 2020 (Singapore)Puppet Virtual Bolt Workshop - 23 April 2020 (Singapore)
Puppet Virtual Bolt Workshop - 23 April 2020 (Singapore)Puppet
 
Puppet Continuous Integration with PE and GitLab
Puppet Continuous Integration with PE and GitLabPuppet Continuous Integration with PE and GitLab
Puppet Continuous Integration with PE and GitLabAlessandro Franceschi
 
Writing and using php streams and sockets tek11
Writing and using php streams and sockets   tek11Writing and using php streams and sockets   tek11
Writing and using php streams and sockets tek11Elizabeth Smith
 
Phing: Building with PHP
Phing: Building with PHPPhing: Building with PHP
Phing: Building with PHPhozn
 
Streams, sockets and filters oh my!
Streams, sockets and filters oh my!Streams, sockets and filters oh my!
Streams, sockets and filters oh my!Elizabeth Smith
 
Yapc::NA::2009 - Command Line Perl
Yapc::NA::2009 - Command Line PerlYapc::NA::2009 - Command Line Perl
Yapc::NA::2009 - Command Line PerlBruce Gray
 

Mais procurados (20)

Developing IT infrastructures with Puppet
Developing IT infrastructures with PuppetDeveloping IT infrastructures with Puppet
Developing IT infrastructures with Puppet
 
Puppet control-repo 
to the next level
Puppet control-repo 
to the next levelPuppet control-repo 
to the next level
Puppet control-repo 
to the next level
 
Puppet Systems Infrastructure Construction Kit
Puppet Systems Infrastructure Construction KitPuppet Systems Infrastructure Construction Kit
Puppet Systems Infrastructure Construction Kit
 
Puppet modules for Fun and Profit
Puppet modules for Fun and ProfitPuppet modules for Fun and Profit
Puppet modules for Fun and Profit
 
Network programming
Network programmingNetwork programming
Network programming
 
Acceptance & Integration Testing With Behat (PHPNw2011)
Acceptance & Integration Testing With Behat (PHPNw2011)Acceptance & Integration Testing With Behat (PHPNw2011)
Acceptance & Integration Testing With Behat (PHPNw2011)
 
Power of Puppet 4
Power of Puppet 4Power of Puppet 4
Power of Puppet 4
 
System Programming and Administration
System Programming and AdministrationSystem Programming and Administration
System Programming and Administration
 
From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...
 
Virtual Bolt Workshop - April 28, 2020
Virtual Bolt Workshop - April 28, 2020Virtual Bolt Workshop - April 28, 2020
Virtual Bolt Workshop - April 28, 2020
 
Whirlwind Tour of Puppet 4
Whirlwind Tour of Puppet 4Whirlwind Tour of Puppet 4
Whirlwind Tour of Puppet 4
 
John's Top PECL Picks
John's Top PECL PicksJohn's Top PECL Picks
John's Top PECL Picks
 
Puppet Virtual Bolt Workshop - 23 April 2020 (Singapore)
Puppet Virtual Bolt Workshop - 23 April 2020 (Singapore)Puppet Virtual Bolt Workshop - 23 April 2020 (Singapore)
Puppet Virtual Bolt Workshop - 23 April 2020 (Singapore)
 
How do event loops work in Python?
How do event loops work in Python?How do event loops work in Python?
How do event loops work in Python?
 
Anatomy of a reusable module
Anatomy of a reusable moduleAnatomy of a reusable module
Anatomy of a reusable module
 
Puppet Continuous Integration with PE and GitLab
Puppet Continuous Integration with PE and GitLabPuppet Continuous Integration with PE and GitLab
Puppet Continuous Integration with PE and GitLab
 
Writing and using php streams and sockets tek11
Writing and using php streams and sockets   tek11Writing and using php streams and sockets   tek11
Writing and using php streams and sockets tek11
 
Phing: Building with PHP
Phing: Building with PHPPhing: Building with PHP
Phing: Building with PHP
 
Streams, sockets and filters oh my!
Streams, sockets and filters oh my!Streams, sockets and filters oh my!
Streams, sockets and filters oh my!
 
Yapc::NA::2009 - Command Line Perl
Yapc::NA::2009 - Command Line PerlYapc::NA::2009 - Command Line Perl
Yapc::NA::2009 - Command Line Perl
 

Semelhante a OSDC 2011 | Advanced Puppet Topics by Ken Barber

Puppet Camp Berlin 2014: Advanced Puppet Design
Puppet Camp Berlin 2014: Advanced Puppet DesignPuppet Camp Berlin 2014: Advanced Puppet Design
Puppet Camp Berlin 2014: Advanced Puppet DesignPuppet
 
The Solar Framework for PHP
The Solar Framework for PHPThe Solar Framework for PHP
The Solar Framework for PHPConFoo
 
Puppet getting started by Dirk Götz
Puppet getting started by Dirk GötzPuppet getting started by Dirk Götz
Puppet getting started by Dirk GötzNETWAYS
 
The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09Bastian Feder
 
Deploying on the cutting edge
Deploying on the cutting edgeDeploying on the cutting edge
Deploying on the cutting edgeericholscher
 
Webinar - Managing Files with Puppet
Webinar - Managing Files with PuppetWebinar - Managing Files with Puppet
Webinar - Managing Files with PuppetOlinData
 
Introduction to puppet - Hands on Session at HPI Potsdam
Introduction to puppet - Hands on Session at HPI PotsdamIntroduction to puppet - Hands on Session at HPI Potsdam
Introduction to puppet - Hands on Session at HPI PotsdamChristoph Oelmüller
 
Installing and Getting Started with Alfresco
Installing and Getting Started with AlfrescoInstalling and Getting Started with Alfresco
Installing and Getting Started with AlfrescoWildan Maulana
 
Scaling to-5000-nodes
Scaling to-5000-nodesScaling to-5000-nodes
Scaling to-5000-nodesPhilip Watts
 
Puppet Camp New York 2015: Puppet Enterprise Scaling Lessons Learned (Interme...
Puppet Camp New York 2015: Puppet Enterprise Scaling Lessons Learned (Interme...Puppet Camp New York 2015: Puppet Enterprise Scaling Lessons Learned (Interme...
Puppet Camp New York 2015: Puppet Enterprise Scaling Lessons Learned (Interme...Puppet
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP ApplicationsPavan Kumar N
 
Managing-Splunk-with-Puppet 31-January-2022.pdf
Managing-Splunk-with-Puppet 31-January-2022.pdfManaging-Splunk-with-Puppet 31-January-2022.pdf
Managing-Splunk-with-Puppet 31-January-2022.pdfssusera181ef
 
OSDC 2011 | Systemautomatisierung mit Chef by Jochen Lillich
OSDC 2011 | Systemautomatisierung mit Chef by Jochen LillichOSDC 2011 | Systemautomatisierung mit Chef by Jochen Lillich
OSDC 2011 | Systemautomatisierung mit Chef by Jochen LillichNETWAYS
 
Puppet Keynote
Puppet KeynotePuppet Keynote
Puppet KeynotePuppet
 
Happy porting x86 application to android
Happy porting x86 application to androidHappy porting x86 application to android
Happy porting x86 application to androidOwen Hsu
 
PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T
PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T
PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T Puppet
 

Semelhante a OSDC 2011 | Advanced Puppet Topics by Ken Barber (20)

Puppet Camp Berlin 2014: Advanced Puppet Design
Puppet Camp Berlin 2014: Advanced Puppet DesignPuppet Camp Berlin 2014: Advanced Puppet Design
Puppet Camp Berlin 2014: Advanced Puppet Design
 
The Solar Framework for PHP
The Solar Framework for PHPThe Solar Framework for PHP
The Solar Framework for PHP
 
Puppet getting started by Dirk Götz
Puppet getting started by Dirk GötzPuppet getting started by Dirk Götz
Puppet getting started by Dirk Götz
 
The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09
 
Deploying on the cutting edge
Deploying on the cutting edgeDeploying on the cutting edge
Deploying on the cutting edge
 
Webinar - Managing Files with Puppet
Webinar - Managing Files with PuppetWebinar - Managing Files with Puppet
Webinar - Managing Files with Puppet
 
Introduction to puppet - Hands on Session at HPI Potsdam
Introduction to puppet - Hands on Session at HPI PotsdamIntroduction to puppet - Hands on Session at HPI Potsdam
Introduction to puppet - Hands on Session at HPI Potsdam
 
Puppet quick start guide
Puppet quick start guidePuppet quick start guide
Puppet quick start guide
 
Installing and Getting Started with Alfresco
Installing and Getting Started with AlfrescoInstalling and Getting Started with Alfresco
Installing and Getting Started with Alfresco
 
Scaling to-5000-nodes
Scaling to-5000-nodesScaling to-5000-nodes
Scaling to-5000-nodes
 
Puppet Camp New York 2015: Puppet Enterprise Scaling Lessons Learned (Interme...
Puppet Camp New York 2015: Puppet Enterprise Scaling Lessons Learned (Interme...Puppet Camp New York 2015: Puppet Enterprise Scaling Lessons Learned (Interme...
Puppet Camp New York 2015: Puppet Enterprise Scaling Lessons Learned (Interme...
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP Applications
 
Managing-Splunk-with-Puppet 31-January-2022.pdf
Managing-Splunk-with-Puppet 31-January-2022.pdfManaging-Splunk-with-Puppet 31-January-2022.pdf
Managing-Splunk-with-Puppet 31-January-2022.pdf
 
Phing
PhingPhing
Phing
 
OSDC 2011 | Systemautomatisierung mit Chef by Jochen Lillich
OSDC 2011 | Systemautomatisierung mit Chef by Jochen LillichOSDC 2011 | Systemautomatisierung mit Chef by Jochen Lillich
OSDC 2011 | Systemautomatisierung mit Chef by Jochen Lillich
 
Puppet Keynote
Puppet KeynotePuppet Keynote
Puppet Keynote
 
Happy porting x86 application to android
Happy porting x86 application to androidHappy porting x86 application to android
Happy porting x86 application to android
 
Php task runners
Php task runnersPhp task runners
Php task runners
 
PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T
PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T
PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T
 
Deploy Flex with Apache Ant
Deploy Flex with Apache AntDeploy Flex with Apache Ant
Deploy Flex with Apache Ant
 

Último

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 

Último (20)

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 

OSDC 2011 | Advanced Puppet Topics by Ken Barber

  • 1. Advanced Puppet Topics Ken Barber Professional Services Engineer Donnerstag, 14. April 2011
  • 3. Topics • Standalone Puppet • Ruby DSL • extlookup • dotty output • External Node Classification • Puppetdocs Donnerstag, 14. April 2011
  • 5. Standalone Puppet • The Puppet Domain Specific Language (DSL) is a language that can be used standalone • Works like any other script • Requires no infrastructure Donnerstag, 14. April 2011
  • 6. Example 1 #!/usr/bin/env puppet file { ‘/tmp/example1.out’: content => “Example 1n”, } create_file.pp: Donnerstag, 14. April 2011
  • 7. Example 1 # chmod +x create_file.pp # ./create_file.pp notice: /Stage[main]//File[/tmp/example1.out]/ensure: defined content as '{md5}8a0a86c394456fa1879929d8e1419f94' notice: Finished catalog run in 0.08 seconds # cat /tmp/example1.out Example 1 # Donnerstag, 14. April 2011
  • 8. Example 2 #!/usr/bin/env puppet package { 'mysql-server': ensure => installed, } file { '/etc/my.cnf': source => 'my.cnf', notify => Service['mysql'], } service { 'mysql': ensure => running, enable => true, require => Package['mysql-server'], } setup_mysql.pp: Donnerstag, 14. April 2011
  • 9. Example 2 # chmod +x setup_mysql.pp # ./setup_mysql.pp notice: /Stage[main]//Package[mysql-server]/ensure: ensure changed 'purged' to 'present' notice: /Stage[main]//File[/etc/mysql/my.cnf]/ensure: defined content as '{md5}b82b1ec5fa04a2680403e94e5cda845e' notice: /Stage[main]//Service[mysql]: Triggered 'refresh' from 1 events notice: Finished catalog run in 60.37 seconds # Donnerstag, 14. April 2011
  • 10. Example 3 # puppet apply -e "file{'/tmp/foo':content=>"foon"}" notice: /Stage[main]//File[/tmp/foo]/ensure: defined content as '{md5}d3b07384d113edec49eaa6238ad5ff00' notice: Finished catalog run in 0.08 seconds # cat /tmp/foo foo # Donnerstag, 14. April 2011
  • 11. Use Cases • Boot strapping Puppet on a machine that has minimal facilities • Development work • Running Puppet in master-less mode Donnerstag, 14. April 2011
  • 13. Why Puppet DSL? • It’s declarative so its ideal for configuration management • We can constrain the behaviour to only configuration management • You don’t need to know ruby to start, and its simpler to learn then most languages Donnerstag, 14. April 2011
  • 14. Why Ruby DSL? • Allows you to extend Puppet beyond normal Puppet DSL • No constraints • Prototype new ideas that can potentially become Puppet DSL later Donnerstag, 14. April 2011
  • 15. How to use Ruby DSL • Puppet now recognises the ‘.rb’ extension • standalone_script.pp -> standalone_script.rb • manifests/site.pp -> manifests/site.rb • <module>/manifests/init.pp -> <module>/ manifests/init.rb • import “extras.pp” -> import “extras.rb” Donnerstag, 14. April 2011
  • 16. How to use the Ruby DSL #!/usr/bin/env puppet hostclass :foo do notice ["foo"] end node "default" do include “foo” end standalone_script.rb: Donnerstag, 14. April 2011
  • 17. Ruby DSL - Nodes # Puppet DSL node "default" { notice(“Default node”) } # Ruby DSL node "default" do notice[“Default node”] end Donnerstag, 14. April 2011
  • 18. Ruby DSL - Classes # Puppet DSL class foo {   notice("foo") } node "default" {   include foo } # Ruby DSL hostclass :foo do   notice ["foo"] end node "default" do   include “foo” end Donnerstag, 14. April 2011
  • 19. Ruby DSL - Functions # Puppet DSL node "default" {   notice("Function output") } # Ruby DSL node "default" do   notice ["Function output"] end # Ruby DSL - alternative node "default" do   call_function “notice”, ["Function output"] end Donnerstag, 14. April 2011
  • 20. Ruby DSL - Resources # Puppet DSL define myresource() {   notice($name) } node "default" {   myresource {"resource_output": } } # Ruby DSL define "myresource" do   notice [@name] end node "default" do   create_resource :myresource, "resource_output" end Donnerstag, 14. April 2011
  • 21. Ruby DSL - Variables # Puppet DSL node "default" {   $myvar = "value is here"   notice($myvar) } # Ruby DSL node "default" do   scope.setvar("myvar", "value is here")   a = scope.lookupvar("myvar")   notice [a] end Donnerstag, 14. April 2011
  • 22. Mysql Example require 'mysql'   hostclass :packages do # Connect to mysql conn = Mysql.new('localhost', 'user', 'password', 'cmdb') # Obtain a list of mysql packages (and versions) pkgs = conn.query('select * from packages') # Create a package resource for each package defining the version # for each pkgs.each_hash { |p| package p['name'], :ensure => p['version'] } conn.close end   node 'default' do include 'packages' end Donnerstag, 14. April 2011
  • 23. Ruby DSL - Further Information • Wiki Article: • http://projects.puppetlabs.com/projects/1/wiki/ Ruby_Dsl • Google ‘puppet ruby dsl’ Donnerstag, 14. April 2011
  • 25. Config vs Code • Node Classifiers • External Node Classifiers • Large lookup tables in Puppet DSL • External data like CSV tables Donnerstag, 14. April 2011
  • 26. Usage # Configure extlookup data directory and precedence $extlookup_datadir = "." $extlookup_precedence = [ "%{fqdn}", "location_%{location}", "county_%{country}", "common" ] # Fetch extlookup and print the results notice(extlookup("snmp_trap_host")) Donnerstag, 14. April 2011
  • 27. Example - common snmp_trap_host,1.1.1.1 common.csv: # ./example1.pp notice: Scope(Class[main]): 1.1.1.1 notice: Finished catalog run in 0.01 seconds # Donnerstag, 14. April 2011
  • 28. Example - country snmp_trap_host,1.1.1.1 common.csv: # ./example1.pp notice: Scope(Class[main]): 1.1.2.1 notice: Finished catalog run in 0.01 seconds # snmp_trap_host,1.1.2.1 country_de.csv: Donnerstag, 14. April 2011
  • 29. Example - location snmp_trap_host,1.1.1.1 common.csv: # ./example1.pp notice: Scope(Class[main]): 1.1.3.1 notice: Finished catalog run in 0.01 seconds # snmp_trap_host,1.1.2.1 country_de.csv: snmp_trap_host,1.1.3.1 location_holidayinn.csv: Donnerstag, 14. April 2011
  • 31. dotty output • Puppet defines every artifact as a resources • Resources are related to each other through dependency • Internally, these dependencies are mapped as a graph • These graphs can be output in dotty format Donnerstag, 14. April 2011
  • 32. dotty: Tools • Graphviz - open source, very flexible, widely used • Gephi - free, java based, powerful graph support • Omnigraffle - commercial, more then just graphs Donnerstag, 14. April 2011
  • 33. dotty output Traditional Way: With new Puppet Interfaces: puppet --noop --graph --graphdir /vagrant/graphs relationships.pp puppet catalog --format dot find localhost > ~/Desktop/catalog.dot Donnerstag, 14. April 2011
  • 34. dotty Example 1 file { '/files': ensure => directory } file { '/files/001.txt': ensure => file, content => '001', require => File['/files'], } Donnerstag, 14. April 2011
  • 35. dotty Example 1 Donnerstag, 14. April 2011
  • 36. dotty Example 2 package { ‘myapp’: ensure => installed } file { ‘/etc/myapp.cfg’: content => template(‘myapp/myapp.cfg’), require => Package[‘myapp’], } service { ‘myapp’: ensure => running, require => File[‘/etc/myapp.cfg’], } Donnerstag, 14. April 2011
  • 37. dotty Example 2 Donnerstag, 14. April 2011
  • 38. dotty Example 3 package { 'myapp': ensure => installed, } file { '/etc/myapp1.cfg': content => 'myapp1', require => Package['myapp'], } file { '/etc/myapp2.cfg': content => 'myapp2', require => Package['myapp'], } service { 'myapp': ensure => running, } Donnerstag, 14. April 2011
  • 39. dotty Example 3 Donnerstag, 14. April 2011
  • 40. dotty Example 3 package { 'myapp': ensure => installed, } file { '/etc/myapp1.cfg': content => 'myapp1', require => Package['myapp'], notify => Service[‘myapp’], } file { '/etc/myapp2.cfg': content => 'myapp2', require => Package['myapp'], notify => Service[‘myapp’], } service { 'myapp': ensure => running, } Donnerstag, 14. April 2011
  • 41. dotty Example 3 Donnerstag, 14. April 2011
  • 42. dotty - big example Donnerstag, 14. April 2011
  • 44. Nodes - normally node “app1” { $snmp_trap_host = “traps.puppetlabs.com” $dns_server = “1.1.1.1” include tomcat include myapp include resolver include snmpd } node “db1” { $snmp_trap_host = “traps.puppetlabs.com” $dns_server = “1.1.1.1” $mysql_dbs = [“db1”] include mysql include resolver include snmpd } Donnerstag, 14. April 2011
  • 45. Why ENC? • Allows you to store node definitions outside of Puppet • Provides Configuration / Code separation • You can provide information from another information store such as a CMDB or asset database Donnerstag, 14. April 2011
  • 46. Configuration [main] external_nodes = /usr/local/bin/puppet_node_classifier node_terminus = exec /etc/puppet/puppet.conf: Donnerstag, 14. April 2011
  • 47. API • First argument passed to the external script is the hostname • The script must return valid YAML on standard out • The script returns 0 for success or non-zero to indicate the node is ‘not found’ Donnerstag, 14. April 2011
  • 48. YAML Returnednode “app1” { $snmp_trap_host = “traps.puppetlabs.com” $dns_server = “1.1.1.1” include tomcat include myapp include resolver include snmpd } --- environment: production parameters: snmp_trap_host: traps.puppetlabs.com dns_server: 1.1.1.1 classes: - tomcat - myapp - resolver - snmpd Text Puppet: YAML: Donnerstag, 14. April 2011
  • 49. Good ENC’s • Puppet Dashboard • The Foreman Donnerstag, 14. April 2011
  • 51. Puppetdocs • Works in a similar way to ruby docs or Perl docs • Documentation should be close to code • Can be setup to auto-generate code from VCS using CI tools like Jenkins • Supports markdown format Donnerstag, 14. April 2011
  • 52. Format - Class # Description of class. # # ==Variables # # None # # == Examples # # include myclass # # == Authors # # Ken Barber <ken@puppetlabs.com> # # == Copyright # # Copyright© 2011 Puppetlabs Inc, unless otherwise noted. # class myclass { .... } Donnerstag, 14. April 2011
  • 53. Format - Resource# Description of resource. # # == Parameters # # [param1] # Parameter 1 does something magical # # == Examples # # myresource { ‘myname’: # param1 => ‘value’, # } # # == Authors # # Ken Barber <ken@puppetlabs.com> # # == Copyright # # Copyright (C) 2011 Puppetlabs Inc, unless otherwise noted. # define myresource($param1) { .... } Donnerstag, 14. April 2011