Question

I'm working on a infrastructure where some servers don't have access to the internet, so I have to push the packages to the local repo before declaring them to be installed on Chef.

However we've been on a situation where Chef failed to install a package since the package wasn't there on some boxes and it has been successful on some other boxes.

What I want to do is to run a Ruby/RSpec test before applying Chef config on the nodes to make sure the packages declared on the recipes do actually exist on the repo.

In order to do that I need to be able to list all the packages exists in the our recipes.

My question is: Is there anyway to list all the declared packages in Chef? I had a quick look at Chef::Platform and ChefSpec but unfortunately couldn't find anything useful to my problem.

Do you have any idea where is the best place to look at?

Était-ce utile?

La solution

If you use ChefSpec you can find all the packages by calling chef_run.find_resources(:package) inside some test. See the source code. Like this:

require 'chefspec'

describe 'example::default' do
  let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }

  it 'does something' do
    chef_run.find_resources(:package)...
  end
end

Autres conseils

You could install one or more of the community ohai plugins. For example the following will return information about installed sofware:

Once the plugins are enabled they will add additional node attributes that will be searchable from chef-server.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top