Building On Puppet and Puppet Forge

Download Building On Puppet and Puppet Forge

Post on 28-Nov-2014

1.390 views

Category:

Technology

2 download

Embed Size (px)

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

<ul><li> 1. Building on Puppet http://www.rankpop.com/you-need-to-start-structuring-your-blog-posts-asap/ </li> <li> 2. HTTP Load Balancer from Pound to nginx Server Density v2: New version : new load balancer nginx : - WebSockets - SPDY standard keep : - modules pulled from our Gihub repo by the puppet master - use of Puppet Console and Live Management to trigger transient changes </li> <li> 3. Reinventing the wheel (don't) Writing our nginx module? - add yet another one to the collection of in-house developed modules community reach? - whether our problem had already been solved - or a kick start where we could stand on http://www.flickr.com/photos/conskeptical/ </li> <li> 4. Going to the Forge </li> <li> 5. Going to the Forge </li> <li> 6. Integration A) get the actual code into the master puppetmoduleinstallpuppetlabs/nginx (or) gitsubmoduleaddhttps://github.com/puppetlabs/puppetlabsnginx.git B) run it on existing nodes 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) </li> <li> 7. Integration Our solution classserverdensitynginx { class{'nginx':} nginx::resource::upstream{ 'socky_rack': ensure=&gt;present, members=&gt;split($lbTargetHostsSocky,','), } (...) </li> <li> 8. nginx 'on-the-fly' update classserverdensitynginx { class{'nginx':} nginx::resource::upstream{ 'socky_rack': ensure=&gt;present, members=&gt;split($lbTargetHostsSocky,','), } (...) </li> <li> 9. nginx 'on-the-fly' update </li> <li> 10. nginx 'on-the-fly' update </li> <li> 11. nginx 'on-the-fly' update </li> <li> 12. nginx 'on-the-fly' update </li> <li> 13. Alternatives Puppet Labs nginx module: https://github.com/serverdensity/puppetlabs-nginx forked James Fryman's module: https://github.com/jfryman/puppet-nginx pick the later? Puppet Labs last update - 30th June 2011. https://github.com/serverdensity/puppetlabs-nginx </li> <li> 14. Extending Server Density Server Density collects server data from an open source agent deployed on each device Create a device on Server Density UI Copy the device ID (agent key) The agent reads the device ID from a config file: [Main] sd_url:http://mydomain.serverdensity.com agent_key:8160b409de9d8a612ec8d964c5b26bf (...) </li> <li> 15. Extending Server Density Server Density v1: </li> <li> 16. Extending Server Density Server Density v1: 'sdagent': ensure=&gt;installed, file { 'config.cfg': path=&gt;'/etc/sdagent/config.cfg', ensure=&gt;file, require=&gt;Package['sdagent'], content=&gt;template('sdagent/config.erb'), } [Main] sd_url:http://boxedice.serverdensity.com agent_key: (...) </li> <li> 17. Extending Server Density Server Density v2: </li> <li> 18. Extending Server Density Server Density v2 in action: </li> <li> 19. Extending Server Density Server Density v2 in action: </li> <li> 20. Extending Server Density Server Density v2 - implementation: Manages the life cycle of Rackspace and Amazon cloud instances A custom fact will return the cloud instance agent key or use Server Density API to create a device on the fly and return the resulting agent key https://github.com/serverdensity/puppet-serverdensity </li> <li> 21. Extending Server Density Custom fact: Facter.add(:agent_key,:timeout=&gt;10)do ifFile::exist?('/etc/sdagentkey') result=Facter::Util::Resolution.exec("cat/etc/sdagentkey") elsifFacter.value('ec2_instance_id') uri=URI("http://ec2meta.serverdensity.com/latest/userdata") req=Net::HTTP::Get.new(uri.request_uri) res=Net::HTTP.start(uri.host,uri.port){|http| http.request(req) } result=res.body.split(':').lastifres.code==200 end setcode{result} end </li> <li> 22. Extending Server Density Custom function: (...) agent_key=lookupvar("agent_key") #lookupvarreturnsundefifnovalue #testagainstniljustincase unlessagent_key.nil?oragent_key==:undef notice["AgentKeyProvidedviaFacter:#{agent_key}"] returnagent_key End (...) </li> <li> 23. Extending Server Density Custom function: (...) base_url="https://api.serverdensity.io" filter={ 'type'=&gt;'device', 'hostname'=&gt;hostname, } filter_json=URI.escape(PSON.dump(filter)) uri= URI("#{base_url}/inventory/devices?filter=#{filter_json}&amp;token=#{token}") req=Net::HTTP::Get.new(uri.request_uri) https=Net::HTTP.new(uri.host,uri.port) https.use_ssl=true res=https.start{|cx|cx.request(req)} (...) </li> <li> 24. Extending Server Density Custom function: (...) device=PSON.parse(res.body) ifdevice['status']==2 notice["Devicenotfound,creatinganewone"] uri=URI("#{base_url}devices/add?account=#{sd_url}") req=Net::HTTP::Post.new(uri.request_uri) req.basic_authsd_username,sd_password params={ 'name'=&gt;server_name, 'hostName'=&gt;hostname, 'notes'=&gt;'Createdautomaticallybypuppetserverdensity', } (...) </li> <li> 25. Extending Server Density Server Density v2: Next: Publishing to the Forge https://github.com/serverdensity/puppet-serverdensity </li> <li> 26. Pedro Pessoa pessoa@serverdensity.com http://serverdensity.com/puppetcamp/ </li> </ul>