Serverspec无法验证OS X目标上由pip安装的任何软件包

时间:2016-06-15 11:59:38

标签: macos serverspec

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

测试Serverspec执行的命令可以得到正确的结果。

以下示例适用于在ansible用户pip install ansible --user上安装的vagrant

  • 我的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)>'
    

1 个答案:

答案 0 :(得分:-1)

出于我理解的原因,Serverspec无法找到OS X的原生Python(在/usr/bin/python中)或使用Homebrew安装的(在/usr/local/bin/python中)。

作为一种解决方法,我补充道:

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

spec_helper.rb