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

Floripa on Rails - ServerSpec

Floripa on Rails - ServerSpec

I and Lucas Alencar, have Co-Authored a lighting talk about ServerSpec, presented on Floripa on Rails:
http://www.meetup.com/Floripa-on-Rails/events/223349050/

Gabriel Mazetto

July 07, 2015
Tweet

More Decks by Gabriel Mazetto

Other Decks in Programming

Transcript

  1. $ gem install serverspec
 
 Fetching: specinfra-2.36.14.gem (100%)
 Fetching: rspec-its-1.2.0.gem

    (100%)
 Fetching: serverspec-2.19.0.gem (100%)
 ... $ serverspec-init
 
 Select OS type:
 1) UN*X
 2) Windows
 Select number: 1
 
 Select a backend type:
 1) SSH
 2) Exec (local)
 ...
  2. Suporta Testar Diversos OS:
 ➔ Fedora/Red Hat/CentOS ➔ Debian ➔

    Ubuntu ➔ Mac OS X ➔ FreeBSD / OpenBSD ➔ Solaris ➔ Suse / OpenSUSE ➔ Windows Deteção automática de OS, mas é possível especificar na mão.
  3. require 'serverspec' 
 # RedHat 7 - 64bits:
 set :os,

    :family => 'redhat', :release => '7', :arch => 'x86_64'
 
 # Debian 7 - 32bits:
 set :os, :family => 'debian', :release => '7', :arch => 'i386'
 
 # Ubuntu 14.04 LTS - 64bits:
 set :os, :family => 'ubuntu', :release => '14.04', :arch => 'x86_64' ...
  4. # describe command com matchers: its(:stdout), its(:stderr), its(:exit_status) 
 #

    Apache2 + Passenger:
 describe command('apachectl -M') do
 its(:stdout) { should contain('mod_passenger') }
 end # nginx + Passenger:
 describe command('nginx -V') do
 its(:stdout) { should contain('--with-passenger') }
 end
  5. # Vamos transformar em um shared behaviour: # Apache2 +

    Passenger:
 shared_examples 'apache2::passenger' do
 describe command('apachectl -M') do
 its(:stdout) { should contain('mod_passenger') }
 end end # nginx + Passenger: shared_examples 'nginx::passenger' do
 describe command('nginx -V') do
 its(:stdout) { should contain('--with-passenger') }
 end
 describe package('passenger') do
 it { should be_installed }
 end end
  6. # utilizando em hosts distintos: describe 'myserver.com' do
 include_examples 'apache2::passenger'

    describe package('apache2') do it { should be_installed }
 end end describe 'myotherserver.com' do include_examples 'nginx::passenger' describe package('nginx-extras') do it { should be_installed }
 end end
  7. Links Úteis ➔ ServerSpec (Documentação)
 (http://serverspec.org/resource_types.html)
 ➔ TDD Docker +

    ServerSpec
 (https://robots.thoughtbot.com/tdd-your-dockerfiles-with-rspec-and-serverspec)
 ➔ ChefSpec + Test Kichen + ServerSpec
 (https://micgo.net/serverspec-guard-and-test-kitchen-testing-servers-like-a- boss/)