neillturner / kitchen-verifier-serverspec

A Test Kitchen Serverspec Verifer without having to transit the Busser layer
Other
39 stars 19 forks source link

CentOS 6.x failure #31

Open pmyjavec opened 6 years ago

pmyjavec commented 6 years ago

When testing against CentOS 6 hosts, it seems the rubygems package is not installed which then causes the "verify" step to fail.

To resolve the issue I just logged into the box manually and installed rubygems

See the output:

>>>>>> ------Exception-------                                                        
>>>>>> Class: Kitchen::ActionFailed                                                  
>>>>>> Message: 1 actions failed.                                                    
>>>>>>     Failed to complete #verify action: [SSH exited (1) for command: [                                                                                               
            if [ ! $(which ruby) ]; then                                             
              echo '-----> Installing ruby, will try to determine platform os'       
              if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then                                                              
                sudo -E -H yum -y install ruby                                       
              else                                                                   
                if [ -f /etc/system-release ] && grep -q 'Amazon Linux' /etc/system-release; then                                                                          
                  sudo -E -H yum -y install ruby                                     
                else                                                                 
                  sudo -E -H apt-get -y install ruby                                 
                fi                                                                   
              fi                                                                     
            fi                                                                       
                        if [ "$(sudo -E -H gem list bundler -i)" = "true" ]; then    
              echo "Bundler already installed"                                       
            else                                                                     
              if [ "$(sudo -E -H gem list bundler -i)" = "false" ]; then             
                sudo -E -H gem install  --no-ri --no-rdoc bundler                    
              else                                                                   
                echo "ERROR: Ruby not installed correctly"                           
                exit 1                                                               
              fi                                                                     
            fi                                                                       

            if [ -d /tmp/kitchen ]; then                                             
                            if [ "$(sudo -E -H gem list serverspec -i)" = "false" ]; then                                                                                  
                        sudo -E -H rm -f /tmp/kitchen/Gemfile                        
          sudo -E -H echo "source 'https://rubygems.org'" >> /tmp/kitchen/Gemfile    
          sudo -E -H echo "gem 'net-ssh','~> 2.9'"  >> /tmp/kitchen/Gemfile          
          sudo -E -H echo "gem 'serverspec'" >> /tmp/kitchen/Gemfile                 

              BUNDLE_CMD=$(which bundle)                                             
              echo "---> BUNDLE_CMD variable is: ${BUNDLE_CMD}"                      
              sudo -E -H  $BUNDLE_CMD install --gemfile=/tmp/kitchen/Gemfile         
            fi                                                                       

            else                                                                     
              echo "ERROR: Default path '/tmp/kitchen' does not exist"               
              exit 1                                                                 
            fi                                                                       
]] on default-centos-6                                                               
>>>>>> ----------------------                                                        
>>>>>> Please see .kitchen/logs/kitchen.log for more details                         
>>>>>> Also try running `kitchen diagnose --all` for configuration                   
---
# kitchen.yml
driver:
  name: 'vagrant'

provisioner:
  name: 'ansible_playbook'
  hosts: "localhost"
  require_ansible_repo: false
  require_ansible_omnibus: false
  require_ansible_source: false
  require_pip: true
  ansible_version: 'latest'
  ansible_verbose: true
  require_chef_for_busser: false
  require_ruby_for_busser: false
  ignore_paths_from_root: [".git",".idea",".kitchen", ".bin", ".kitchen.yml", ".gems", ".bundle"]

verifier:
  name: 'serverspec'
  default_pattern: true

platforms:
  - name: 'ubuntu-16.04'
  - name: 'centos-7'
  - name: 'centos-6'

suites:
  - name: 'default'
    attributes:
    run_list:
tolland commented 6 years ago

Yeah, it seems that on CentOS 7 the ruby package depends on rubygems, so installing ruby also installs rubygems, however that's not true in CentOS 6...

# cat /etc/system-release
CentOS Linux release 7.4.1708 (Core)

$ rpm -q --requires ruby | grep rubygems
ruby(rubygems) >= 2.0.14.1

so installing ruby will pull in the gems package...

              if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then                                                              
                sudo -E -H yum -y install ruby   

However on CentOS 6, this is not the case, and ruby doesn't depend on rubygems;

# rpm -qR ruby
/usr/bin/ruby
libc.so.6()(64bit)
libc.so.6(GLIBC_2.2.5)(64bit)
libcrypt.so.1()(64bit)
libdl.so.2()(64bit)
libm.so.6()(64bit)
libpthread.so.0()(64bit)
librt.so.1()(64bit)
libruby.so.1.8()(64bit)
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rtld(GNU_HASH)
ruby-libs = 1.8.7.374-5.el6
rpmlib(PayloadIsXz) <= 5.2-1

# cat /etc/system-release
CentOS release 6.9 (Final)

so installing it doesn't get gems in the path. So the script jumps to trying to trying to install bundler with gem and fails;

if [ "$(sudo -E -H gem list bundler -i)" = "true" ]; then

tolland commented 6 years ago

This fixes it for CentOS, and I've tested it against CentOS7, and fedora-27

diff --git a/lib/kitchen/verifier/serverspec.rb b/lib/kitchen/verifier/serverspec.rb
index 4304d58..0932e73 100644
--- a/lib/kitchen/verifier/serverspec.rb
+++ b/lib/kitchen/verifier/serverspec.rb
@@ -134,7 +134,7 @@ module Kitchen
             if [ ! $(which ruby) ]; then
               echo '-----> Installing ruby, will try to determine platform os'
               if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
-                #{sudo_env('yum')} -y install ruby
+                #{sudo_env('yum')} -y install ruby rubygems
               else
                 if [ -f /etc/system-release ] && grep -q 'Amazon Linux' /etc/system-release; then
                   #{sudo_env('yum')} -y install ruby