Serverspec 无法验证 pip 在 OS X 目标上安装的任何包
Serverspec fails to verify any package installed by pip on OS X target
使用 serverspec-2.36.0
我无法验证 pip
在 OS X El Capitan 虚拟机上安装的任何软件包。
测试 Serverspec 执行的命令给出了正确的结果。
以下示例适用于在用户 vagrant
上安装 pip install ansible --user
的 ansible
。
我的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)>'
出于我无法理解的原因,Serverspec 无法找到 OS X 的原生 Python(在 /usr/bin/python
中)或使用 Homebrew 安装的(在 /usr/local/bin/python
中)。
作为解决方法,我添加了:
set :path, '/usr/local/bin:$PATH'
至spec_helper.rb
。
使用 serverspec-2.36.0
我无法验证 pip
在 OS X El Capitan 虚拟机上安装的任何软件包。
测试 Serverspec 执行的命令给出了正确的结果。
以下示例适用于在用户 vagrant
上安装 pip install ansible --user
的 ansible
。
我的
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)>'
出于我无法理解的原因,Serverspec 无法找到 OS X 的原生 Python(在 /usr/bin/python
中)或使用 Homebrew 安装的(在 /usr/local/bin/python
中)。
作为解决方法,我添加了:
set :path, '/usr/local/bin:$PATH'
至spec_helper.rb
。