Skip to content

Instantly share code, notes, and snippets.

@nicdk
Created November 7, 2018 06:21
Show Gist options
  • Save nicdk/39fb543bccffa7d168b5cbbc091a49a3 to your computer and use it in GitHub Desktop.
Save nicdk/39fb543bccffa7d168b5cbbc091a49a3 to your computer and use it in GitHub Desktop.

vagrant-box-serverspec memo

% vagrant init -m centos/7
%cat Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
end
% vagrant up
% echo 'cat /etc/redhat-release; uname -a' | vagrant ssh
/etc/profile.d/lang.sh: line 19: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
CentOS Linux release 7.5.1804 (Core)
Linux localhost.localdomain 3.10.0-862.14.4.el7.x86_64 #1 SMP Wed Sep 26 15:12:11 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

[CentOS-announce] Announcing release of Ruby 2.5 on CentOS 7 x86_64

% echo 'sudo yum install -y centos-release-scl' | vagrant ssh
% echo 'sudo yum-config-manager --enable rhel-server-rhscl-7-rpms' | vagrant ssh
% echo 'sudo yum install -y rh-ruby25' | vagrant ssh
% vagrant ssh
[vagrant]% scl enable rh-ruby25 bash
[vagrant]% ruby -v
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]

in vagrant.

% cd /vagrant/
% gem install bundler
% bundler init
% bundle add serverspec
% bundle add rake

run serverspec.

$ serverspec-init
Select OS type:

  1) UN*X
  2) Windows

Select number: 1

Select a backend type:

  1) SSH
  2) Exec (local)

Select number: 2

 + spec/
 + spec/localhost/
 + spec/localhost/sample_spec.rb
 + spec/spec_helper.rb
 + Rakefile
 + .rspec
$ rake spec
/opt/rh/rh-ruby25/root/usr/bin/ruby -I/opt/rh/rh-ruby25/root/usr/share/gems/gems/rspec-support-3.8.0/lib:/opt/rh/rh-ruby25/root/usr/share/gems/gems/rspec-core-3.8.0/lib /opt/rh/rh-ruby25/root/usr/share/gems/gems/rspec-core-3.8.0/exe/rspec --pattern spec/localhost/\*_spec.rb

Package "httpd"
  should be installed (FAILED - 1)

Service "httpd"
  should be enabled (FAILED - 2)
  should be running (FAILED - 3)

Port "80"
  should be listening (FAILED - 4)

Failures:

  1) Package "httpd" should be installed
     On host `localhost'
     Failure/Error: it { should be_installed }
       expected Package "httpd" to be installed
       /bin/sh -c rpm\ -q\ httpd
       package httpd is not installed

     # ./spec/localhost/sample_spec.rb:4:in `block (2 levels) in <top (required)>'

  2) Service "httpd" should be enabled
     On host `localhost'
     Failure/Error: it { should be_enabled }
       expected Service "httpd" to be enabled
       /bin/sh -c systemctl\ --quiet\ is-enabled\ httpd

     # ./spec/localhost/sample_spec.rb:12:in `block (2 levels) in <top (required)>'

  3) Service "httpd" should be running
     On host `localhost'
     Failure/Error: it { should be_running }
       expected Service "httpd" to be running
       /bin/sh -c systemctl\ is-active\ httpd
       unknown

     # ./spec/localhost/sample_spec.rb:13:in `block (2 levels) in <top (required)>'

  4) Port "80" should be listening
     On host `localhost'
     Failure/Error: it { should be_listening }
       expected Port "80" to be listening
       /bin/sh -c ss\ -tunl\ \|\ grep\ --\ :80\\\

     # ./spec/localhost/sample_spec.rb:27:in `block (2 levels) in <top (required)>'

Finished in 0.32835 seconds (files took 0.53353 seconds to load)
4 examples, 4 failures

Failed examples:

rspec ./spec/localhost/sample_spec.rb:4 # Package "httpd" should be installed
rspec ./spec/localhost/sample_spec.rb:12 # Service "httpd" should be enabled
rspec ./spec/localhost/sample_spec.rb:13 # Service "httpd" should be running
rspec ./spec/localhost/sample_spec.rb:27 # Port "80" should be listening

/opt/rh/rh-ruby25/root/usr/bin/ruby -I/opt/rh/rh-ruby25/root/usr/share/gems/gems/rspec-support-3.8.0/lib:/opt/rh/rh-ruby25/root/usr/share/gems/gems/rspec-core-3.8.0/lib /opt/rh/rh-ruby25/root/usr/share/gems/gems/rspec-core-3.8.0/exe/rspec --pattern spec/localhost/\*_spec.rb failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment