Top Banner
Puppet at the Puppet at the center of everything center of everything http://www.rankpop.com/you-need-to-start-structuring-your-blog-posts-asap/
37

Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Jul 15, 2015

Download

Technology

NETWAYS
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Puppet at thePuppet at thecenter of everythingcenter of everything

http://www.rankpop.com/you-need-to-start-structuring-your-blog-posts-asap/

Page 2: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge
Page 3: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

serverdensity.com/knockknock

Page 4: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Server Density Architecture

100+ servers – Ubuntu 12.04

50% Virtual

Nginx, Python, MongoDB

25TB data per month

Page 5: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Puppet Use Cases

Code deploys

Failover

Configuration

System Updates

http://www.arcomem.eu/wp-content/uploads/2011/03/usecases.png

Page 6: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

http://www.flickr.com/photos/conskeptical/

Puppet Use CasesConfiguration

nginx::config::worker_rlimit_nofile: 30000nginx::config::worker_connections: 10240nginx::config::worker_processes: 4

storm::config_file: '/etc/storm/storm.yaml'storm::drpc::manage_service: falsestorm::drpc::enable: false

Forge modules - don't reinvent the wheel:https://forge.puppetlabs.com/jfryman/nginx

https://forge.puppetlabs.com/deric/storm

Page 7: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

http://www.flickr.com/photos/conskeptical/

Puppet Use CasesConfiguration

include nginx

include storm

Page 8: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Puppet Use CasesCode deploys

Commit and wait for the build

buildbot.net

Page 9: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Puppet Use CasesCode deploys

Check what is deployed

Page 10: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Puppet Use CasesCode deploys

Deploy

Page 11: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Puppet Use CasesCode deploys

Deploy

Puppet::Type.type(:package).provide(:honshuu,        :parent => Puppet::Provider::Package) do   desc "Server Density deployinator"

package {  'honshuu­alerts­processing':     ensure   => present,     provider => honshuu,     require  => File['/var/www/'],     notify   => Service['celeryd­alerts','apache2'],}

Page 12: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Puppet Use CasesCode deploys

Deploy

MCollective magic

Page 13: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

nginx 'on-the-fly' update

Puppet Use CasesFailover

Page 14: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

nginx 'on-the-fly' update

class serverdensity­nginx{    class { 'nginx': }    nginx::resource::upstream {       'socky_rack':          ensure => present,          members => split( $lbTargetHostsSocky, ',' ),    }(...)

Page 15: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

nginx 'on-the-fly' update

Page 16: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

nginx 'on-the-fly' update

Page 17: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

nginx 'on-the-fly' update

Page 18: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

nginx 'on-the-fly' update

Page 19: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Puppet Use CasesSystem updates

Update apt cache – just to be sure

Page 20: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Puppet Use CasesSystem updates

Run

CANARIES=" \  hstage1.honshuu.dev \  hstage2.honshuu.dev \  hstage­lb1.honshuu.dev \  exm­a1.sng.amz \  ma1.dal.sl \  sdcom­web1.wdc.sl \  queues­rab2.wdc.sl \"

Page 21: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Puppet Use CasesSystem updates

Run

for i in $CANARIES  do    mco rpc puppetral ­I $i create type=exec        title="/bin/bash ­c 'apt­get dist­upgrade ­y'"done

Page 22: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Reducing the code baseMongoDB

class mongo­a{(…)191 lines of code+Templates for config files and init scripts

class mongo­c{(…)179 lines of code+Template for config file

Page 23: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Reducing the code baseMongoDB

class mongo­d{(…)257 lines of code+Templates for config files, init scripts, pam and limits

class mongo­s{(…)180 lines of code+Template for config file and init script

Page 24: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Reducing the code baseMongoDB

Forge module + Hierahttps://forge.puppetlabs.com/dwerder/mongodb

class site::mongomodule {   class { '::mongodb::globals':     manage_package_repo => true,     version             => '2.4.12'  } ­>  class { '::mongodb::server': verbose => true }}

Page 25: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Extending Server Density

Server Density collects server data from an open source agent deployed on each device

The agent reads the device ID from a config file:

[Main]sd_url: http://mydomain.serverdensity.comagent_key: 8160b409de9d8a612ec8d964c5b26bf(...)

Copy the device ID (agent key)

Create a device on Server Density UI

Page 26: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Server Density v1:

Extending Server Density

Page 27: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Server Density v1:

[Main]sd_url: http://boxedice.serverdensity.comagent_key: <%= sdAgentKey %>(...)

Extending Server Density

'sd­agent':    ensure => installed,

file {    'config.cfg':      path    => '/etc/sd­agent/config.cfg',      ensure  => file,      require => Package['sd­agent'],      content => template('sd­agent/config.erb'),}

Page 28: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Server Density v2:

Extending Server Density

Page 29: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Server Density v2 – in action:

Extending Server Density

Page 30: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Server Density v2 – in action:

Extending Server Density

Page 31: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Server Density v2 - implementation:

Manages the life cycle of Rackspace and Amazon cloud instances

A custom fact will return the cloud instance agent key

Extending Server Density

or use Server Density API to create a device on the fly and return the resulting agent key

https://github.com/serverdensity/puppet-serverdensity

Page 32: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Custom fact:

Facter.add(:agent_key, :timeout => 10) do    if File::exist?('/etc/sd­agent­key')        result = Facter::Util::Resolution.exec("cat /etc/sd­agent­key")    elsif Facter.value('ec2_instance_id')        uri = URI("http://ec2meta.serverdensity.com/latest/user­data")        req = Net::HTTP::Get.new(uri.request_uri)        res = Net::HTTP.start(uri.host, uri.port) {|http|                http.request(req)        }        result = res.body.split(':').last if res.code == 200    end

    setcode { result }end

Extending Server Density

Page 33: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Custom function:

(...)        agent_key = lookupvar("agent_key")

        # lookupvar returns undef if no value        # test against nil just in case        unless agent_key.nil? or agent_key == :undef            notice ["Agent Key Provided via Facter: #{ agent_key }"]            return agent_key        End(...) 

Extending Server Density

Page 34: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Custom function:

(...)base_url = "https://api.serverdensity.io"

filter = {  'type' => 'device',  'hostname' => hostname,}

filter_json = URI.escape(PSON.dump(filter))

uri =  URI("#{base_url}/inventory/devices?filter=#{filter_json}&token=#{token}")req = Net::HTTP::Get.new(uri.request_uri)https = Net::HTTP.new(uri.host, uri.port)https.use_ssl = trueres = https.start { |cx| cx.request(req) }(...) 

Extending Server Density

Page 35: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Custom function:

(...)device = PSON.parse(res.body)

if device['status'] == 2notice ["Device not found, creating a new one"]

uri = URI("#{ base_url }devices/add?account=#{ sd_url }")req = Net::HTTP::Post.new(uri.request_uri)req.basic_auth sd_username, sd_password

params = {  'name' => server_name,  'hostName' => hostname,  'notes' => 'Created automatically by puppet­serverdensity',}(...) 

Extending Server Density

Page 36: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Server Density v2:

Next: Publishing to the Forge

Extending Server Density

https://forge.puppetlabs.com/serverdensity/serverdensity_agent

Page 37: Puppet Camp Berlin 2015: Pedro Pessoa | Puppet at the center of everything - with a little help from the Forge

Pedro Pessoa

[email protected]

serverdensity.com/knockknockblog.serverdensity.com