onknows
onknows

Reputation: 6711

How to check if recipe is included/applied with Chef

I have a wrapper cookbook that includes postgresql::server. In another cookbook I want to check if that recipe is applied. Using node.recipe? 'postgresql::server' I cannot test for that.

How can I do this with Chef?

Upvotes: 0

Views: 2116

Answers (3)

Christo
Christo

Reputation: 21

For completeness: In principle node.recipe? is the right way to go.

But in the compile phase of your chef run, node['recipes'] will initially only contain the recipes in your explicitly defined run list. It will be completed during the compilation phase with every include_recipe that occurs.

Therefore: If your node.recipe? 'postgresql::server' is evaluated before a include_recipe 'postgresql::server' in the order of compilation, it will return false.

Upvotes: 0

Tensibai
Tensibai

Reputation: 15784

Try node['recipes'].include? 'postgresql::server'

For what it worth, according to the code , your node.recipe? should work with latest version.

Upvotes: 4

Tim Haintz
Tim Haintz

Reputation: 676

From here: https://docs.chef.io/run_lists.html

knife status --run-list

knife status "role:web" --run-list

Hope this helps.

Thanks, Tim.

Upvotes: -1

Related Questions