Search code examples
chef-infrachef-recipe

chef, regarding multiple calls to the same resource and about services


For example, lets say you have two template resources.

Both notify the same service to restart should either of them be updated.

Since they both do the same action in the same way , do the calls in the runlist get concatenated into one call?

Secondly, If I have a call to start a service but a subsequent resource makes a call to restart the same service, what happens and how should I deal with it?


Solution

  • Two different things here.

    1. A duplicate resource with a different action

    In this case, chef will clone the first resource with that name, rather than creating a second resource from scratch. The action, however, is not cloned, and will be the default_action unless you specifically set it. Any other attributes set in the second resource declaration will then be set (overriding what was cloned from the first declaration).

    This new resource will then be placed on the resource stack in the same order it was declared. In this case, BOTH actions will be run in the order in which they were declared.

    2. A second notification to the same resource.

    In this case the notifications are added to the notification stack, not the resource stack. The code to add to the notification stack will first look for an existing notification. If it finds one, then it will NOT add another.

    I know that a two notifications to the same resource with the same action will be considered duplicate, and the second will not be added.

    I'm not entirely clear on whether two different actions on the same resource are merged, or treated as different notifications, but I believe it is the later.

    I'm completely uncertain what happens when your notifications include multiple actions. (ie, one notify to :start the service, and another to [:enable, start ]