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

Automating infrastructure with ruby - Tiago Macedo

Automating infrastructure with ruby - Tiago Macedo

Slide deck used by Tiago Macedo on Coimbra.rb (organized by http://whitesmith.co )

Daniel Lopes

October 11, 2013
Tweet

More Decks by Daniel Lopes

Other Decks in Programming

Transcript

  1. • Repeatability • Automation • Agility • Scalability • Reassurance

    • Disaster Recovery Infrastructure as Code Test-Driven Infrastructure with Chef By Stephen Nelson-Smith
  2. Chef ruby_block "add users to passwords file" do block do

    require 'webrick/httpauth/htpasswd' passwd = WEBrick::HTTPAuth::Htpasswd.new(nginx[:pass_file]) nginx[:users].each do |u| passwd.set_passwd( 'Auth', u['username'], u['password'] ) end passwd.flush end end
  3. Chef name "varnish" description "Varnish caching proxy for Solr" run_list

    'varnish' default_attributes( :varnish => { :malloc => '3G', :backend => { :nodes => Configuration::Server.all.select { |s| s.solr_slave? && s.production? }.map{|s| s.name}, :port => 30002 } } )
  4. Chef { "run_list" : [ "role[staging_server]" ], "database_config" : {

    "staging" : { "database" : "staging", "adapter" : "mysql2", "reconnect" : "true", "host" : "localhost", "username" : "staging", "encoding" : "utf8" } } }
  5. Chef server "lisbon", :staging_server do natted! attributes( :database_config => {

    :staging => { :adapter => "mysql2", :database => "staging", :encoding => "utf8", :reconnect => "true", :username => "staging", :host => "localhost" } } ) end
  6. Chef package 'haproxy' template '/etc/haproxy/haproxy.cfg' do variables :port => 80

    owner 'haproxy' end service 'haproxy' do action [:start] end
  7. Chef package 'nginx' template '/etc/nginx/nginx.cfg' do variables :port => 80

    owner 'nginx' end service 'nginx' do action [:start] end
  8. fog

  9. Load Balancers elb = Fog::AWS::ELB.new(credentials) listener = {'Protocol' => 'HTTP',

    'LoadBalancerPort' => 80, 'InstancePort' => 80, 'InstanceProtocol' => 'HTTP'} elb.create_load_balancer('us-east-1a', 'my-elb',[listener]) ids = Fog::Compute.new(credentials).servers.map {|s| s.id} elb.register_instances_with_load_balancer(ids, 'my-elb')