Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Complete Beginners' Guide 
to Puppet - Through Types!
Guide to Puppet - Through Types!
whoami 
Igor Galić 
igalic (gh/irc) 
@hirojin (twitter)
whoami
how i got here 
 ✈ 
how i got here 
c ... bash ... perl 
linux ... make ... ansible 
puppet
how i got here
why this talk exists
why this talk exists
dijkstra 
"The art of programming is the art of organizing complexity, 
of mastering multitude and avoiding its bastard ch...
dijkstra 
"Simplicity is a great virtue but it requires hard work to 
achieve it and education to appreciate it. And to ma...
nooop 
include 'ssh'
hiera 
class { 'ssh': 
permit_root_login => false, 
}
include 
include 'ssh'
resources 
igalic@levix ~ % puppet resource user igalic 
user { 'igalic': 
ensure => 'present', 
comment => 'Igor Galić,,,...
differences 
dsl detail types & providers 
nope access to the RAL yupp 
sub-types 
impl diff platforms providers 
branchin...
defined type 
define trafficserver::config::records ( 
$changes = [ $title ], 
) { 
include 'trafficserver' 
$configfile =...
symmetry 
@@trafficserver_record { 'proxy.config.http.server_ports': 
changes => '80:ipv4 80:ipv6', 
}
"simple" type 
Puppet::Type.newtype(:trafficserver_record) do 
desc 'trafficserver_record is a type to manage records.conf...
intermezzo
"simple" provider 
Puppet::Type.type(:trafficserver_record).provide(:traffic_line) do 
desc 'Manage traffic server records...
intermezzo
defined type 
define git::config( 
$value, 
$section = regsubst($name, '^([^.]+).([^.]+)$','1'), 
$key = regsubst($name, '...
implementation (wrong) 
exec{"git config --global ${section}.${key} '${value}'": 
environment => inline_template('<%= "HOM...
type 
Puppet::Type.newtype(:git_config) do 
validate do 
fail('it is required to pass "value"') if self[:value].nil? || se...
implementation (correct) 
Puppet::Type.type(:git_config).provide(:git_config) do 
mk_resource_methods 
def check_current?(...
done
references 
puppet types and providers by Dan Bode & Nan Liu 
shit gary larizza says, e.g.: http://garylarizza.com/blog/20...
Upcoming SlideShare
Loading in …5
×

Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014

1,697 views

Published on

Absolute Beginners Guide to Puppet Through Types - Igor Galić, Brainsware OG

Published in: Technology
  • Be the first to comment

Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014

  1. 1. Complete Beginners' Guide to Puppet - Through Types!
  2. 2. Guide to Puppet - Through Types!
  3. 3. whoami Igor Galić igalic (gh/irc) @hirojin (twitter)
  4. 4. whoami
  5. 5. how i got here  ✈ 
  6. 6. how i got here c ... bash ... perl linux ... make ... ansible puppet
  7. 7. how i got here
  8. 8. why this talk exists
  9. 9. why this talk exists
  10. 10. dijkstra "The art of programming is the art of organizing complexity, of mastering multitude and avoiding its bastard chaos as effectively as possible."
  11. 11. dijkstra "Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better."
  12. 12. nooop include 'ssh'
  13. 13. hiera class { 'ssh': permit_root_login => false, }
  14. 14. include include 'ssh'
  15. 15. resources igalic@levix ~ % puppet resource user igalic user { 'igalic': ensure => 'present', comment => 'Igor Galić,,,', gid => '1000', groups => ['adm', 'cdrom', 'sudo', 'dip', 'plugdev', 'lpadmin', 'sambashare', ' home => '/home/igalic', shell => '/bin/zsh', uid => '1000', } igalic@levix ~ %
  16. 16. differences dsl detail types & providers nope access to the RAL yupp sub-types impl diff platforms providers branching same/same contract/impl type/provider "easy" overload $name messy
  17. 17. defined type define trafficserver::config::records ( $changes = [ $title ], ) { include 'trafficserver' $configfile = "${::trafficserver::sysconfdir}/records.config" $lens = 'Trafficserver_records.lns' $context = "/files${configfile}" $incl = $configfile augeas { "${lens}_${title}": lens => $lens, context => $context, incl => $incl, changes => $changes, notify => Exec[trafficserver-config-reload], } }
  18. 18. symmetry @@trafficserver_record { 'proxy.config.http.server_ports': changes => '80:ipv4 80:ipv6', }
  19. 19. "simple" type Puppet::Type.newtype(:trafficserver_record) do desc 'trafficserver_record is a type to manage records.config entries' newparam(:record, :namevar => true) do desc "record entry" end newproperty(:value) do desc "Value of this record" end end
  20. 20. intermezzo
  21. 21. "simple" provider Puppet::Type.type(:trafficserver_record).provide(:traffic_line) do desc 'Manage traffic server records.config entries using traffic_line command' commands :traffic_line => 'traffic_line' mk_resource_methods ConfigPattern = 'proxy.(config|local|cluster).*' def initialize(value={}) super(value) end def name=(value) @property_hash[:name] = value end # this method is only called when value isn't insync? def value=(value) @property_hash[:name] = resource[:name]
  22. 22. intermezzo
  23. 23. defined type define git::config( $value, $section = regsubst($name, '^([^.]+).([^.]+)$','1'), $key = regsubst($name, '^([^.]+).([^.]+)$','2'), $user = 'root', ) { exec{"git config --global ${section}.${key} '${value}'": environment => inline_template('<%= "HOME=" + ENV["HOME"] %>'), path => ['/usr/bin', '/bin', '/usr/local/bin'], user => $user, unless => "git config --global --get ${section}.${key} '${value}'", } }
  24. 24. implementation (wrong) exec{"git config --global ${section}.${key} '${value}'": environment => inline_template('<%= "HOME=" + ENV["HOME"] %>'), path => ['/usr/bin', '/bin', '/usr/local/bin'], user => $user, unless => "git config --global --get ${section}.${key} '${value}'", }
  25. 25. type Puppet::Type.newtype(:git_config) do validate do fail('it is required to pass "value"') if self[:value].nil? || self[:value].em end newparam(:name) do desc "The default namevar" end newparam(:user) do desc "The user for which the config will be set. Default value: root" defaultto "root" end newparam(:section, :namevar => true) do desc "The configuration section. Example: user." end newparam(:key, :namevar => true) do desc "The configuration key. Example: email." end
  26. 26. implementation (correct) Puppet::Type.type(:git_config).provide(:git_config) do mk_resource_methods def check_current?(value) require 'etc' user = @resource[:user] key = @resource[:key] section = @resource[:section] home = Etc.getpwnam(user)[:dir] current = Puppet::Util::Execution.execute( "git config --global --get #{section}.#{key}", :uid => user, :failonfail => false, :custom_environment => { 'HOME' => home } ) return value == current.strip end def update
  27. 27. done
  28. 28. references puppet types and providers by Dan Bode & Nan Liu shit gary larizza says, e.g.: http://garylarizza.com/blog/2013 /12/15/seriously-what-is-this-provider-doing/ <3 ADRIEN THEBO <3 Morgan Haskel <3 Ashley Penney </3 Hunter Haugen <3 pry <3 https://github.com/Brainsware/puppet-trafficserver https://github.com/puppetlabs/puppetlabs-git

×