2

I'm using Packer to create an AMI in AWS based on the Amazon Linux AMI, provisioned with Ansible.

Some of my serverspec tests fail and I don't understand why. First one that always fails is trying to make sure that Docker is installed and running. It always fails trying to test that the service is enabled and running. This is my spec

require 'spec_helper'

describe package('docker') do
  it { should be_installed }
end

describe service('docker') do
  it { should be_enabled }
  it { should be_running }
end

After googling a bit, I've tried this with same results

require 'spec_helper'

describe package('docker') do
  it { should be_installed }
end

describe service('docker') do
  it { should be_enabled.with_level(2) }
  it { should be_enabled.with_level(3) }
  it { should be_enabled.with_level(4) }
  it { should be_enabled.with_level(5) }
  it { should be_running }
end

While provisioning with Ansible, I've tried to execute the same commands that serverspec is using for the specs, and I get what I understand is the right answer, but still specs fail.

These are the commands that serverspec is using

amazon-ebs: 2) Service "docker" should be enabled with level 2
amazon-ebs: On host `localhost'
amazon-ebs: Failure/Error: it { should be_enabled.with_level(2) }
amazon-ebs:   expected Service "docker" to be enabled with level 2
amazon-ebs:   /bin/sh -c chkconfig\ --list\ docker\ \|\ grep\ 2:on
amazon-ebs:   
amazon-ebs: # ./spec/localhost/docker_spec.rb:8:in `block (2 levels) in <top (required)>'
amazon-ebs:
amazon-ebs: 3) Service "docker" should be enabled with level 3
amazon-ebs: On host `localhost'
amazon-ebs: Failure/Error: it { should be_enabled.with_level(3) }
amazon-ebs:   expected Service "docker" to be enabled with level 3
amazon-ebs:   /bin/sh -c chkconfig\ --list\ docker\ \|\ grep\ 3:on
amazon-ebs:   
amazon-ebs: # ./spec/localhost/docker_spec.rb:9:in `block (2 levels) in <top (required)>'
amazon-ebs:
amazon-ebs: 4) Service "docker" should be enabled with level 4
amazon-ebs: On host `localhost'
amazon-ebs: Failure/Error: it { should be_enabled.with_level(4) }
amazon-ebs:   expected Service "docker" to be enabled with level 4
amazon-ebs:   /bin/sh -c chkconfig\ --list\ docker\ \|\ grep\ 4:on
amazon-ebs:   
amazon-ebs: # ./spec/localhost/docker_spec.rb:10:in `block (2 levels) in <top (required)>'
amazon-ebs:
amazon-ebs: 5) Service "docker" should be enabled with level 5
amazon-ebs: On host `localhost'
amazon-ebs: Failure/Error: it { should be_enabled.with_level(5) }
amazon-ebs:   expected Service "docker" to be enabled with level 5
amazon-ebs:   /bin/sh -c chkconfig\ --list\ docker\ \|\ grep\ 5:on
amazon-ebs:   
amazon-ebs: # ./spec/localhost/docker_spec.rb:11:in `block (2 levels) in <top (required)>'
amazon-ebs:
amazon-ebs: 6) Service "docker" should be running
amazon-ebs: On host `localhost'
amazon-ebs: Failure/Error: it { should be_running }
amazon-ebs:   expected Service "docker" to be running
amazon-ebs:   /bin/sh -c service\ docker\ status
amazon-ebs:   
amazon-ebs: # ./spec/localhost/docker_spec.rb:12:in `block (2 levels) in <top (required)>'

And this is the playbook that installs Docker, printing the output of the same commands as serverspec uses

---

- name: Install yum dependencies
  yum: name=docker state=present

- name: "Starting Docker service"
  service: name=docker enabled=yes state=started

- command: "chkconfig --list docker"
  register: docker_enabled

- debug: var=docker_enabled

- command: "service docker status"
  register: docker_status

- debug: var=docker_status

And the output of both commands are

    amazon-ebs: TASK [debug] *******************************************************************
    amazon-ebs: ok: [127.0.0.1] => {
    amazon-ebs: "stdout": "docker         \t0:off\t1:off\t2:on\t3:on\t4:on\t5:on\t6:off",
    amazon-ebs: }
    amazon-ebs:

    amazon-ebs: TASK [debug] *******************************************************************
    amazon-ebs: ok: [127.0.0.1] => {
    amazon-ebs: "stdout": "docker (pid  2943) is running...",
    amazon-ebs: }

What I'm doing wrong?

Jose Armesto
  • 12,794
  • 8
  • 51
  • 56

0 Answers0