So, I woke up on a Sunday morning wanting to play with [ChefSpec] (https://docs.chef.io/chefspec.html) (it's been on my 'to-play-with' list for a while now..), so what better time to play with this than a nice, sunny Sunday morning in Crete.
I started looking into the [examples] (https://github.com/sethvargo/chefspec/tree/master/examples) in order to see how to write some tests. I soon realized an easy addition would be to use Fauxhai to mock the different platforms -- to my disappointment OpenSUSE 13.2 (our current target platform) was not in the list.
Now, at this point, I do realize I could have just said 'oh, well' and moved on with something else.. But you have to understand, I'm sitting in the sun, the birds are singing (really), and it's an overall wonderful day... what choice did I have but to want to contribute to the community!?
According to the [Contributing instructions] (https://github.com/customink/fauxhai/blob/master/CONTRIBUTING.md), I should start a machine and just install ohai and fauxhai and then run 'sudo fauxhai > /tmp/fauxhai.json' .. GREAT!! Now, where is Fauxhai?? How do I install it?
I spinned up an EC2 instance using AMI "ami-3a6cc64d" and lo and behold my troubles:
ip-172-31-9-201:~ # gem install ohai
-bash: gem: command not found
ip-172-31-9-201:~ # zypper in ruby
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following 7 NEW packages are going to be installed:
fdupes libruby2_1-2_1 ruby ruby2.1 ruby2.1-rubygem-gem2rpm ruby2.1-stdlib ruby-common
7 new packages to install.
Overall download size: 3.4 MiB. Already cached: 0 B After the operation, additional 14.5 MiB will be used.
Continue? [y/n/? shows all options] (y): y
(......)
great, with ruby installed, let's install ohai:
ip-172-31-9-201:~ # gem install ohai
ERROR: Could not find a valid gem 'ohai' (>= 0), here is why:
Unable to download data from https://rubygems.org - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://api.rubygems.org/latest_specs.4.8.gz)
...maybe not... No gem install would work!!
I didn't really care enough to find a permanent solution for SSL certs and ruby ... I just want to get the fauxhai output and send this VM back to oblivion. So, let's try to ignore SSL, without using HTTPS:
ip-172-31-9-201:~ # gem install ohai --source http://rubygems.org
Fetching: mime-types-2.5.gem (100%)
Successfully installed mime-types-2.5
Fetching: systemu-2.6.5.gem (100%)
Successfully installed systemu-2.6.5
Fetching: libyajl2-1.2.0.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing ohai:
ERROR: Failed to build gem native extension.
/usr/bin/ruby.ruby2.1 extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib64/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /usr/lib64/ruby/gems/2.1.0/gems/libyajl2-1.2.0 for inspection.
Results logged to /usr/lib64/ruby/gems/2.1.0/extensions/x86_64-linux/2.1.0/libyajl2-1.2.0/gem_make.out
Now, this took quite a bit of googling, but I came across this post (http://iamadevops.tumblr.com/post/104321734369/gem-install-libyajl2-failure-in-vagrant ) that told me I'm missing build tools in general, so:
ip-172-31-9-201:~ # zypper in gcc make
after this, i was able to get the gem install to work, however I was getting the following error:
ip-172-31-9-201:~ # fauxhai > /tmp/fauxhai.json
-bash: fauxhai: command not found
ip-172-31-9-201:~ # fauxhai.ruby2.1
/usr/lib64/ruby/gems/2.1.0/gems/fauxhai-2.3.0/lib/fauxhai/runner.rb:39:in `chef_packages': undefined method `[]' for nil:NilClass (NoMethodError)
from /usr/lib64/ruby/gems/2.1.0/gems/fauxhai-2.3.0/lib/fauxhai/runner.rb:11:in `initialize'
from /usr/lib64/ruby/gems/2.1.0/gems/fauxhai-2.3.0/bin/fauxhai:23:in `new'
from /usr/lib64/ruby/gems/2.1.0/gems/fauxhai-2.3.0/bin/fauxhai:23:in `<top (required)>'
from /usr/bin/fauxhai.ruby2.1:23:in `load'
from /usr/bin/fauxhai.ruby2.1:23:in `<main>'
At this point, I was probably only missing the chef gems, BUT I did not know that yet... so I rolled back and tried the other approach for installing ohai and fauxhai, by fixing the SSL issue :
ip-172-31-9-201:~ # gem uninstall ohai
You have requested to uninstall the gem:
ohai-8.2.0
fauxhai-2.3.0 depends on ohai (>= 0)
If you remove this gem, these dependencies will not be met.
Continue with Uninstall? [yN] y
Remove executables:
ohai
in addition to the gem? [Yn] Y
Removing ohai
Successfully uninstalled ohai-8.2.0
ip-172-31-9-201:~ # gem uninstall fauxhai
Remove executables:
fauxhai
in addition to the gem? [Yn] Y
Removing fauxhai
Successfully uninstalled fauxhai-2.3.0
I very quickly found this incredibly helpful guide (https://gist.github.com/luislavena/f064211759ee0f806c88) that both explains the issue and offers two ways to try to fix it. The manual way did not work for me, so I followed the newer one (https://gist.github.com/luislavena/f064211759ee0f806c88#installing-using-update-packages-new): I downloaded the gem with the update and..
ip-172-31-9-201:~ # gem install --local rubygems-update-2.2.3.gem
Successfully installed rubygems-update-2.2.3
Parsing documentation for rubygems-update-2.2.3
Done installing documentation for rubygems-update after 0 seconds
1 gem installed
ip-172-31-9-201:~ # update_rubygems.ruby2.1 --no-ri --no-rdoc
RubyGems 2.2.3 installed
=== 2.2.2 / 2014-02-05
Bug fixes:
* Fixed ruby tests when BASERUBY is not set. Patch for #778 by Nobuyoshi
Nakada.
* Removed double requests in RemoteFetcher#cache_update_path to improve remote
install speed. Pull request #772 by Charlie Somerville.
* The mkmf.log is now placed next to gem_make.out when building extensions.
* `gem install -g --local` no longer accesses the network. Bug #776 by Jeremy
Evans.
* RubyGems now correctly handles URL passwords with encoded characters. Pull
request #781 by Brian Fletcher.
* RubyGems now correctly escapes URL characters. Pull request #788 by Brian
Fletcher.
* RubyGems can now unpack tar files where the type flag is not given. Pull
request #790 by Cody Russell.
* Typo corrections. Pull request ruby/ruby#506 by windwiny.
* RubyGems now uses both the default certificates and ssl_ca_cert instead of
one or the other. Pull request #795 by zebardy.
* RubyGems can now use the bundler API against hosted gem servers in a
directory. Pull request #801 by Brian Fletcher.
* RubyGems bin stubs now ignore non-versions. This allows RubyGems bin stubs
to list file names like "_foo_". Issue #799 by Postmodern.
* Restored behavior of Gem::Version::new when subclassed. Issue #805 by
Sergio Rubio.
------------------------------------------------------------------------------
RubyGems installed the following executables:
/usr/bin/gem.ruby2.1
then i ran an update on the system, just to be sure:
ip-172-31-9-201:~ # gem update --system
(output too long)
then, I could finally install ohai and fauxhai!!!
ip-172-31-9-201:~ # gem install ohai
Fetching: ohai-8.2.0.gem (100%)
Successfully installed ohai-8.2.0
Parsing documentation for ohai-8.2.0
Installing ri documentation for ohai-8.2.0
Done installing documentation for ohai after 2 seconds
1 gem installed
ip-172-31-9-201:~ # gem install fauxhai
Fetching: net-ssh-2.9.2.gem (100%)
Successfully installed net-ssh-2.9.2
Fetching: fauxhai-2.3.0.gem (100%)
Successfully installed fauxhai-2.3.0
Parsing documentation for net-ssh-2.9.2
Installing ri documentation for net-ssh-2.9.2
Parsing documentation for fauxhai-2.3.0
Installing ri documentation for fauxhai-2.3.0
Done installing documentation for net-ssh, fauxhai after 11 seconds
2 gems installed
ip-172-31-9-201:~ # fauxhai
-bash: fauxhai: command not found
BUT, I could NOT yet RUN fauxhai:
ip-172-31-9-201:~ # fauxhai.ruby2.1
/usr/lib64/ruby/gems/2.1.0/gems/fauxhai-2.3.0/lib/fauxhai/runner.rb:39:in `chef_packages': undefined method `[]' for nil:NilClass (NoMethodError)
from /usr/lib64/ruby/gems/2.1.0/gems/fauxhai-2.3.0/lib/fauxhai/runner.rb:11:in `initialize'
from /usr/lib64/ruby/gems/2.1.0/gems/fauxhai-2.3.0/bin/fauxhai:23:in `new'
from /usr/lib64/ruby/gems/2.1.0/gems/fauxhai-2.3.0/bin/fauxhai:23:in `<top (required)>'
from /usr/bin/fauxhai.ruby2.1:23:in `load'
from /usr/bin/fauxhai.ruby2.1:23:in `<main>'
At this point, I realized I was probably missing the chef gems, so:
ip-172-31-9-201:~ # gem contents chef
Unable to find gem 'chef' in default gem paths
Directories searched:
ip-172-31-9-201:~ # gem install chef
(bunch of gems successfully installed)
Done installing documentation for net-scp, specinfra, multi_json, diff-lcs, rspec-support, rspec-expectations, rspec-core, rspec-its, rspec-mocks, rspec, serverspec, builder, rspec_junit_formatter, plist, method_source, slop, coderay, pry, rack, uuidtools, hashie, chef-zero, erubis, highline, net-ssh-gateway, net-ssh-multi, mixlib-authentication, chef after 44 seconds
28 gems installed
and FINALLY!!! :
ip-172-31-9-201:~ # fauxhai.ruby2.1
(Much wanted JSON here!!)
Success, the pull request has been submitted. The world is now a better place!
I should probably be heading to the beach now..