user2114835
user2114835

Reputation:

Chef recipe not executing on first convergence

I've basic chef cookbook and one of the recipes does not converge in the first run.

Chef Cookbook: https://github.com/linaksa/linaksa_infra

When I run kitchen test the recipe linaksa_infra::hosts does not get converge at all. Also when I run kitchen setup it does not get converge but if I run kitchen converge after then it does. I am not sure what am I doing wrong?

Here is the output of kitchen test kitchen setup and kitchen converge: https://gist.github.com/linaksa/76607bbfd15e471dfa67

I am using Chef DK 0.10.0. Any help would be highly appreciated.

Upvotes: 0

Views: 785

Answers (1)

zuazo
zuazo

Reputation: 5738

Don't worry, the recipe is executed in both cases.

The problem is that the recipe is printed on the screen only if at least contains a resource inside it.

Looking at the recipe code:

nodes = search(:node, 'ipaddress:*')
nodes.each do |n|
  hostsfile_entry n['ipaddress'] do
    # [...]
  end
end

The reason is that the first time the search returns no nodes (we are using kitchen). So in the first run this recipe will not create any resource. Therefore, the recipe will not be displayed on screen as executed.

The second time, if you are using chef_zero provisioner the search will return the localhost machine because it was saved at the end of the previous chef run.

You can try running kitchen with -l debug to confirm what is going on.

Upvotes: 3

Related Questions