문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top