Upload
puppet-labs
View
417
Download
2
Embed Size (px)
DESCRIPTION
Absolute Beginners Guide to Puppet Through Types - Igor Galić, Brainsware OG
Citation preview
Complete Beginners' Guideto Puppet - Through Types!
Guide to Puppet - Through Types!
whoamiIgor Galić
igalic (gh/irc)
@hirojin (twitter)
whoami
how i got here🚗✈🚅
how i got herec ... 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 chaos aseffectively as possible."
dijkstra"Simplicity is a great virtue but it requires hard work toachieve it and education to appreciate it. And to makematters worse: complexity sells better."
nooop
include 'ssh'
hiera
class { 'ssh': permit_root_login => false,}
include
include 'ssh'
resources
igalic@levix ~ % puppet resource user igalicuser { '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 ~ %
differences
dsl detail types & providersnope access to the RAL yuppsub-typesbranching
impl diff platforms providers
same/same contract/impl type/provider"easy" overload $name messy
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], }}
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.config entries'
newparam(:record, :namevar => true) do desc "record entry" end
newproperty(:value) do desc "Value of this record" end
end
intermezzo
"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]
intermezzo
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}'", }}
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}'",}
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
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
done
referencespuppet 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 </3Hunter Haugen <3
pry <3
https://github.com/Brainsware/puppet-trafficserver
https://github.com/puppetlabs/puppetlabs-git