spec_helper.rb.sudo-example 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. require 'rubygems'
  2. require 'bundler/setup'
  3. require 'highline/import'
  4. require 'serverspec'
  5. require 'pathname'
  6. require 'net/ssh'
  7. require 'yaml'
  8. include Serverspec::Helper::Ssh
  9. include Serverspec::Helper::RedHat
  10. include Serverspec::Helper::Properties
  11. properties = YAML.load_file('properties.yml')
  12. # Point this to the right file for the environment you
  13. # want to test
  14. $environment = YAML.load_file('environment.yml') # Changeme
  15. sudo_password = ask("Enter sudo password: ") { |q| q.echo = false }
  16. password = ask("Enter login password: ") { |q| q.echo = false } #Option: comment out this line and the one below if you have SSH key access to the server and don't need a password.
  17. RSpec.configure do |c|
  18. #c.filter_run_excluding :slow => true #Option: uncomment to exclude the slow yum package tests
  19. c.sudo_password = sudo_password
  20. c.host = ENV['TARGET_HOST']
  21. set_property properties[c.host]
  22. options = Net::SSH::Config.for(c.host)
  23. options[:password] = password #Option: comment out this line if you have SSH key access to the server and don't need a password.
  24. user = "sudo user" # Changeme
  25. c.ssh = Net::SSH.start(c.host, user, options)
  26. c.os = backend.check_os
  27. end