2

使用serverspec-2.36.0我无法验证pipOS X El Capitan 虚拟机上安装的任何软件包。

测试由 Serverspec 执行的命令会给出正确的结果。

以下示例适用于在用户上ansible安装。pip install ansible --uservagrant

  • 我的ansible_spec.rb

    require 'spec_helper'
    
    describe command('whoami') do
      let(:disable_sudo) { true }
      its(:stdout) { should match 'vagrant' }
    end
    
    describe package('ansible') do
      let(:disable_sudo) { true }
      it { should be_installed.by('pip') }
    end
    
  • 结果:

    Command "whoami"
      stdout
        should match "vagrant"
    
    Package "ansible"
      should be installed by "pip" (FAILED - 1)
    

    第二个任务的详细信息:

    Failures:
    
      1) Package "ansible" should be installed by "pip"
         On host `osx-01'
         Failure/Error: it { should be_installed.by('pip') }
           expected Package "ansible" to be installed by "pip"
           /bin/sh -c pip\ list\ \|\ grep\ -iw\ --\ \\\^ansible
    
         # ./spec/ansible_spec.rb:10:in `block (2 levels) in <top (required)>'
    
  • 我登录机器并运行:

    $ whoami
    vagrant
    $ pip list | grep -iw -- ^ansible
    ansible (2.1.0.0)
    $ /bin/sh -c pip\ list\ \|\ grep\ -iw\ --\ \\\^ansible
    ansible (2.1.0.0)
    

我对这两个方面一无所知:故障排除的原因和下一步可能的步骤。


故障排除

  • 我添加了一个要检查的任务which python(从 Serverspec 内部),但它失败了:

    1) Command "which python" stdout should match "/usr/local/bin/python"
       On host `ansible-osx-devops-environment-01'
       Failure/Error: its(:stdout) { should match '/usr/local/bin/python' }
         expected "" to match "/usr/local/bin/python"
         env PATH="/usr/local/bin" /bin/sh -c which\ python
    
       # ./spec/ansible_spec.rb:11:in `block (2 levels) in <top (required)>'
    
4

1 回答 1

-1

由于我无法理解的原因,Serverspec 找不到 OS X 的本机 Python(在 中/usr/bin/python)或随 Homebrew 一起安装的 Python(在 中/usr/local/bin/python)。

作为一种解决方法,我添加了:

set :path, '/usr/local/bin:$PATH'

spec_helper.rb.

于 2016-06-15T23:36:56.137 回答