serverspec测试无法检查Docker服务是否在AWS上运行

时间:2016-07-17 12:39:42

标签: amazon-web-services ansible ami packer serverspec

我使用Packer在AWS中基于使用Ansible配置的Amazon Linux AMI创建AMI。

我的一些服务器规格测试失败,我不明白为什么。首先总是失败的是尝试确保Docker已安装并正在运行。它始终无法尝试测试服务是否已启用并正在运行。这是我的规范

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

在谷歌搜索后,我尝试了相同的结果

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

在使用Ansible进行配置时,我尝试执行serverpec用于规范的相同命令,我得到的理解是正确答案,但规格仍然失败。

这些是serverspec正在使用的命令

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)>'

这是安装Docker的playbook,打印与serverspec使用相同命令的输出

---

- 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

两个命令的输出都是

    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: }

我做错了什么?

0 个答案:

没有答案