Using serverspec-2.36.0
I cannot verify any package installed by pip
on OS X El Capitan virtual machine.
Testing the command executed by Serverspec gives correct results.
The following example is for ansible
installed with pip install ansible --user
on user vagrant
.
My 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
Result:
Command "whoami"
stdout
should match "vagrant"
Package "ansible"
should be installed by "pip" (FAILED - 1)
Details of the second task:
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)>'
I login to machine and run:
$ 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)
I am clueless regarding both: the reason and next possible steps in troubleshooting.
troubleshooting
I added a task to check which python
(from inside the Serverspec) and it fails with:
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)>'
For reasons beyond my understanding Serverspec could not find either OS X's native Python (in /usr/bin/python
) or the one installed with Homebrew (in /usr/local/bin/python
).
As a workaround I added:
set :path, '/usr/local/bin:$PATH'
to spec_helper.rb
.