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

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Dernier (20)

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.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