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

Using Ruby to Automate Your Life

Seth Vargo
October 13, 2013

Using Ruby to Automate Your Life

You probably use Ruby everyday, so why not use Ruby to automate some common tasks? What if you could spin up an EC2 instance and have it automatically configure your web server, database, users, and more? What if you could effectively capture and replicate your production environments reliably and consistently? What if you could then give developers production-like environments as Virtual Machines, with no additional work? What if you could set up your new laptop with multiple Ruby versions, your favorite software, and even change the desktop background - from a single command? The good news is - you can!

Chef is a configuration management and automation tool that solves these problems and many m you'll learn common just how easy it is to capture your infrastructure in Chef. Save time and money by using Chef's Ruby DSL to "define" your laptop.

How many times have you bought a new laptop and realize just how much stuff you installed over the years? If you're using Chef, run a single command and all your favorite Applications, Preferences, and even passwords are back in place. And the best part - because Chef is written in Ruby, you get to continue using the language you love!

Seth Vargo

October 13, 2013
Tweet

More Decks by Seth Vargo

Other Decks in Technology

Transcript

  1. REPETITIVE CAN OF SHIT cap deploy git push irb ruby

    bundle rake guard rspec vagrant time
  2. REPETITIVE CAN OF SHIT cap deploy git push tail /var/log

    ssh irb ruby ls bundle test rake heroku guard export rspec brew thor curl vagrant nano cut time
  3. REPETITIVE CAN OF SHIT cap deploy apt-get install git clone

    git push cd directory tail /var/log top ssh irb ruby alias ls grep bundle test rake heroku gunzip guard head ping export cp rspec brew open thor telnet man chmod curl port vagrant chown vi packer nano cut find time hash COMMAND ALL THE THINGS!
  4. REPETITIVE CAN OF SHIT cap deploy apt-get install git clone

    git push cd directory tail /var/log top ssh irb ruby alias ls grep bundle test rake heroku gunzip guard head ping export cp rspec brew open thor telnet man chmod curl port vagrant chown vi packer nano cut find time hash COMMAND ALL THE THINGS!
  5. ?

  6. EVEN THOUGH I WORK FOR OPSCODE, THIS IS NOT A

    VENDOR PITCH. THE CHEF CLIENT IS COMPLETELY FREE AND OPEN SOURCED UNDER THE APACHE 2.0 LICENSE. DISCLAIMER #1
  7. deploy_to = '/var/www/myface' directories = [ 'releases', 'shared', 'shared/log', 'shared/pids',

    'shared/system', ] # Create each directory directories.each do |path| directory "#{deploy_to}/#{path}" end
  8. timestamp = Time.now.to_i git "#{deploy_to}/#{timestamp}" do repository 'git://github.com/user/repo.git reference 'master'

    depth 1 action :checkout end link "#{deploy_to}/current" do to "#{deploy_to}/#{timestamp}" end file "#{deploy_to}/current/tmp/restart.txt" do action :touch end
  9. timestamp = Time.now.to_i git "#{deploy_to}/#{timestamp}" do repository 'git://github.com/user/repo.git reference 'master'

    depth 1 action :checkout end link "#{deploy_to}/current" do to "#{deploy_to}/#{timestamp}" end file "#{deploy_to}/current/tmp/restart.txt" do action :touch end
  10. timestamp = Time.now.to_i git "#{deploy_to}/#{timestamp}" do repository 'git://github.com/user/repo.git reference 'master'

    depth 1 action :checkout end link "#{deploy_to}/current" do to "#{deploy_to}/#{timestamp}" end file "#{deploy_to}/current/tmp/restart.txt" do action :touch end
  11. timestamp = Time.now.to_i git "#{deploy_to}/#{timestamp}" do repository 'git://github.com/user/repo.git reference 'master'

    depth 1 action :checkout end link "#{deploy_to}/current" do to "#{deploy_to}/#{timestamp}" end file "#{deploy_to}/current/tmp/restart.txt" do action :touch end
  12. timestamp = Time.now.to_i git "#{deploy_to}/#{timestamp}" do repository 'git://github.com/user/repo.git reference 'master'

    depth 1 action :checkout end link "#{deploy_to}/current" do to "#{deploy_to}/#{timestamp}" end file "#{deploy_to}/current/tmp/restart.txt" do action :touch end
  13. timestamp = Time.now.to_i git "#{deploy_to}/#{timestamp}" do repository 'git://github.com/user/repo.git reference 'master'

    depth 1 action :checkout end link "#{deploy_to}/current" do to "#{deploy_to}/#{timestamp}" end file "#{deploy_to}/current/tmp/restart.txt" do action :touch end
  14. timestamp = Time.now.to_i git "#{deploy_to}/#{timestamp}" do repository 'git://github.com/user/repo.git reference 'master'

    depth 1 action :checkout end link "#{deploy_to}/current" do to "#{deploy_to}/#{timestamp}" end file "#{deploy_to}/current/tmp/restart.txt" do action :touch end
  15. timestamp = Time.now.to_i git "#{deploy_to}/#{timestamp}" do repository 'git://github.com/user/repo.git reference 'master'

    depth 1 action :checkout end link "#{deploy_to}/current" do to "#{deploy_to}/#{timestamp}" end file "#{deploy_to}/current/tmp/restart.txt" do action :touch end
  16. timestamp = Time.now.to_i git "#{deploy_to}/#{timestamp}" do repository 'git://github.com/user/repo.git reference 'master'

    depth 1 action :checkout end link "#{deploy_to}/current" do to "#{deploy_to}/#{timestamp}" end file "#{deploy_to}/current/tmp/restart.txt" do action :touch end
  17. timestamp = Time.now.to_i git "#{deploy_to}/#{timestamp}" do repository 'git://github.com/user/repo.git reference 'master'

    depth 1 action :checkout end link "#{deploy_to}/current" do to "#{deploy_to}/#{timestamp}" end file "#{deploy_to}/current/tmp/restart.txt" do action :touch end
  18. timestamp = Time.now.to_i git "#{deploy_to}/#{timestamp}" do repository 'git://github.com/user/repo.git reference 'master'

    depth 1 action :checkout end link "#{deploy_to}/current" do to "#{deploy_to}/#{timestamp}" end file "#{deploy_to}/current/tmp/restart.txt" do action :touch end
  19. New Laptop redis vagrant mongodb sqlite postgresql rbenv mysql imagemagick

    git graphviz gecode ruby-build Google Chrome Firefox VirtualBox
  20. New Laptop DRAG CHROME INTO THE APPLICATIONS DIRECTORY GOOGLE CHOME

    AND THE CHROME LOGO COPYRIGHT GOOGLE, INC.
  21. New Laptop dmg_package 'Virtual Box' do dmg_name 'virtualbox' source 'http://download.virtualbox.org/...'

    end dmg_package 'Vagrant' do dmg_name 'vagrant' source 'http://files.vagrantup.com/...' end VIRTUALBOX & VAGRANT
  22. New Laptop %w[ gecode git graphviz imagemagick mongodb mysql postgresql

    rbenv redis ruby-build sqlite ].each do |name| homebrew_package name end PACKAGES? NO PROBLEM!
  23. New Laptop %w[ gecode git graphviz imagemagick mongodb mysql postgresql

    rbenv redis ruby-build sqlite ].each do |name| homebrew_package name end WANT SOME RUBIES? rbenv ruby-build
  24. New Laptop %w[ 1.8.7-p371 1.9.3-p448 2.0.0-p247 ].each do |version| execute

    "rbenv install #{version}" do not_if "rbenv versions | grep #{version}" end end INSTALL SOME RUBIES
  25. New Laptop %w[ 1.8.7-p371 1.9.3-p448 2.0.0-p247 ].each do |version| execute

    "rbenv install #{version}" do not_if "rbenv versions | grep #{version}" end end IDEMPOTENCY not_if "rbenv versions | grep #{version}"
  26. New Laptop def set_background(file) """ tell application "Finder" set desktop

    picture to POSIX file "#{file}" end tell killall Dock """ end SET THE DESKTOP BACKGROUND
  27. New Laptop def set_background(file) """ tell application "Finder" set desktop

    picture to POSIX file "#{file}" end tell killall Dock """ end SET THE DESKTOP BACKGROUND ?
  28. New Laptop image = '/Library/Cache/my_background.png' remote_file image do source 'http://imgur.com/a/5hbCH'

    action :create_if_missing notifies :run, 'execute[set desktop background]' end execute 'set desktop background' do command "oascript #{set_background(image)}" action :nothing end SET THE DESKTOP BACKGROUND
  29. New Laptop image = '/Library/Cache/my_background.png' remote_file image do source 'http://imgur.com/a/5hbCH'

    action :create_if_missing notifies :run, 'execute[set desktop background]' end execute 'set desktop background' do command "oascript #{set_background(image)}" action :nothing end SET THE DESKTOP BACKGROUND image = '/Library/Cache/my_background.png'
  30. New Laptop image = '/Library/Cache/my_background.png' remote_file image do source 'http://imgur.com/a/5hbCH'

    action :create_if_missing notifies :run, 'execute[set desktop background]' end execute 'set desktop background' do command "oascript #{set_background(image)}" action :nothing end SET THE DESKTOP BACKGROUND remote_file image do
  31. New Laptop image = '/Library/Cache/my_background.png' remote_file image do source 'http://imgur.com/a/5hbCH'

    action :create_if_missing notifies :run, 'execute[set desktop background]' end execute 'set desktop background' do command "oascript #{set_background(image)}" action :nothing end SET THE DESKTOP BACKGROUND source 'http://imgur.com/a/5hbCH'
  32. New Laptop image = '/Library/Cache/my_background.png' remote_file image do source 'http://imgur.com/a/5hbCH'

    action :create_if_missing notifies :run, 'execute[set desktop background]' end execute 'set desktop background' do command "oascript #{set_background(image)}" action :nothing end SET THE DESKTOP BACKGROUND action :create_if_missing
  33. New Laptop image = '/Library/Cache/my_background.png' remote_file image do source 'http://imgur.com/a/5hbCH'

    action :create_if_missing notifies :run, 'execute[set desktop background]' end execute 'set desktop background' do command "oascript #{set_background(image)}" action :nothing end SET THE DESKTOP BACKGROUND notifies :run, 'execute[set desktop background]'
  34. New Laptop image = '/Library/Cache/my_background.png' remote_file image do source 'http://imgur.com/a/5hbCH'

    action :create_if_missing notifies :run, 'execute[set desktop background]' end execute 'set desktop background' do command "oascript #{set_background(image)}" action :nothing end SET THE DESKTOP BACKGROUND execute 'set desktop background' do
  35. New Laptop image = '/Library/Cache/my_background.png' remote_file image do source 'http://imgur.com/a/5hbCH'

    action :create_if_missing notifies :run, 'execute[set desktop background]' end execute 'set desktop background' do command "oascript #{set_background(image)}" action :nothing end SET THE DESKTOP BACKGROUND command "oascript #{set_background(image)}"
  36. INSTALLED Google Chrome Firefox CONFIGURED Virtual Box Vagrant MongoDB PostgreSQL

    Rbenv Gecode Graphviz 3 Rubies Desktop Background lines of code
  37. INSTALLED Google Chrome Firefox CONFIGURED Virtual Box Vagrant MongoDB PostgreSQL

    Rbenv Gecode Graphviz 3 Rubies Desktop Background < 150 lines of code