Using Test Kitchen with Docker and serverspec to test Ansible roles

ansible_logo_black_square

Lets write some tests for our Ansible roles. When we are testing our roles, we can validate the quality of the role. With this blog item we are using the test kitchen framework and serverspec for the Ansible role: dj-wasabi.zabbix-agent.

With test kitchen we can start an vagrant box or an docker image and our Ansible role will be executed on this instance. There is an whole list of Test Kitchen drivers which can be found here. (If you have an more recent up2date list, please let me know and I update the link). When the Ansible role is installed, serverspec will be executed so we can verify if the installation and configuration is done correctly. Ideally you want to execute this every time when an change is done for the Role, so the best way is to do everything with Jenkins.

We will make use of the following tools:

  • Test Kitchen
  • docker
  • Serverspec

Installation of Jenkins is out of scope for this blog item, same as installation of docker. You’ll need to check these websites for installing Jenkins and  docker on your machine.

Before we even continue, we need to install test kitchen. We do this with the following command:

wdijkerman@curiosity [ ~/git/ansible/ansible-zabbix-agent ] (13:02:01 - Thu Aug 20)
 (master) > gem install test-kitchen

This is easy, it only take around 10 seconds to install. We continue with the test kitchen setup by executing the next command:

wdijkerman@curiosity [ ~/git/ansible/ansible-zabbix-agent ] (13:03:05 - Thu Aug 20)
 (master) > kitchen init --create-gemfile --driver=kitchen-docker
      create  .kitchen.yml
      create  chefignore
      create  test/integration/default
      create  .gitignore
      append  .gitignore
      append  .gitignore
      create  Gemfile
      append  Gemfile
      append  Gemfile
You must run `bundle install' to fetch any new gems.

The command creates some files and directories at default which we almost all will be using. We remove the chefignore file, as we don’t use chef in this case.

We update the Gemfile by adding the next line at the end of the file:

gem "kitchen-ansible"

Now we run the “bundle install” command, it will install the kitchen-docker and kitchen-ansible gems with their dependencies.

wdijkerman@curiosity [ ~/git/ansible/ansible-zabbix-agent ] (13:03:55 - Thu Aug 20)
 (master) > bundle install
Using multipart-post 2.0.0
Using faraday 0.9.1
Using highline 1.7.3
Using thor 0.19.1
Using librarian 0.1.2
Using librarian-ansible 1.0.6
Using mixlib-shellout 2.1.0
Using net-ssh 2.9.2
Using net-scp 1.2.1
Using safe_yaml 1.0.4
Using test-kitchen 1.4.2
Using kitchen-ansible 0.0.23
Using kitchen-docker 2.3.0
Using bundler 1.6.2
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
wdijkerman@curiosity [ ~/git/ansible/ansible-zabbix-agent ] (13:03:59 - Thu Aug 20)
 (master) > 

We can also set some version restrictions in this file, an example looks like this:

gem 'test-kitchen', '>= 1.4.0'
gem 'kitchen-docker', '>= 2.3.0'
gem 'kitchen-ansible'

With the above example, you’ll install test-kitchen with version 1.4.0 or higher and version 2.3.0 or higher for kitchen-docker. But for now, we use it without the versions.

We have an basic .kitchen.yml file, like this:

---
driver:
  name: docker

provisioner:
  name: chef_solo

platforms:
  - name: ubuntu-14.04
  - name: centos-7.1

suites:
  - name: default
    run_list:
    attributes:

We are changing the file, so it will look like this:

---
driver:
  name: docker
  provision_command: sed -i '/tsflags=nodocs/d' /etc/yum.conf

provisioner:
  name: ansible_playbook
#  ansible_yum_repo: "http://mirror.logol.ru/epel/6/x86_64/epel-release-6-8.noarch.rpm"
  hosts: localhost
#  requirements_path: requirements.yml

platforms:
  - name: centos-6.6

verifier:
  ruby_bindir: '/usr/bin'

suites:
  - name: default

What does it do:

We use the docker driver to run our playbook and tests. It will start an docker image and executes the playbook and after this, we execute serverspec tests to validate of everything should work as expected.

We use the “ansible_playbook” as provisioner. I have 2 lines commented in this .kitchen.yml file. My Ansible role doesn’t have any dependencies. With the “ansible_yum_repo” we can point it to for example the epel-release.rpm file. When the docker image is started, it will download and install this epel repository file so if the role needs some packages from Epel, it will succeed. Same as for the “requirements_path”. This is an yml file which can be used for downloading the role dependencies.

The Zabbix Agent role doesn’t have any dependencies, but for the Zabbix Server role, it has 3 dependencies. You could use it like this:

wdijkerman@curiosity [ ~/git/ansible/ansible-zabbix-agent ] (13:07:22 - Thu Aug 20)
 (master) > cat requirements.yml
---
- src: geerlingguy.apache
- src: geerlingguy.mysql
- src: galaxyprojectdotorg.postgresql

There is only 1 platform in this test, centos-6.6. Same as for the “suites” there is only one. You can  specify more platforms and suits. The following example is the “suites” part of the dj-wasabi.zabbix-server role:

suites:
  - name: zabbix-server-mysql
    provisioner:
        name: ansible_playbook
        playbook: test/integration/zabbix-server-mysql.yml
  - name: zabbix-server-pgsql
    provisioner:
        name: ansible_playbook
        playbook: test/integration/zabbix-server-pgsql.yml

There are 2 suits with their own playbooks. In the above case, there is an playbook which will be executed with the “MySQL” as backend and there is an playbook with the “PostgreSQL” as backend. Both playbooks will be executed in their own docker instance. So it will start with for example the  ‘zabbix-server-mysql’ suits and when this is finished successfully, it continues with the suit ‘zabbix-server-pgsql’.

You can find on these pages some more information on the configuration of test kitchen, ansible and docker parts:

We now create our only playbook:

wdijkerman@curiosity [ ~/git/ansible/ansible-zabbix-agent ] (13:07:25 - Thu Aug 20)
 (master) > vi test/integration/default.ym
--- 
- hosts: localhost
  roles:
    - role: ansible-zabbix-agent

We have configured the playbook which will be executed against the docker image on ‘localhost’.

But we are not there yet, we will need create some serverspec tests to. With these tests we validate if the execution of the Ansible role went successful.

First we have to create the following directory: test/integration/default/serverspec/localhost

We create the spec_helper.rb file:

wdijkerman@curiosity [ ~/git/ansible/ansible-zabbix-agent ] (13:07:41 - Thu Aug 20)
 (master) > vi test/integration/default/serverspec/spec_helper.rb
require 'serverspec'
set :backend, :exec

We will create the serverspec file:

wdijkerman@curiosity [ ~/git/ansible/ansible-zabbix-agent ] (13:08:22 - Thu Aug 20)
 (master) > vi test/integration/default/serverspec/localhost/ansible_zabbix_agent_spec.rb

The name is not that important, but it has to end with: _spec.rb. We add the following content to the file:

require 'serverspec'
require 'spec_helper'

describe 'Zabbix Agent Packages' do
    describe package('zabbix-agent') do
        it { should be_installed }
    end
end

describe 'Zabbix Agent Configuration' do
    describe file('/etc/zabbix/zabbix_agent.conf') do
        it { should be_file}
        it { should be_owned_by 'zabbix'}
        it { should be_grouped_into 'zabbix'}
    end
end

With the first “describe” we print ‘Zabbix Agent Packages’ and this is an block. When you have some rspec experience with Puppet, you would for example add the params like this: let(:params) { {:server => ‘192.168.1.1’} }
In our case, this is nothing more than printing the text.

Now we proceed with the 2nd describe: package(‘zabbix-agent’). All actions till the firsy “end” is related to this package. For the package we only have 1: it should be_installed. So, when this spec file is executed it will check if the ‘zabbix-agent’ package is installed. If not, you’ll see an error message.

We proceed with the 4th describe, file(‘/etc/zabbix/zabbix_agent.conf’). We have several checks for this file:

  • It Should be an file. (You could also choose for link, directory or even device)
  • The owner of the file needs to be user zabbix
  • The group of the file needs to be group zabbix

There are a lot of other options and checks to use in your spec file, but if we explain it here this is really gonna be an long post.

Only thing that we need to do is to run kitchen. So we execute the following command:

wdijkerman@curiosity [ ~/git/ansible/ansible-zabbix-agent ] (13:09:13 - Thu Aug 20)
 (master) > kitchen test

If everything goes fine, you’ll see a lot of output. At the end of the run, serverspec will be executed:

       Zabbix Agent Packages
         Package "zabbix-agent"
           should be installed
      
       Zabbix Agent Configuration
         File "/etc/zabbix/zabbix_agent.conf"
           should be file (FAILED - 1)
           should be owned by "zabbix" (FAILED - 2)
           should be grouped into "zabbix" (FAILED - 3)
      
       Failures:
      
         1) Zabbix Agent Configuration File "/etc/zabbix/zabbix_agent.conf" should be file
            Failure/Error: it { should be_file}
              expected `File "/etc/zabbix/zabbix_agent.conf".file?` to return true, got false
              /bin/sh -c test\ -f\ /etc/zabbix/zabbix_agent.conf
             
            # /tmp/verifier/suites/serverspec/localhost/ansible_zabbix_agent_spec.rb:12:in `block (3 levels) in <top (required)>
      
         2) Zabbix Agent Configuration File "/etc/zabbix/zabbix_agent.conf" should be owned by "zabbix"
            Failure/Error: it { should be_owned_by 'zabbix'}
              expected `File "/etc/zabbix/zabbix_agent.conf".owned_by?("zabbix")` to return true, got false
              /bin/sh -c stat\ -c\ \%U\ /etc/zabbix/zabbix_agent.conf\ \|\ grep\ --\ \\\^zabbix\\\$
             
            # /tmp/verifier/suites/serverspec/localhost/ansible_zabbix_agent_spec.rb:13:in `block (3 levels) in <top (required)>'
      
         3) Zabbix Agent Configuration File "/etc/zabbix/zabbix_agent.conf" should be grouped into "zabbix"
            Failure/Error: it { should be_grouped_into 'zabbix'}
              expected `File "/etc/zabbix/zabbix_agent.conf".grouped_into?("zabbix")` to return true, got false
              /bin/sh -c stat\ -c\ \%G\ /etc/zabbix/zabbix_agent.conf\ \|\ grep\ --\ \\\^zabbix\\\$
             
            # /tmp/verifier/suites/serverspec/localhost/ansible_zabbix_agent_spec.rb:14:in `block (3 levels) in <top (required)>'
      
       Finished in 0.11823 seconds (files took 0.37248 seconds to load)
       4 examples, 3 failures

Whoops, it seems that my serverspec file was expecting something else. I made an typo, the file should be /etc/zabbix/zabbix_agentd.conf with an d! 🙂

We can see the docker image is created with the “kitchen list” command, the “Last Action” is “Set Up”:

wdijkerman@curiosity [ ~/git/ansible/ansible-zabbix-agent ] (13:14:51- Thu Aug 20)
 (master) > kitchen list
Instance          Driver  Provisioner      Verifier  Transport  Last Action
default-centos-66  Docker  AnsiblePlaybook  Busser    Ssh        Set Up

There are 2 ways to proceed when we fix the typo:

  • We run ‘kitchen test’ again, but it will destroy our docker image and starts again from the start.
  • We run “kitchen verify’ and we only run the serverspec tests. (A lot quicker!)

We use the “kitchen verify” command:

wdijkerman@curiosity [ ~/git/ansible/ansible-zabbix-agent ] (13:15:12 - Thu Aug 20)
 (master) >  kitchen verify
-----> Starting Kitchen (v1.4.2)
-----> Verifying <default-centos-66>...
$$$$$$ Running legacy verify for 'Docker' Driver
       Preparing files for transfer
       Removing /tmp/verifier/suites/serverspec
       Transferring files to <default-centos-66>
-----> Running serverspec test suite
       /opt/rh/ruby193/root/usr/bin/ruby -I/tmp/verifier/suites/serverspec -I/tmp/verifier/gems/gems/rspec-support-3.3.0/lib:/tmp/verifier/gems/gems/rspec-core-3.3.2/lib /tmp/verifier/gems/bin/rspec --pattern /tmp/verifier/suites/serverspec/\*\*/\*_spec.rb --color --format documentation --default-path /tmp/verifier/suites/serverspec
      
       Zabbix Agent Packages
         Package "zabbix-agent"
           should be installed
      
       Zabbix Agent Configuration
         File "/etc/zabbix/zabbix_agentd.conf"
           should be file
           should be owned by "zabbix"
           should be grouped into "zabbix"
      
       Finished in 0.10183 seconds (files took 0.33263 seconds to load)
       4 examples, 0 failures
      
       Finished verifying <default-centos-66> (0m1.12s).
-----> Kitchen is finished. (0m1.17s)

As you see, we only run the serverspec tests and everything is ok. 4 examples with 0 failures.
We can continue with creating serverspec tests and rerun the “kitchen verify” command till we are satisfied.

In theory, you’ll create the tests first before creating the playbook. With practice ….

At the end when you are ready, you’ll create an Jenkins job which pulls for changes from your git repository. You’ll create an job which has 2 “Execute shells” steps:

  • Install bundler and test-kitchen and run bundle install
  • Execute kitchen test

Installation of the gem step:s:

gem install bundler --no-rdoc --no-ri
gem install test-kitchen --no-rdoc --no-ri
bundle install

And 2nd build step:

kitchen test

Whoot! 🙂

Advertisement

7 thoughts on “Using Test Kitchen with Docker and serverspec to test Ansible roles

  1. Should this work with docker toolbox on Mac OS X?

    “`
    $ kitchen test
    —–> Starting Kitchen (v1.4.2)
    —–> Cleaning up any prior instances of
    —–> Destroying …
    Finished destroying (0m0.00s).
    —–> Testing
    —–> Creating …
    >>>>>> ——Exception——-
    >>>>>> Class: Kitchen::ActionFailed
    >>>>>> Message: Failed to complete #create action: [undefined method `create’ for Tempfile:Class]
    >>>>>> ———————-
    >>>>>> Please see .kitchen/logs/kitchen.log for more details
    >>>>>> Also try running `kitchen diagnose –all` for configuration
    “`

    – .kitchen/logs/kitchen.log

    “`
    I, [2015-09-14T21:58:47.268841 #65839] INFO — Kitchen: —–> Starting Kitchen (v1.4.2)
    I, [2015-09-14T21:58:47.316844 #65839] INFO — Kitchen: —–> Cleaning up any prior instances of
    I, [2015-09-14T21:58:47.318199 #65839] INFO — Kitchen: —–> Destroying …
    I, [2015-09-14T21:58:47.320510 #65839] INFO — Kitchen: —–> Testing
    I, [2015-09-14T21:58:47.320607 #65839] INFO — Kitchen: —–> Creating …
    E, [2015-09-14T21:58:47.321961 #65839] ERROR — Kitchen: ——Exception——-
    E, [2015-09-14T21:58:47.321993 #65839] ERROR — Kitchen: Class: Kitchen::ActionFailed
    E, [2015-09-14T21:58:47.322009 #65839] ERROR — Kitchen: Message: Failed to complete #create action: [undefined method `create’ for Tempfile:Class]
    E, [2015-09-14T21:58:47.322032 #65839] ERROR — Kitchen: —Nested Exception—
    E, [2015-09-14T21:58:47.322044 #65839] ERROR — Kitchen: Class: NoMethodError
    E, [2015-09-14T21:58:47.322056 #65839] ERROR — Kitchen: Message: undefined method `create’ for Tempfile:Class
    E, [2015-09-14T21:58:47.322067 #65839] ERROR — Kitchen: ——Backtrace——-
    E, [2015-09-14T21:58:47.322082 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/kitchen-docker-2.3.0/lib/kitchen/driver/docker.rb:252:in `build_image’
    E, [2015-09-14T21:58:47.322095 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/kitchen-docker-2.3.0/lib/kitchen/driver/docker.rb:104:in `create’
    E, [2015-09-14T21:58:47.322107 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:424:in `public_send’
    E, [2015-09-14T21:58:47.322119 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:424:in `block in perform_action’
    E, [2015-09-14T21:58:47.322131 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:488:in `call’
    E, [2015-09-14T21:58:47.322142 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:488:in `synchronize_or_call’
    E, [2015-09-14T21:58:47.322158 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:453:in `block in action’
    E, [2015-09-14T21:58:47.322170 #65839] ERROR — Kitchen: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/benchmark.rb:281:in `measure’
    E, [2015-09-14T21:58:47.322184 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:452:in `action’
    E, [2015-09-14T21:58:47.322197 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:424:in `perform_action’
    E, [2015-09-14T21:58:47.322209 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:352:in `create_action’
    E, [2015-09-14T21:58:47.322220 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:341:in `block in transition_to’
    E, [2015-09-14T21:58:47.322233 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:340:in `each’
    E, [2015-09-14T21:58:47.322246 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:340:in `transition_to’
    E, [2015-09-14T21:58:47.322257 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:160:in `verify’
    E, [2015-09-14T21:58:47.322269 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:189:in `block in test’
    E, [2015-09-14T21:58:47.322280 #65839] ERROR — Kitchen: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/benchmark.rb:281:in `measure’
    E, [2015-09-14T21:58:47.322294 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:185:in `test’
    E, [2015-09-14T21:58:47.322306 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/command.rb:176:in `public_send’
    E, [2015-09-14T21:58:47.322318 #65839] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/command.rb:176:in `block (2 levels) in run_action’
    E, [2015-09-14T21:58:47.322337 #65839] ERROR — Kitchen: ———————-
    “`

    “`
    docker version
    Client:
    Version: 1.8.1
    API version: 1.20
    Go version: go1.4.2
    Git commit: d12ea79
    Built: Thu Aug 13 02:49:29 UTC 2015
    OS/Arch: darwin/amd64

    Server:
    Version: 1.8.1
    API version: 1.20
    Go version: go1.4.2
    Git commit: d12ea79
    Built: Thu Aug 13 02:49:29 UTC 2015
    OS/Arch: linux/amd64
    “`

    Like

      • Hmm I replaced my `docker.rb` unfortunately that wasn’t enough for my environment.

        “`
        I, [2015-09-16T19:06:44.532789 #43253] INFO — Kitchen: —–> Starting Kitchen (v1.4.2)
        I, [2015-09-16T19:06:44.666421 #43253] INFO — Kitchen: —–> Cleaning up any prior instances of
        I, [2015-09-16T19:06:44.668645 #43253] INFO — Kitchen: —–> Destroying …
        I, [2015-09-16T19:06:44.695204 #43253] INFO — Kitchen: —–> Testing
        I, [2015-09-16T19:06:44.695335 #43253] INFO — Kitchen: —–> Creating …
        E, [2015-09-16T19:06:44.700008 #43253] ERROR — Kitchen: ——Exception——-
        E, [2015-09-16T19:06:44.700039 #43253] ERROR — Kitchen: Class: Kitchen::ActionFailed
        E, [2015-09-16T19:06:44.700056 #43253] ERROR — Kitchen: Message: Failed to complete #create action: [undefined local variable or method `build_context’ for #]
        E, [2015-09-16T19:06:44.700071 #43253] ERROR — Kitchen: —Nested Exception—
        E, [2015-09-16T19:06:44.700086 #43253] ERROR — Kitchen: Class: NameError
        E, [2015-09-16T19:06:44.700099 #43253] ERROR — Kitchen: Message: undefined local variable or method `build_context’ for #
        E, [2015-09-16T19:06:44.700112 #43253] ERROR — Kitchen: ——Backtrace——-
        E, [2015-09-16T19:06:44.700125 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/kitchen-docker-2.3.0/lib/kitchen/driver/docker.rb:263:in `build_image’
        E, [2015-09-16T19:06:44.700138 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/kitchen-docker-2.3.0/lib/kitchen/driver/docker.rb:104:in `create’
        E, [2015-09-16T19:06:44.700153 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:424:in `public_send’
        E, [2015-09-16T19:06:44.700169 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:424:in `block in perform_action’
        E, [2015-09-16T19:06:44.700182 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:488:in `call’
        E, [2015-09-16T19:06:44.700195 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:488:in `synchronize_or_call’
        E, [2015-09-16T19:06:44.700207 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:453:in `block in action’
        E, [2015-09-16T19:06:44.700222 #43253] ERROR — Kitchen: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/benchmark.rb:281:in `measure’
        E, [2015-09-16T19:06:44.700234 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:452:in `action’
        E, [2015-09-16T19:06:44.700247 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:424:in `perform_action’
        E, [2015-09-16T19:06:44.700259 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:352:in `create_action’
        E, [2015-09-16T19:06:44.700273 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:341:in `block in transition_to’
        E, [2015-09-16T19:06:44.700288 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:340:in `each’
        E, [2015-09-16T19:06:44.700301 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:340:in `transition_to’
        E, [2015-09-16T19:06:44.700314 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:160:in `verify’
        E, [2015-09-16T19:06:44.700326 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:189:in `block in test’
        E, [2015-09-16T19:06:44.700340 #43253] ERROR — Kitchen: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/benchmark.rb:281:in `measure’
        E, [2015-09-16T19:06:44.700353 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/instance.rb:185:in `test’
        E, [2015-09-16T19:06:44.700366 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/command.rb:176:in `public_send’
        E, [2015-09-16T19:06:44.700389 #43253] ERROR — Kitchen: /Library/Ruby/Gems/2.0.0/gems/test-kitchen-1.4.2/lib/kitchen/command.rb:176:in `block (2 levels) in run_action’
        E, [2015-09-16T19:06:44.700406 #43253] ERROR — Kitchen: ———————-
        “`

        Like

        • Hi,

          I Installed it again on my Mac and encountered the same problem you have right now.

          For some reason I don’t know (I’m not an ruby expert at all and don’t want to be), when removing or adding the ‘!’ on line 70 of the docker.rb file, it works.
          So, if this won’t work:

          69 default_config :build_context do |driver|
          70 !driver.remote_socket?
          71 end

          change it into this. (or vice versa)

          69 default_config :build_context do |driver|
          70 driver.remote_socket?
          71 end

          I’ve run 3 runs right now and they keep working now … 😐

          Like

          • Cool! I’m no ruby expert either. After that change it pulled and started a centos image. It fails with an ssh error for some reason even though the connect mode is local.

            “`
            Complete!
            —–> Enabling ruby193
            /opt/rh/ruby193/root/usr/lib64
            Transferring files to
            ERROR: cannot find role in /tmp/kitchen/roles/ansible-zabbix-agent or /tmp/kitchen/ansible-zabbix-agent or /tmp/kitchen/roles/ansible-zabbix-agent
            zlib(finalizer): the stream was freed prematurely.
            >>>>>> Converge failed on instance .
            >>>>>> Please see .kitchen/logs/default-centos-66.log for more details
            >>>>>> ——Exception——-
            >>>>>> Class: Kitchen::ActionFailed
            >>>>>> Message: SSH exited (1) for command: [sudo -E ansible-playbook –inventory-file=/tmp/kitchen/hosts -c local -M /tmp/kitchen/modules /tmp/kitchen/default.yml]
            >>>>>> ———————-
            “`

            I do see the bits in the container under /tmp/kitchen.

            “`
            [root@d7f888072e16 kitchen]# ls /tmp/kitchen
            ansible.cfg default.yml filter_plugins group_vars hosts host_vars lookup_plugins modules roles
            “`

            I tried to run it by hand, but the default.yml playbook has the wrong name for the role.

            “`
            [root@d7f888072e16 kitchen]# ansible-playbook -i /tmp/kitchen/hosts -c local default.yml
            ERROR: cannot find role in /tmp/kitchen/roles/ansible-zabbix-agent or /tmp/kitchen/ansible-zabbix-agent or /tmp/kitchen/roles/ansible-zabbix-agent
            [root@d7f888072e16 kitchen]# ls roles
            ansible-dj-wasabi-zabbix-agent
            [root@d7f888072e16 kitchen]# cat default.yml

            – hosts: localhost
            roles:
            – role: ansible-zabbix-agent
            agent_server: zabbix.pixar.com
            agent_serveractive: zabbix.pixar.com

            “`

            I modified the playbook and ran it by hand and it looks like the default version 2.4 is not available in the default EPEL repo. It may make sense to change the default version or modify the test?

            “`
            [root@d7f888072e16 kitchen]# ansible-playbook -i /tmp/kitchen/hosts -c local default.yml

            PLAY [localhost] **************************************************************

            GATHERING FACTS ***************************************************************
            ok: [localhost]

            TASK: [ansible-dj-wasabi-zabbix-agent | RedHat | Set some facts] **************
            ok: [localhost]

            TASK: [ansible-dj-wasabi-zabbix-agent | RedHat | Set short version name] ******
            ok: [localhost]

            TASK: [ansible-dj-wasabi-zabbix-agent | RedHat | Use EPEL package name] *******
            ok: [localhost]

            TASK: [ansible-dj-wasabi-zabbix-agent | RedHat | Install basic repo file] *****
            skipping: [localhost]

            TASK: [ansible-dj-wasabi-zabbix-agent | RedHat | Installing zabbix-agent] *****
            failed: [localhost] => {“changed”: false, “failed”: true, “rc”: 0, “results”: []}
            msg: No Package matching ‘zabbix24-agent’ found available, installed or updated

            FATAL: all hosts have already failed — aborting

            PLAY RECAP ********************************************************************
            to retry, use: –limit @/root/default.retry

            localhost : ok=4 changed=0 unreachable=0 failed=1
            “`

            This is all very cool.

            Like

          • Yes, it assumes the module is stored on the machine/laptop as ‘ansible-zabbix-agent’. Someone made an PR with an very basic setup of this and it really took some time to find out that the name of the directory should be ‘ansible-zabbix-agent’. I made an change several days ago, so ‘zabbix’ is default as repo. But I’m thinking about adding an new test, which uses the repo package. So when executing ‘kitchen test’ it will test an “zabbix” repo version and an ‘epel’ repo version.

            Yes, this is really fun. I’m about to update all my Ansible roles with these kinds of tests. I’m also checking if some “BATS” tests should be included as well. More info: https://github.com/sstephenson/bats

            Like

  2. Hi,

    I get the following error

    sudo /usr/local/bin/kitchen verify
    —–> Starting Kitchen (v1.10.2)
    —–> Verifying …
    $$$$$$ Running legacy verify for ‘Docker’ Driver
    Preparing files for transfer
    Removing /tmp/verifier/suites/bats
    Removing /tmp/verifier/suites/serverspec
    Transferring files to
    —–> Running bats test suite
    ✓ Second run should change nothing

    1 test, 0 failures
    —–> Running serverspec test suite
    —–> Bundle Installing..
    run /opt/rh/ruby193/root/usr/bin/ruby /tmp/verifier/gems/bin/bundle install –gemfile /tmp/verifier/suites/serverspec/Gemfile –local || /opt/rh/ruby193/root/usr/bin/ruby /tmp/verifier/gems/bin/bundle install –gemfile /tmp/verifier/suites/serverspec/Gemfile from “.”
    Don’t run Bundler as root. Bundler can ask for sudo if it is needed, and
    installing your bundle as root will break this application for all non-root
    users on this machine.
    Resolving dependencies…
    Rubygems 1.8.23 is not threadsafe, so your gems will be installed one at a time. Upgrade to Rubygems 2.1.0 or higher to enable parallel gem installation.
    Using rake 11.2.2
    Using bundler 1.12.5
    Bundle complete! 1 Gemfile dependency, 2 gems now installed.
    Use `bundle show [gemname]` to see where a bundled gem is installed.
    /opt/rh/ruby193/root/usr/bin/ruby -I/tmp/verifier/suites/serverspec -I/tmp/verifier/gems/gems/rspec-support-3.4.1/lib:/tmp/verifier/gems/gems/rspec-core-3.4.4/lib /tmp/verifier/gems/bin/rspec –pattern /tmp/verifier/suites/serverspec/\*\*/\*_spec.rb –color –format documentation –default-path /tmp/verifier/suites/serverspec
    /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:36:in `require’: cannot load such file — json (LoadError)
    from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:36:in `require’
    from /tmp/verifier/gems/gems/serverspec-2.36.0/lib/serverspec/type/json_file.rb:1:in `’
    from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:36:in `require’
    from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:36:in `require’
    from /tmp/verifier/gems/gems/serverspec-2.36.0/lib/serverspec/helper/type.rb:16:in `block in ‘
    from /tmp/verifier/gems/gems/serverspec-2.36.0/lib/serverspec/helper/type.rb:16:in `each’
    from /tmp/verifier/gems/gems/serverspec-2.36.0/lib/serverspec/helper/type.rb:16:in `’
    from /tmp/verifier/gems/gems/serverspec-2.36.0/lib/serverspec/helper/type.rb:3:in `’
    from /tmp/verifier/gems/gems/serverspec-2.36.0/lib/serverspec/helper/type.rb:2:in `’
    from /tmp/verifier/gems/gems/serverspec-2.36.0/lib/serverspec/helper/type.rb:1:in `’
    from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:36:in `require’
    from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:36:in `require’
    from /tmp/verifier/gems/gems/serverspec-2.36.0/lib/serverspec/helper.rb:2:in `’
    from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:36:in `require’
    from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:36:in `require’
    from /tmp/verifier/gems/gems/serverspec-2.36.0/lib/serverspec.rb:7:in `’
    from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:60:in `require’
    from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:60:in `rescue in require’
    from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:35:in `require’
    from /tmp/verifier/suites/serverspec/localhost/ansible_zabbix_agent_spec.rb:1:in `’
    from /tmp/verifier/gems/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `load’
    from /tmp/verifier/gems/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `block in load_spec_files’
    from /tmp/verifier/gems/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `each’
    from /tmp/verifier/gems/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `load_spec_files’
    from /tmp/verifier/gems/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:106:in `setup’
    from /tmp/verifier/gems/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:92:in `run’
    from /tmp/verifier/gems/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:in `run’
    from /tmp/verifier/gems/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:in `invoke’
    from /tmp/verifier/gems/gems/rspec-core-3.4.4/exe/rspec:4:in `’
    from /tmp/verifier/gems/bin/rspec:23:in `load’
    from /tmp/verifier/gems/bin/rspec:23:in `’
    /opt/rh/ruby193/root/usr/bin/ruby -I/tmp/verifier/suites/serverspec -I/tmp/verifier/gems/gems/rspec-support-3.4.1/lib:/tmp/verifier/gems/gems/rspec-core-3.4.4/lib /tmp/verifier/gems/bin/rspec –pattern /tmp/verifier/suites/serverspec/\*\*/\*_spec.rb –color –format documentation –default-path /tmp/verifier/suites/serverspec failed
    !!!!!! Ruby Script [/tmp/verifier/gems/gems/busser-serverspec-0.5.9/lib/busser/runner_plugin/../serverspec/runner.rb /tmp/verifier/suites/serverspec] exit code was 1
    >>>>>> ——Exception——-
    >>>>>> Class: Kitchen::ActionFailed
    >>>>>> Message: 1 actions failed.
    >>>>>> Verify failed on instance . Please see .kitchen/logs/default-centos-66.log for more details
    >>>>>> ———————-
    >>>>>> Please see .kitchen/logs/kitchen.log for more details
    >>>>>> Also try running `kitchen diagnose –all` for configuration

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s