SlideShare une entreprise Scribd logo
1  sur  17
Télécharger pour lire hors ligne
Replacing "exec" with a
  type and provider
  Return manifests to a declarative
           configuration



           Dominic Cleal <dcleal@redhat.com>
Puppet's declarative DSL

user { 'dcleal':
  ensure => present,
  comment => 'Dominic Cleal',
  shell   => '/bin/bash',
}
package { 'vim':
  ensure => 'present',
}
How execs can fail
$ puppet module install puppetlabs-apt
$ vim apt/manifests/key.pp
...
exec { "apt::key ${upkey} absent":
  command   => "apt-key del '${upkey}'",
  path      => '/bin:/usr/bin',
  onlyif    => "apt-key list | grep '${upkey}'",
  user      => 'root',
  group     => 'root',
  logoutput => 'on_failure',
}
Convert the exec to a type/provider
        'user' type
ensure
name
comment
                             'useradd'
shell
home                          provider
                      exists?, create, destroy
                      comment, comment=
                                                 useradd <user>
                      shell, shell=
                      home, home=
                                                 usermod <user>


                                                 userdel <user>
Types: properties and parameters
● Properties are changeable, e.g. a user's
  shell or a service's start-at-boot flag
● Parameters represent other required data, e.
  g. hasrestart on service
● All data can be validated and munged
● Types can be "ensurable", if the object can:
  ○ exist and not exist
  ○ be created
  ○ be destroyed
Convert the exec to a type/provider
 'apt_key' type
ensure
key               'keyring' provider
key_server        exists?
                  create                   apt-key list
                  destroy
                                       apt-key --recv-keys..


                                           apt-key del
Types: simple example
$ cat apt_key/lib/puppet/type/apt_key.rb
Puppet::Type.newtype(:apt_key) do
  @doc = "Manages apt keys"

  ensurable

  newparam(:key) do
    desc "The key ID"
    isnamevar
  end

  newparam(:key_server) do
    desc "Key server to download key form"
    defaultto "pgp.mit.edu"
  end
end
Types: known values
Puppet::Type.type(:file).newparam(:checksum) do
  desc "The checksum type to use when
determining whether to replace a file's conten
ts.
  The default checksum type is md5."

  newvalues "md5", "md5lite", "mtime", "ctime",
"none"

  defaultto :md5
end
Types: validation
module Puppet
  newtype(:schedule) do
    newparam(:repeat) do
      desc "How often a given resource may be applied
in this schedule's `period`. Defaults to 1; must be an
integer."

      validate do |value|
        unless value.is_a?(Integer) or value =~
/^d+$/
          raise Puppet::Error,
            "Repeat must be a number"
        end
      end
Providers: getters/setters, ensurable
● getters and setters are implemented for each
  property
● ensurable types also have exists?, create
  and destroy to manage its existence
● list of commands that are required to run
● confined to certain operating systems via
  facts
Providers: simple example
$ cat apt_key/lib/puppet/provider/apt_key/keyring.rb
Puppet::Type.type(:apt_key).provide(:keyring) do
  commands :aptkey => "/usr/bin/apt-key"

  def exists?
    aptkey("list").include? resource[:key].upcase
  end

  def create
    aptkey "adv", "--keyserver", resource[:key_server], "--recv-
keys", resource[:key].upcase
  end

  def destroy
    aptkey "del", resource[:key].upcase
  end
end
Providers: confinement
Puppet::Type.type(:group).provide :aix do
  desc "Group management for AIX."

 confine :operatingsystem => :aix
 defaultfor :operatingsystem => :aix



Puppet::Type.type(:exec).provide :posix do
  confine :feature => :posix
  defaultfor :feature => :posix
Providers: instances and ralsh
$ puppet resource host
host { 'argon':
  ensure     => 'present',
  host_aliases => ['foo'],
  ip         => '192.168.0.10',
  target     => '/etc/hosts',
}

host { 'iridium':
  ensure     => 'present',
  host_aliases => ['localhost.localdomain', 'localhost'],
  ip         => '127.0.0.1',
  target     => '/etc/hosts',
}
Providers: instances and ralsh
def self.instances
  resources = []
  aptkey("list").each_line { |k| resources << new({:
name => $1}) if k =~ /^pubs+w+/(w+)/ }
  resources
end

# puppet resource apt_key
apt_key { '1F41B907':
   ensure => 'present'
}
apt_key { '46925553':
   ensure => 'present'
Testing providers with rspec
prov_c = Puppet::Type.type(:apt_key).provider(:keyring)
describe prov_c do
  it "should remove key" do
    resource = Puppet::Type.type(:apt_key).new(
      :name => '16BA136C',
      :ensure => :absent
    )
    provider = prov_c.new(resource)
    provider.expects(:aptkey).with('del', '16BA136C')
    provider.destroy
  end
end
Creating a module
$ puppet module generate domcleal-apt_key
$ cd domcleal-apt_key
$ mkdir -p lib/puppet/type 
     lib/puppet/provider/apt_key
$ touch lib/puppet/type/apt_key.rb 
     lib/puppet/provider/apy_key/keyring.rb
$ puppet module build .

upload pkg/domcleal-apt_key-0.0.1.tar.gz
Resources
● docs.puppetlabs.com guides
   ○ Writing custom types & providers
   ○ Provider development
● Puppet Types and Providers
   ○ Dan Bode & Nan Liu, O'Reilly, 2012
● puppet source itself, spec/unit/provider/
● puppetlabs_spec_helper

Contenu connexe

Tendances

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 MeetupKacper Gunia
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationWorkhorse Computing
 
Testing Backbone applications with Jasmine
Testing Backbone applications with JasmineTesting Backbone applications with Jasmine
Testing Backbone applications with JasmineLeon van der Grient
 
November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2Kacper Gunia
 
Keeping objects healthy with Object::Exercise.
Keeping objects healthy with Object::Exercise.Keeping objects healthy with Object::Exercise.
Keeping objects healthy with Object::Exercise.Workhorse Computing
 
Shell programming 1.ppt
Shell programming  1.pptShell programming  1.ppt
Shell programming 1.pptKalkey
 
BASH Guide Summary
BASH Guide SummaryBASH Guide Summary
BASH Guide SummaryOhgyun Ahn
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bitsChris Saylor
 
Stanford Hackathon - Puppet Modules
Stanford Hackathon - Puppet ModulesStanford Hackathon - Puppet Modules
Stanford Hackathon - Puppet ModulesPuppet
 
Any event intro
Any event introAny event intro
Any event introqiang
 
COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?Lloyd Huang
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationWorkhorse Computing
 

Tendances (20)

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
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
 
Memory Manglement in Raku
Memory Manglement in RakuMemory Manglement in Raku
Memory Manglement in Raku
 
Testing Backbone applications with Jasmine
Testing Backbone applications with JasmineTesting Backbone applications with Jasmine
Testing Backbone applications with Jasmine
 
Perl basics for pentesters part 2
Perl basics for pentesters part 2Perl basics for pentesters part 2
Perl basics for pentesters part 2
 
Perl Basics for Pentesters Part 1
Perl Basics for Pentesters Part 1Perl Basics for Pentesters Part 1
Perl Basics for Pentesters Part 1
 
Unix - Shell Scripts
Unix - Shell ScriptsUnix - Shell Scripts
Unix - Shell Scripts
 
November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2
 
Keeping objects healthy with Object::Exercise.
Keeping objects healthy with Object::Exercise.Keeping objects healthy with Object::Exercise.
Keeping objects healthy with Object::Exercise.
 
New in php 7
New in php 7New in php 7
New in php 7
 
Shell programming 1.ppt
Shell programming  1.pptShell programming  1.ppt
Shell programming 1.ppt
 
BASH Guide Summary
BASH Guide SummaryBASH Guide Summary
BASH Guide Summary
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bits
 
Stanford Hackathon - Puppet Modules
Stanford Hackathon - Puppet ModulesStanford Hackathon - Puppet Modules
Stanford Hackathon - Puppet Modules
 
Metadata-driven Testing
Metadata-driven TestingMetadata-driven Testing
Metadata-driven Testing
 
Any event intro
Any event introAny event intro
Any event intro
 
COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
 
Nubilus Perl
Nubilus PerlNubilus Perl
Nubilus Perl
 

En vedette

Deploying RDO OpenStack with a pair of plugins
Deploying RDO OpenStack with a pair of pluginsDeploying RDO OpenStack with a pair of plugins
Deploying RDO OpenStack with a pair of pluginsDominic Cleal
 
Writing your own augeasproviders
Writing your own augeasprovidersWriting your own augeasproviders
Writing your own augeasprovidersDominic Cleal
 
Foreman and Chef integration at ChefConf 2014
Foreman and Chef integration at ChefConf 2014Foreman and Chef integration at ChefConf 2014
Foreman and Chef integration at ChefConf 2014Dominic Cleal
 
Making your first contribution to Foreman
Making your first contribution to ForemanMaking your first contribution to Foreman
Making your first contribution to ForemanDominic Cleal
 
Extending Foreman the easy way with foreman_hooks
Extending Foreman the easy way with foreman_hooksExtending Foreman the easy way with foreman_hooks
Extending Foreman the easy way with foreman_hooksDominic Cleal
 
Foreman in Your Data Center :OSDC 2015
Foreman in Your Data Center :OSDC 2015Foreman in Your Data Center :OSDC 2015
Foreman in Your Data Center :OSDC 2015Stephen Benjamin
 

En vedette (6)

Deploying RDO OpenStack with a pair of plugins
Deploying RDO OpenStack with a pair of pluginsDeploying RDO OpenStack with a pair of plugins
Deploying RDO OpenStack with a pair of plugins
 
Writing your own augeasproviders
Writing your own augeasprovidersWriting your own augeasproviders
Writing your own augeasproviders
 
Foreman and Chef integration at ChefConf 2014
Foreman and Chef integration at ChefConf 2014Foreman and Chef integration at ChefConf 2014
Foreman and Chef integration at ChefConf 2014
 
Making your first contribution to Foreman
Making your first contribution to ForemanMaking your first contribution to Foreman
Making your first contribution to Foreman
 
Extending Foreman the easy way with foreman_hooks
Extending Foreman the easy way with foreman_hooksExtending Foreman the easy way with foreman_hooks
Extending Foreman the easy way with foreman_hooks
 
Foreman in Your Data Center :OSDC 2015
Foreman in Your Data Center :OSDC 2015Foreman in Your Data Center :OSDC 2015
Foreman in Your Data Center :OSDC 2015
 

Similaire à Replacing "exec" with a type and provider

Learning Puppet basic thing
Learning Puppet basic thing Learning Puppet basic thing
Learning Puppet basic thing DaeHyung Lee
 
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 2014Puppet
 
Perl: Hate it for the Right Reasons
Perl: Hate it for the Right ReasonsPerl: Hate it for the Right Reasons
Perl: Hate it for the Right ReasonsMatt Follett
 
From Dev to DevOps - Apache Barcamp Spain 2011
From Dev to DevOps - Apache Barcamp Spain 2011From Dev to DevOps - Apache Barcamp Spain 2011
From Dev to DevOps - Apache Barcamp Spain 2011Carlos Sanchez
 
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 2012Carlos Sanchez
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteBram Vogelaar
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013grim_radical
 
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 2012Carlos Sanchez
 
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014Puppet
 
Getting Started with PL/Proxy
Getting Started with PL/ProxyGetting Started with PL/Proxy
Getting Started with PL/ProxyPeter Eisentraut
 
Test-Driven Puppet Development - PuppetConf 2014
Test-Driven Puppet Development - PuppetConf 2014Test-Driven Puppet Development - PuppetConf 2014
Test-Driven Puppet Development - PuppetConf 2014Puppet
 
PM : code faster
PM : code fasterPM : code faster
PM : code fasterPHPPRO
 
From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011Carlos Sanchez
 
A tour of Ansible
A tour of AnsibleA tour of Ansible
A tour of AnsibleDevOps Ltd.
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl TechniquesDave Cross
 

Similaire à Replacing "exec" with a type and provider (20)

Learning Puppet basic thing
Learning Puppet basic thing Learning Puppet basic thing
Learning Puppet basic thing
 
Puppet
PuppetPuppet
Puppet
 
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
 
Perl: Hate it for the Right Reasons
Perl: Hate it for the Right ReasonsPerl: Hate it for the Right Reasons
Perl: Hate it for the Right Reasons
 
Puppet @ Seat
Puppet @ SeatPuppet @ Seat
Puppet @ Seat
 
From Dev to DevOps - Apache Barcamp Spain 2011
From Dev to DevOps - Apache Barcamp Spain 2011From Dev to DevOps - Apache Barcamp Spain 2011
From Dev to DevOps - Apache Barcamp Spain 2011
 
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
 
Puppet fundamentals
Puppet fundamentalsPuppet fundamentals
Puppet fundamentals
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suite
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013
 
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
 
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
 
Getting Started with PL/Proxy
Getting Started with PL/ProxyGetting Started with PL/Proxy
Getting Started with PL/Proxy
 
Test-Driven Puppet Development - PuppetConf 2014
Test-Driven Puppet Development - PuppetConf 2014Test-Driven Puppet Development - PuppetConf 2014
Test-Driven Puppet Development - PuppetConf 2014
 
Ansible
AnsibleAnsible
Ansible
 
PM : code faster
PM : code fasterPM : code faster
PM : code faster
 
From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011
 
A tour of Ansible
A tour of AnsibleA tour of Ansible
A tour of Ansible
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Intro to-puppet
Intro to-puppetIntro to-puppet
Intro to-puppet
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 

Dernier (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Replacing "exec" with a type and provider

  • 1. Replacing "exec" with a type and provider Return manifests to a declarative configuration Dominic Cleal <dcleal@redhat.com>
  • 2. Puppet's declarative DSL user { 'dcleal': ensure => present, comment => 'Dominic Cleal', shell => '/bin/bash', } package { 'vim': ensure => 'present', }
  • 3. How execs can fail $ puppet module install puppetlabs-apt $ vim apt/manifests/key.pp ... exec { "apt::key ${upkey} absent": command => "apt-key del '${upkey}'", path => '/bin:/usr/bin', onlyif => "apt-key list | grep '${upkey}'", user => 'root', group => 'root', logoutput => 'on_failure', }
  • 4. Convert the exec to a type/provider 'user' type ensure name comment 'useradd' shell home provider exists?, create, destroy comment, comment= useradd <user> shell, shell= home, home= usermod <user> userdel <user>
  • 5. Types: properties and parameters ● Properties are changeable, e.g. a user's shell or a service's start-at-boot flag ● Parameters represent other required data, e. g. hasrestart on service ● All data can be validated and munged ● Types can be "ensurable", if the object can: ○ exist and not exist ○ be created ○ be destroyed
  • 6. Convert the exec to a type/provider 'apt_key' type ensure key 'keyring' provider key_server exists? create apt-key list destroy apt-key --recv-keys.. apt-key del
  • 7. Types: simple example $ cat apt_key/lib/puppet/type/apt_key.rb Puppet::Type.newtype(:apt_key) do @doc = "Manages apt keys" ensurable newparam(:key) do desc "The key ID" isnamevar end newparam(:key_server) do desc "Key server to download key form" defaultto "pgp.mit.edu" end end
  • 8. Types: known values Puppet::Type.type(:file).newparam(:checksum) do desc "The checksum type to use when determining whether to replace a file's conten ts. The default checksum type is md5." newvalues "md5", "md5lite", "mtime", "ctime", "none" defaultto :md5 end
  • 9. Types: validation module Puppet newtype(:schedule) do newparam(:repeat) do desc "How often a given resource may be applied in this schedule's `period`. Defaults to 1; must be an integer." validate do |value| unless value.is_a?(Integer) or value =~ /^d+$/ raise Puppet::Error, "Repeat must be a number" end end
  • 10. Providers: getters/setters, ensurable ● getters and setters are implemented for each property ● ensurable types also have exists?, create and destroy to manage its existence ● list of commands that are required to run ● confined to certain operating systems via facts
  • 11. Providers: simple example $ cat apt_key/lib/puppet/provider/apt_key/keyring.rb Puppet::Type.type(:apt_key).provide(:keyring) do commands :aptkey => "/usr/bin/apt-key" def exists? aptkey("list").include? resource[:key].upcase end def create aptkey "adv", "--keyserver", resource[:key_server], "--recv- keys", resource[:key].upcase end def destroy aptkey "del", resource[:key].upcase end end
  • 12. Providers: confinement Puppet::Type.type(:group).provide :aix do desc "Group management for AIX." confine :operatingsystem => :aix defaultfor :operatingsystem => :aix Puppet::Type.type(:exec).provide :posix do confine :feature => :posix defaultfor :feature => :posix
  • 13. Providers: instances and ralsh $ puppet resource host host { 'argon': ensure => 'present', host_aliases => ['foo'], ip => '192.168.0.10', target => '/etc/hosts', } host { 'iridium': ensure => 'present', host_aliases => ['localhost.localdomain', 'localhost'], ip => '127.0.0.1', target => '/etc/hosts', }
  • 14. Providers: instances and ralsh def self.instances resources = [] aptkey("list").each_line { |k| resources << new({: name => $1}) if k =~ /^pubs+w+/(w+)/ } resources end # puppet resource apt_key apt_key { '1F41B907': ensure => 'present' } apt_key { '46925553': ensure => 'present'
  • 15. Testing providers with rspec prov_c = Puppet::Type.type(:apt_key).provider(:keyring) describe prov_c do it "should remove key" do resource = Puppet::Type.type(:apt_key).new( :name => '16BA136C', :ensure => :absent ) provider = prov_c.new(resource) provider.expects(:aptkey).with('del', '16BA136C') provider.destroy end end
  • 16. Creating a module $ puppet module generate domcleal-apt_key $ cd domcleal-apt_key $ mkdir -p lib/puppet/type lib/puppet/provider/apt_key $ touch lib/puppet/type/apt_key.rb lib/puppet/provider/apy_key/keyring.rb $ puppet module build . upload pkg/domcleal-apt_key-0.0.1.tar.gz
  • 17. Resources ● docs.puppetlabs.com guides ○ Writing custom types & providers ○ Provider development ● Puppet Types and Providers ○ Dan Bode & Nan Liu, O'Reilly, 2012 ● puppet source itself, spec/unit/provider/ ● puppetlabs_spec_helper