Navarro
Navarro

Reputation: 1384

How to make a Chef custom resource execute on every chef run

I have a custom Chef resource that starts a background job. It has :start, :stop and :reset actions.

There is another resource that notifies :reset to my custom one when it is updated.

The main problem I have is that on each chef-client run the status of the resource returns:

custom_resource[resource-name] action start (up to date)
custom_resource[resource-name] action reset (up to date)

This behavior from Chef is the one I expect but not the one I need. My resource must be run on each chef-client run like the resource execute does. How can I achieve this?

Upvotes: 0

Views: 515

Answers (2)

danielcooperxyz
danielcooperxyz

Reputation: 999

The answer described here is the recommended way in Chef 11.x/12.x.

Add the below in your custom resource file.

def whyrun_supported?
  true
end

Upvotes: 0

coderanger
coderanger

Reputation: 54181

It does run every time by default, but unless you call new_resource.updated_by_last_action(true) or a similar API Chef shows "up to date" because the resource hasn't said it updated anything on the system.

Upvotes: 1

Related Questions