2

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)>'
    
techraf
  • 64,883
  • 27
  • 193
  • 198
  • 1
    Those backslashes are for escaping and the actual command is `pip list | grep -iw -- ^ansible` (https://github.com/mizzy/specinfra/blob/513a2c41c0d0f59ffd76f2308dffeabcfa8aadc8/lib/specinfra/command/base/package.rb#L40). Same output though. Interesting side effect is that command would also return a false success for, say, `ansible-lint` despite an absence of `ansible`. Anyway, this sounds like more of a vagrant issue than servserspec issue. – Matthew Schuchard Jun 15 '16 at 12:58
  • Well spotted `-w`! And it will in fact prevent ever finding `ansible-lint`. – techraf Jun 15 '16 at 13:05
  • Yeah, sorry I couldn't really help, but I am going to do a PR to Specinfra because of this. It is likely happening for other package providers too. By the way, have you tried this: https://github.com/jvoorhis/vagrant-serverspec? I have never used it, but it certainly looks promising. – Matthew Schuchard Jun 15 '16 at 13:49
  • I think I'm on track. For some reason Serverspec does not find `pip` (even `which pip` with explicitly provided `PATH` fails). – techraf Jun 15 '16 at 13:52

1 Answers1

-1

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.

techraf
  • 64,883
  • 27
  • 193
  • 198