使用serverspec-2.36.0
我无法验证pip
OS X El Capitan 虚拟机上安装的任何软件包。
测试由 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)>'