96
Friday, August 23, 13

Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Embed Size (px)

DESCRIPTION

"Building Data-Driven Infrastructure with Puppet" by James Fryman, Operations Hacker, GitHub, Inc. Presentation Overview: As your Puppet Infrastructure grows, so does the complexity of the Puppet codebase. The complexity of the codebase often creates a scenario where it becomes more time consuming to modify/add to the codebase. Likewise, any new addition or node still may require modifications to the Puppet database, which could include the management of many edge cases. Fortunately, the software industry has been working on developing techniques with code abstraction, refactoring, and software maturity. This talk will focus on how to write scalable modules within Puppet to be used to create Data Driven Infrastructures. In addition, this talk will demonstrate how to structure process/procedure/code to quickly and rapidly scale operations with minimal modifications to Puppet code. Speaker Bio: James Fryman, Operations Hacker, GitHub, Inc. James Fryman is a Technologist who has been working on spreading the good word of technology via the greatest mechanism known to man: the beer fueled rant. James has been working to automate software and infrastructure for the last 10 years, and has learned quite a bit about Security, Architecture, Scaling, and Development as a result. James currently works for GitHub as an Operations Hacker.

Citation preview

Page 1: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Friday, August 23, 13

Page 2: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

DataDrivenInfrastructure

Friday, August 23, 13

Page 3: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Friday, August 23, 13

Page 4: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

?

Friday, August 23, 13

Page 5: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

?

http://git.io/UmUdKAFriday, August 23, 13

Page 6: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Let meTell youa story

Friday, August 23, 13

Page 7: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

What is a

Cloud

Friday, August 23, 13

Page 8: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

I don’t have to think about IT

With the Cloud...

Friday, August 23, 13

Page 9: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Friday, August 23, 13

Page 10: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

aaSPlatformSoftware

Infrastructure

Friday, August 23, 13

Page 11: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Friday, August 23, 13

Page 12: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Friday, August 23, 13

Page 13: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Where is our cloud?

Friday, August 23, 13

Page 14: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Friday, August 23, 13

Page 15: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

UtopiaFriday, August 23, 13

Page 16: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

James Fryman

Friday, August 23, 13

Page 17: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Friday, August 23, 13

Page 18: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Automations Junkie

Friday, August 23, 13

Page 19: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Are youCrazy?

Friday, August 23, 13

Page 20: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Goals?Data?What

Friday, August 23, 13

Page 21: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Goals?Data?What

Friday, August 23, 13

Page 22: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Goals?Data?What

Friday, August 23, 13

Page 23: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Machine

Parsable

Friday, August 23, 13

Page 24: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

There is SystemOne

Friday, August 23, 13

Page 25: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Feedback

PuppetDBProvisioning

Configuring

Destroying

gPanel

Friday, August 23, 13

Page 26: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Partsof the

SystemFriday, August 23, 13

Page 27: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

provisioner

Friday, August 23, 13

Page 28: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Home GrownFriday, August 23, 13

Page 29: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Home Grown

Friday, August 23, 13

Page 30: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

controller

Friday, August 23, 13

Page 31: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Lots O’ Models

Friday, August 23, 13

Page 32: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

file { '/etc/facter/facts.d/quagga_manage_service': ensure => present, replace => false,} if $::quagga_manage_service { $service_state[ensure] = running $service_state[enable] = true} else { $service_state[ensure] = undef $service_state[enable] = undef} service { 'quagga': ensure => $service_state[ensure], enable => $service_state[enable],}

Friday, August 23, 13

Page 33: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

orchestrator

Friday, August 23, 13

Page 34: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

ChatOps

Friday, August 23, 13

Page 35: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

ChatOps

Friday, August 23, 13

Page 36: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Feedbackof the

SystemFriday, August 23, 13

Page 37: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Metrics&MonitoringFriday, August 23, 13

Page 38: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

begin JSON.parse(RestClient.get(url)).each do |cache| data["#{cache['target']}"] = 0 count = 0 cache["datapoints"].each do |point| unless (point[0].nil?) data["#{cache['target']}"] += point[0] count += 1 end end data["#{cache['target']}"] /= count data["total"] += data["#{cache['target']}"] endrescue ZeroDivisionError => e puts "UNKNOWN metric not in graphite!" exit EXIT_UNKNOWNrescue => e puts e.message exit EXIT_CRITICALend

Friday, August 23, 13

Page 39: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

begin JSON.parse(RestClient.get(url)).each do |cache| data["#{cache['target']}"] = 0 count = 0 cache["datapoints"].each do |point| unless (point[0].nil?) data["#{cache['target']}"] += point[0] count += 1 end end data["#{cache['target']}"] /= count data["total"] += data["#{cache['target']}"] endrescue ZeroDivisionError => e puts "UNKNOWN metric not in graphite!" exit EXIT_UNKNOWNrescue => e puts e.message exit EXIT_CRITICALend

Friday, August 23, 13

Page 40: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

event

Friday, August 23, 13

Page 41: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

eventlog

Friday, August 23, 13

Page 42: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

eventalertlog

Friday, August 23, 13

Page 43: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

eventalertlog error

Friday, August 23, 13

Page 44: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Must self-correct

Friday, August 23, 13

Page 45: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Feedback

PuppetDBProvisioning

Configuring

Destroying

gPanel

Friday, August 23, 13

Page 46: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Friday, August 23, 13

Page 47: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Deployable using text files

Friday, August 23, 13

Page 48: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Modularity

Friday, August 23, 13

Page 49: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

haproxy::proxy { $es_proxy_name: proxy => 'listen', mode => 'http', ip => $::ipaddress_lo, port => '9200', config => { balance => 'roundrobin', }, }

Friday, August 23, 13

Page 50: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

haproxy::proxy { $es_proxy_name: proxy => 'listen', mode => 'http', ip => $::ipaddress_lo, port => '9200', config => { balance => 'roundrobin', }, }

Friday, August 23, 13

Page 51: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

haproxy::proxy::member { $es_proxy_name: hostname => $::ec2_local_ipv4, port => '9200', param => [ 'weight 1', 'maxconn 1000', 'check', ], }

Friday, August 23, 13

Page 52: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

collectd::plugin { [ 'cpu', 'load', 'memory', 'swap', 'irq', 'exec', 'entropy', ]: } 

collectd::plugin { [ 'df', 'interface', 'protocols', 'disk', ]: config => true }

Friday, August 23, 13

Page 53: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Level 4:Templates

Level 5:Data Driven

Friday, August 23, 13

Page 54: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

SelfAuthoritati

ve

Friday, August 23, 13

Page 55: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

def self.collect_resources(resource) query = [ "and", ["=", "type", "File"], ["=", "exported", true], ["=", "tag", "nagios::object::#{resource}"], ["=", ["node", "active"], true] ] self.search('/v2/resources', query.to_json) end

Friday, August 23, 13

Page 56: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

def self.collect_resources(resource) query = [ "and", ["=", "type", "File"], ["=", "exported", true], ["=", "tag", "nagios::object::#{resource}"], ["=", ["node", "active"], true] ] self.search('/v2/resources', query.to_json) end

Friday, August 23, 13

Page 57: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

# Seed the initial file with false, and enable # on next run with gh-nagios enable_pager <hostname>

file { '/etc/facter/facts.d/enable_pager.txt': ensure => file, owner => 'root', group => 'root', mode => '0644', content => 'enable_pager=false', replace => false,}

Friday, August 23, 13

Page 58: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

@@file { "/etc/nagios/objects/${type}.d/${filename}.cfg": content => template('nagios/etc/nagios/object.erb'), mode => '0444', group => 'nagios', notify => Service['nagios'], }

Friday, August 23, 13

Page 59: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Tips

Friday, August 23, 13

Page 60: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Refactoring

Friday, August 23, 13

Page 61: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Refactoring

Friday, August 23, 13

Page 62: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

least to mostspecific

Friday, August 23, 13

Page 63: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

frymanet.com

mysqlnginx rails

rubycommon admin

package repos

Friday, August 23, 13

Page 64: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

graduate to params

Friday, August 23, 13

Page 65: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

class ntp::params {  $defaults = { package => { version => ‘latest’, }, config => { servers => [‘pool.ntp.org’], }, }}

Friday, August 23, 13

Page 66: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

externalize

Friday, August 23, 13

Page 67: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

class ntp::params {  $defaults = { package => { version => hiera(‘ntp_package_version’), }, config => { servers => hiera(‘ntp_servers’), }, }}

Friday, August 23, 13

Page 68: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

CloudFormation

Friday, August 23, 13

Page 69: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

CloudFormation

Friday, August 23, 13

Page 70: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

"Resources": { "RendererServerGroup": { "Type": "AWS::AutoScaling::AutoScalingGroup", "Properties": { "AvailabilityZones": { "Fn::GetAZs": "" }, "LaunchConfigurationName": { "Ref": "LaunchConfig" }, "MinSize": "2", "MaxSize": "16", "Tags": [ { "Key": "Environment", "Value": "Production", "PropagateAtLaunch": "true" }, { "Key": "Role", "Value": "renderer", "PropagateAtLaunch": "true" } ] } },Friday, August 23, 13

Page 71: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Autoloading

Friday, August 23, 13

Page 72: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

# autoloader.ppclass nagios::autoload_helpers { $helpers = get_nagios_helpers()

case $::puppetversion { /^3/: { include $helpers } default: { nagios::autoload_helpers::import_shim { $helpers: } } }}

Friday, August 23, 13

Page 73: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

# autoloader.ppclass nagios::autoload_helpers { $helpers = get_nagios_helpers()

case $::puppetversion { /^3/: { include $helpers } default: { nagios::autoload_helpers::import_shim { $helpers: } } }}

Friday, August 23, 13

Page 74: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

module Puppet::Parser::Functions newfunction(:get_nagios_helpers, :type => :rvalue, :doc => "Grab all modules that have nagios helpers for import") do

module_path = File.expand_path('..', Puppet::Module.find('nagios',compiler.environment.to_s).path)

helpers = Dir["#{module_path}/**/nagios/helpers.pp"].map do |d| "#{d.split('/')[-4]}::nagios::helpers" done

helpers endend

Friday, August 23, 13

Page 75: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Modeling

Friday, August 23, 13

Page 76: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Be Dynamic Friday, August 23, 13

Page 77: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Be Dynamic Friday, August 23, 13

Page 78: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

<%- if @comment -%>### <%= @comment %><%- end -%><%= @type %> <% if @label %><%= @label %><% end %> {<%- @config.sort.reverse.each do |key,value| -%> <%- if value.class == Array -%> <%- value.each do |element| -%> <%= key %>(<%= element %>); <%- end -%> <%- else -%> <%= key %>(<%= value %>); <%- end -%><%- end -%>};

Friday, August 23, 13

Page 79: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Fencing Resources

Friday, August 23, 13

Page 80: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

# Seed the initial file with false, and enable # on next run with gh-nagios enable_pager <hostname>

file { '/etc/facter/facts.d/enable_pager.txt': ensure => file, owner => 'root', group => 'root', mode => '0644', content => 'enable_pager=false', replace => false,}

Friday, August 23, 13

Page 81: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

if $::enable_pager { @@file { "/etc/nagios/objects/${type}.d/${filename}.cfg": content => template('nagios/etc/nagios/object.erb'), mode => '0444', group => 'nagios', notify => Service['nagios'], }}

Friday, August 23, 13

Page 82: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Buy it?

Friday, August 23, 13

Page 83: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Buy it?

Friday, August 23, 13

Page 84: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

It’s About

Friday, August 23, 13

Page 85: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Missing?What’s

Friday, August 23, 13

Page 86: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

LanguageFriday, August 23, 13

Page 87: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Predictive Analysis

Friday, August 23, 13

Page 88: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Coming

Home

Friday, August 23, 13

Page 89: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Goals?Data?What

Friday, August 23, 13

Page 90: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

SystemsThinking

Recap

Friday, August 23, 13

Page 91: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

There is SystemOne

Machine

Parsable

Must be a

Known

Quantity

SelfAuthoritati

veMust self-correct

Friday, August 23, 13

Page 92: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

Friday, August 23, 13

Page 95: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

what’s next?

Friday, August 23, 13

Page 96: Building Data-Driven Infrastructure with Puppet - PuppetConf 2013

what’s next?

Friday, August 23, 13