Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Design Patterns in Configuration Management - Part 1

Design Patterns in Configuration Management - Part 1

This is the first presentation in a series of talks describing architecture patterns for infrastructure and the underlying code patterns necessary to support these patterns.

This deck describes the following patterns:

* Modularity
* Managing Complex States
* Convention over Configuration
* Proxy/Factory Patterns in Puppet

This presentation is an accompanying deck to the presentation "Data Driven Infrastructure" which can be found at https://speakerdeck.com/jfryman/building-data-driven-infrastructure-with-puppet

A full video of this talk can be found at https://www.youtube.com/watch?v=e4lAzjCKk24

James Fryman

May 14, 2014
Tweet

More Decks by James Fryman

Other Decks in Technology

Transcript

  1. Self-Correct Not Serving Log Remove from LB Cycle Service Escalate

    Assets Missing Ready Validate FS Configuration Success
  2. define  statemachine::set(      $ensure    =  present,    

     $base        =  $name,      $state      =  undef,      $backend  =  $statemachine::config::backend,   )  {      if  $state  {          ensure_resource($backend,  $name,  {              "ensure"  =>  $ensure,              "base"      =>  $base,              "state"    =>  $state,          })      }  else  {          statemachine::log  {  "Unable  to  set  state  for  $ {base}.  Missing  state.  Skipping...":  }      }   }
  3. class  statemachine::config  (      $logger      =  'statemachine::logger::console',

         $backend    =  'statemachine::backend::local',   )  {      validate_string($logger,  $backend)   !    File  {          ensure  =>  file,          owner    =>  'root',          group    =>  'root',          mode      =>  '0755',      }   !    file  {  '/etc/statemachine':          ensure  =>  directory,      }      file  {  '/etc/facter/facts.d/statemachine':          source  =>  'puppet:///modules/statemachine/etc/facter/facts.d/statemachine',      }      file  {  '/usr/local/bin/statemachine':          source  =>  'puppet:///modules/statemachine/usr/local/bin/statemachine',      }   }
  4. define  statemachine::backend::local(      $ensure  =  present,      $base

         =  $name,      $state    =  undef,   )  {      include  statemachine::backend::local::config      $settings  =  $statemachine::backend::local::config::settings      validate_hash($settings)   !    validate_re($ensure,  '^(absent|present)$')      validate_string($base,  $state)   !    $state_file  =  regsubst($base,  '::',  '_',  'G')   !    file  {  "${settings['base_dir']}/${state_file}":          ensure    =>  $ensure,          owner      =>  'root',          group      =>  'root',          mode        =>  '0644',          content  =>  "${state}\n",      }   }
  5. statemachine  {  'frymanet::base':      states  =>  [    

         'provisioning',          'config',          'ready',      ],   } Declare
  6. -­‐-­‐-­‐   :base:  frymanet::base   :hierarchy:      -­‐  platform/%{::virtual}

         -­‐  platform/%{::productname}      -­‐  platform/%{::operatingsystem}      -­‐  platform/%{::operatingsystem}/%{::lsbdistcodename}      -­‐  platform/%{::cloud}      -­‐  platform/%{::datacenter}      -­‐  platform/%{::datacenter}/%{::operatingsystem} Stacks
  7. require  'yaml'   ! module  Puppet::Parser::Functions      newfunction(:find_ladder_rungs,  :type

     =>  :rvalue,                              :doc  =>  'Find  all  manifests  eligible  for  import  based  on  a  ladder  stack')   do  |args|          load_stack      =  args[0]          stack_config  =  "#{lookupvar('ladder::config::conf_dir')}/#{load_stack}.yaml"          module_path    =  File.expand_path('..',  Puppet::Module.find('ladder',   compiler.environment.to_s).path)          manifests        =  []   !        #  Recursively  render  the  rung  and  populate  with  real  values          def  expand_rung(rung)              rung.sub!(/%{(.*)}/)  {  |match|  lookupvar(match.first)  }              rung.match(/%{(.*)}/)  ?  expand_rung(rung)  :  rung.gsub(/\//,  '::')          end   !        if  File.exists?  stack_config              stack  =  YAML.load_file  "#{module_path}/#{stack_config}"   !            stack[:hierarchy].each  do  |rung|                  rung_lookup  =  "#{stack[:base]}::#{expand_rung(rung)}"   !                if  Puppet::Module.find(rung_lookup,  compiler.environment.to_s)                      manifests  <<  rung_lookup                  end              end          end   !