SlideShare una empresa de Scribd logo
1 de 19
Descargar para leer sin conexión
Smoothing Troubles
Custom Types and Providers
Chad Thompson
PuppetCamp Chicago
August 18, 2014
Chad Thompson
“DevOps Engineer”
http://chadthompson.me
node default {
!
file{"/etc/config.conf:
ensure => "present",
owner => "chad.thompson",
content => "Key Value”,
}
!
}
From puppet manifests…
node default {
include custommod
}
class custommod {
file{“/etc/config.conf”:
ensure => "present",
owner => "chad.thompson",
content => "Key Value”,
}
}
… to Modules
node default {
custommod::config{“config”:
config_dir => “/etc/“,
}
define custommod::config(
$config_dir = “/etc/“
)
{
file{“/etc/config.conf: […]
}
}
… to Defined Types
!
user{“chad.thompson”:
ensure => "present",
managehome => true,
}
Encapsulation
package{“nginx”:
ensure => installed,
}
!
file{“/etc/nginx/nginx.conf”:
ensure => "present",
content => template(“..”),
require => Package[“nginx”],
notify => Service[“nginx”],
}
!
service{“nginx”:
ensure => running,
require => Package[“nginx”],
}
Dependency Management
# Copy SSH keys into place
file{"/home/devuser/.ssh":
ensure => "directory",
owner => 'dice',
}->
exec{"cp /opt/ssh-keys/* /home/devuser/.ssh/":
path => "/bin:/usr/bin",
user => 'devuser',
creates => '/home/devuser/.ssh/id_rsa.pub',
}->
exec{"chown devuser:devuser /home/devuser/.ssh/*":
path => "/bin:/usr/bin",
user => "devuser",
}->
exec{"chmod -R 0400 /home/devuser/.ssh/*":
path => "/bin:/usr/bin",
}->
Procedural Routines
exec{} -> exec{} -> exec{}->
Difficult Things..
• Executing deployment scripts.
• Deployment scripts (“php artisan…”)
• Database migrations
• Third party service integrations. (“Send a
note to HipChat…”)
A different way..
!
wpcli{“/usr/local/bin”:
ensure => present,
}
http://wp-cli.org
A Custom Type
!
# lib/puppet/type/wpcli.rb
Puppet::Type.newtype(:wpcli) do
@doc = "Install The WP-CLI Tool"
ensurable
!
# A single parameter -
# the path to install the wp-cli binary.
newparam(:path, :namevar => true) do
desc "The wp-cli install location."
end
end
Defines the behavior of the ‘wpcli’ type.
A Provider
!
require 'mkmf'
!
Puppet::Type.type(:wpcli).provide :ruby do
desc "..."
!
# Required executables for the module
commands :curl => 'curl'
commands :php => 'php'
…
end
Defines the Steps for Execution
Some Background..
• The Ruby Language (http://ruby-lang.org)
• Libraries, Objects, Gem Files (oh, my!)
• There can be many providers for a type.
• Test for features / facts.
• A convention for the ‘lib’ directory.
.
!"" Modulefile
!"" README
!"" lib
#   $"" puppet
#   !"" provider
#   #   $"" wpcli
#   #   $"" ruby.rb
#   $"" type
#   $"" wpcli.rb
!"" manifests
#   $"" init.pp
!"" spec
#   $"" spec_helper.rb
$"" tests
!"" init.pp
$"" wpcli.pp
The Custom Type
# lib/puppet/type/wpcli.rb
Puppet::Type.newtype(:wpcli) do
@doc = "Install The WP-CLI Tool"
ensurable
!
# A single parameter -
# the path to install the wp-cli binary.
newparam(:path, :namevar => true) do
desc "The wp-cli install location."
end
end
The Provider
require 'mkmf'
!
Puppet::Type.type(:wpcli).provide :ruby do
desc "..."
!
def create
end
!
def destroy
end
!
## This provider will create a binary called 'wp'
def exists?
end
!
end
## This provider will create a binary called 'wp'
def exists?
executable = find_executable 'wp'
if executable.nil?
return false
else
return true
end
end
# Required executables for the module
commands :curl => 'curl'
commands :php => 'php'
!
@@wp_url = 'https://raw.githubusercontent.com/wp-cli/
builds/gh-pages/phar/wp-cli.phar'
!
def create
# Using the puppet logger to output
# information - sends information
# to the puppet master
debug("CREATE #{resource[:path]}")
!
curl(['-o', "#{resource[:path]}/wp", @@wp_url])
File.chmod(0755, "#{resource[:path]}/wp")
end
Conclusion
Q: How do I mix scripting with Puppet?
!
A: With Custom Types/Providers!
THank you!
http://chadthompson.me
@chadothompson
chad_thompson@mac.com

Más contenido relacionado

La actualidad más candente

Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
Dr.Ravi
 

La actualidad más candente (20)

BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
Perl basics for pentesters part 2
Perl basics for pentesters part 2Perl basics for pentesters part 2
Perl basics for pentesters part 2
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojo
 
Perl Basics for Pentesters Part 1
Perl Basics for Pentesters Part 1Perl Basics for Pentesters Part 1
Perl Basics for Pentesters Part 1
 
Intro to-puppet
Intro to-puppetIntro to-puppet
Intro to-puppet
 
Puppet @ Seat
Puppet @ SeatPuppet @ Seat
Puppet @ Seat
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
 
Stanford Hackathon - Puppet Modules
Stanford Hackathon - Puppet ModulesStanford Hackathon - Puppet Modules
Stanford Hackathon - Puppet Modules
 
Development of Ansible modules
Development of Ansible modulesDevelopment of Ansible modules
Development of Ansible modules
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
 
Ansible fest Presentation slides
Ansible fest Presentation slidesAnsible fest Presentation slides
Ansible fest Presentation slides
 
Configuration Management in Ansible
Configuration Management in Ansible Configuration Management in Ansible
Configuration Management in Ansible
 
PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
 

Similar a Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers (Beginner)

From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
Carlos Sanchez
 
20090514 Introducing Puppet To Sasag
20090514 Introducing Puppet To Sasag20090514 Introducing Puppet To Sasag
20090514 Introducing Puppet To Sasag
garrett honeycutt
 
PM : code faster
PM : code fasterPM : code faster
PM : code faster
PHPPRO
 
Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012
Carlos Sanchez
 

Similar a Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers (Beginner) (20)

Puppet
PuppetPuppet
Puppet
 
Terraform in deployment pipeline
Terraform in deployment pipelineTerraform in deployment pipeline
Terraform in deployment pipeline
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013
 
Replacing "exec" with a type and provider
Replacing "exec" with a type and providerReplacing "exec" with a type and provider
Replacing "exec" with a type and provider
 
Introduction to InSpec and 1.0 release update
Introduction to InSpec and 1.0 release updateIntroduction to InSpec and 1.0 release update
Introduction to InSpec and 1.0 release update
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Sprockets
SprocketsSprockets
Sprockets
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
 
20090514 Introducing Puppet To Sasag
20090514 Introducing Puppet To Sasag20090514 Introducing Puppet To Sasag
20090514 Introducing Puppet To Sasag
 
Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014
 
PM : code faster
PM : code fasterPM : code faster
PM : code faster
 
Easy native wrappers with SWIG
Easy native wrappers with SWIGEasy native wrappers with SWIG
Easy native wrappers with SWIG
 
Automated Puppet Testing - PuppetCamp Chicago '12 - Scott Nottingham
Automated Puppet Testing - PuppetCamp Chicago '12 - Scott NottinghamAutomated Puppet Testing - PuppetCamp Chicago '12 - Scott Nottingham
Automated Puppet Testing - PuppetCamp Chicago '12 - Scott Nottingham
 
Composer
ComposerComposer
Composer
 
EC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and PackerEC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and Packer
 
Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012
 
Phing
PhingPhing
Phing
 
Ingo Muschenetz: Titanium Studio Deep Dive
Ingo Muschenetz: Titanium Studio Deep DiveIngo Muschenetz: Titanium Studio Deep Dive
Ingo Muschenetz: Titanium Studio Deep Dive
 
Refactor Dance - Puppet Labs 'Best Practices'
Refactor Dance - Puppet Labs 'Best Practices'Refactor Dance - Puppet Labs 'Best Practices'
Refactor Dance - Puppet Labs 'Best Practices'
 
Configuration Management in the Cloud - Cloud Phoenix Meetup Feb 2014
Configuration Management in the Cloud - Cloud Phoenix Meetup Feb 2014Configuration Management in the Cloud - Cloud Phoenix Meetup Feb 2014
Configuration Management in the Cloud - Cloud Phoenix Meetup Feb 2014
 

Más de Puppet

Puppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepoPuppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepo
Puppet
 
2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)
Puppet
 
Enforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationEnforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automation
Puppet
 

Más de Puppet (20)

Puppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepoPuppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepo
 
Puppetcamp r10kyaml
Puppetcamp r10kyamlPuppetcamp r10kyaml
Puppetcamp r10kyaml
 
2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)
 
Puppet camp vscode
Puppet camp vscodePuppet camp vscode
Puppet camp vscode
 
Modules of the twenties
Modules of the twentiesModules of the twenties
Modules of the twenties
 
Applying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance codeApplying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance code
 
KGI compliance as-code approach
KGI compliance as-code approachKGI compliance as-code approach
KGI compliance as-code approach
 
Enforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationEnforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automation
 
Keynote: Puppet camp compliance
Keynote: Puppet camp complianceKeynote: Puppet camp compliance
Keynote: Puppet camp compliance
 
Automating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNowAutomating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNow
 
Puppet: The best way to harden Windows
Puppet: The best way to harden WindowsPuppet: The best way to harden Windows
Puppet: The best way to harden Windows
 
Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020
 
Accelerating azure adoption with puppet
Accelerating azure adoption with puppetAccelerating azure adoption with puppet
Accelerating azure adoption with puppet
 
Puppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael PinsonPuppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael Pinson
 
ServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin ReeuwijkServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin Reeuwijk
 
Take control of your dev ops dumping ground
Take control of your  dev ops dumping groundTake control of your  dev ops dumping ground
Take control of your dev ops dumping ground
 
100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy Software100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy Software
 
Puppet User Group
Puppet User GroupPuppet User Group
Puppet User Group
 
Continuous Compliance and DevSecOps
Continuous Compliance and DevSecOpsContinuous Compliance and DevSecOps
Continuous Compliance and DevSecOps
 
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick MaludyThe Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
 

Último

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
+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
 

Último (20)

%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
%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
 
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
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
+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...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
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
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
%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
 

Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers (Beginner)

  • 1. Smoothing Troubles Custom Types and Providers Chad Thompson PuppetCamp Chicago August 18, 2014
  • 3. node default { ! file{"/etc/config.conf: ensure => "present", owner => "chad.thompson", content => "Key Value”, } ! } From puppet manifests…
  • 4. node default { include custommod } class custommod { file{“/etc/config.conf”: ensure => "present", owner => "chad.thompson", content => "Key Value”, } } … to Modules
  • 5. node default { custommod::config{“config”: config_dir => “/etc/“, } define custommod::config( $config_dir = “/etc/“ ) { file{“/etc/config.conf: […] } } … to Defined Types
  • 7. package{“nginx”: ensure => installed, } ! file{“/etc/nginx/nginx.conf”: ensure => "present", content => template(“..”), require => Package[“nginx”], notify => Service[“nginx”], } ! service{“nginx”: ensure => running, require => Package[“nginx”], } Dependency Management
  • 8. # Copy SSH keys into place file{"/home/devuser/.ssh": ensure => "directory", owner => 'dice', }-> exec{"cp /opt/ssh-keys/* /home/devuser/.ssh/": path => "/bin:/usr/bin", user => 'devuser', creates => '/home/devuser/.ssh/id_rsa.pub', }-> exec{"chown devuser:devuser /home/devuser/.ssh/*": path => "/bin:/usr/bin", user => "devuser", }-> exec{"chmod -R 0400 /home/devuser/.ssh/*": path => "/bin:/usr/bin", }-> Procedural Routines exec{} -> exec{} -> exec{}->
  • 9. Difficult Things.. • Executing deployment scripts. • Deployment scripts (“php artisan…”) • Database migrations • Third party service integrations. (“Send a note to HipChat…”)
  • 11. A Custom Type ! # lib/puppet/type/wpcli.rb Puppet::Type.newtype(:wpcli) do @doc = "Install The WP-CLI Tool" ensurable ! # A single parameter - # the path to install the wp-cli binary. newparam(:path, :namevar => true) do desc "The wp-cli install location." end end Defines the behavior of the ‘wpcli’ type.
  • 12. A Provider ! require 'mkmf' ! Puppet::Type.type(:wpcli).provide :ruby do desc "..." ! # Required executables for the module commands :curl => 'curl' commands :php => 'php' … end Defines the Steps for Execution
  • 13. Some Background.. • The Ruby Language (http://ruby-lang.org) • Libraries, Objects, Gem Files (oh, my!) • There can be many providers for a type. • Test for features / facts. • A convention for the ‘lib’ directory.
  • 14. . !"" Modulefile !"" README !"" lib #   $"" puppet #   !"" provider #   #   $"" wpcli #   #   $"" ruby.rb #   $"" type #   $"" wpcli.rb !"" manifests #   $"" init.pp !"" spec #   $"" spec_helper.rb $"" tests !"" init.pp $"" wpcli.pp
  • 15. The Custom Type # lib/puppet/type/wpcli.rb Puppet::Type.newtype(:wpcli) do @doc = "Install The WP-CLI Tool" ensurable ! # A single parameter - # the path to install the wp-cli binary. newparam(:path, :namevar => true) do desc "The wp-cli install location." end end
  • 16. The Provider require 'mkmf' ! Puppet::Type.type(:wpcli).provide :ruby do desc "..." ! def create end ! def destroy end ! ## This provider will create a binary called 'wp' def exists? end ! end
  • 17. ## This provider will create a binary called 'wp' def exists? executable = find_executable 'wp' if executable.nil? return false else return true end end
  • 18. # Required executables for the module commands :curl => 'curl' commands :php => 'php' ! @@wp_url = 'https://raw.githubusercontent.com/wp-cli/ builds/gh-pages/phar/wp-cli.phar' ! def create # Using the puppet logger to output # information - sends information # to the puppet master debug("CREATE #{resource[:path]}") ! curl(['-o', "#{resource[:path]}/wp", @@wp_url]) File.chmod(0755, "#{resource[:path]}/wp") end
  • 19. Conclusion Q: How do I mix scripting with Puppet? ! A: With Custom Types/Providers! THank you! http://chadthompson.me @chadothompson chad_thompson@mac.com