Building On Puppet and Puppet Forge

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

description

"Building on Puppet and Puppet Forge" by Pedro Pessoa of Server Density at Puppet Camp London 2014. Find the video here: http://puppetlabs.com/community/puppet-camp

Transcript of Building On Puppet and Puppet Forge

Page 1: Building On Puppet and Puppet Forge

Building on Building on PuppetPuppet

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

Page 2: Building On Puppet and Puppet Forge
Page 3: Building On Puppet and Puppet Forge

HTTP Load Balancerfrom Pound to nginx

New version : new load balancer

nginx :- WebSockets - SPDY standard

keep : - modules pulled from our Gihub repo by thepuppet master- use of Puppet Console and Live Management to trigger transient changes

Server Density v2:

Page 4: Building On Puppet and Puppet Forge

Reinventing the wheel(don't)

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

Writing our nginx module? - add yet another one to the collection ofin-house developed modules

community reach?- whether our problem had already been solved- or a kick start where we could stand on

Page 5: Building On Puppet and Puppet Forge

Going to the Forge

Page 6: Building On Puppet and Puppet Forge

Going to the Forge

Page 7: Building On Puppet and Puppet Forge

A) get the actual code into the master

Integration

puppet module install puppetlabs/nginx(or)git submodule add https://github.com/puppetlabs/puppetlabs­nginx.git 

no parameterized classes on PE Console (2.8.x)(or)merge our site.pp (which is empty) and the console, it being an ENC and all - (how-merging-works)

B) run it on existing nodes

Page 8: Building On Puppet and Puppet Forge

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

Integration

Our solution

Page 9: Building On Puppet and Puppet Forge

nginx 'on-the-fly' update

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

Page 10: Building On Puppet and Puppet Forge

nginx 'on-the-fly' update

Page 11: Building On Puppet and Puppet Forge

nginx 'on-the-fly' update

Page 12: Building On Puppet and Puppet Forge

nginx 'on-the-fly' update

Page 13: Building On Puppet and Puppet Forge

nginx 'on-the-fly' update

Page 14: Building On Puppet and Puppet Forge

Alternatives

pick the later? Puppet Labs last update - 30th June 2011.

Puppet Labs nginx module: https://github.com/serverdensity/puppetlabs-nginx forked James Fryman's module: https://github.com/jfryman/puppet-nginx

https://github.com/serverdensity/puppetlabs-nginx

Page 15: Building On Puppet and Puppet 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 16: Building On Puppet and Puppet Forge

Server Density v1:

Extending Server Density

Page 17: Building On Puppet and Puppet 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 18: Building On Puppet and Puppet Forge

Server Density v2:

Extending Server Density

Page 19: Building On Puppet and Puppet Forge

Server Density v2 – in action:

Extending Server Density

Page 20: Building On Puppet and Puppet Forge

Server Density v2 – in action:

Extending Server Density

Page 21: Building On Puppet and Puppet 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 22: Building On Puppet and Puppet 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 23: Building On Puppet and Puppet 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 24: Building On Puppet and Puppet 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 25: Building On Puppet and Puppet 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 26: Building On Puppet and Puppet Forge

Server Density v2:

Next: Publishing to the Forge

Extending Server Density

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

Page 27: Building On Puppet and Puppet Forge

Pedro Pessoa

[email protected]

http://serverdensity.com/puppetcamp/