1
votes

Is there a way to do something when the values change in a Chef Data Bag.

Lets say a data bag looks like this.

{
    "data": {
        "version": "1.0.12-SNAPSHOT"
    }
}

and it changes to this

{
    "data": {
        "version": "1.0.13"
    }
}

is there a way for a Chef resource to 'Subscribe' to this change or this change to 'Notify' a Resource of the change?

1
Using open source chef server or enterprise chef? - StephenKing
I am using enterprise chef. - tinytelly
Then it's not a clear no. I don't know, if you can already trigger a push job on an event like a data bag upload in enterprise chef. But such a push job could then trigger chef-client. - StephenKing

1 Answers

2
votes

The common solution for this is not to subscribe to the change in the data bag but to sensibly handle the result of the change.

It seems that you describe a version of a software to be installed there. Thus, a sensible approach would be to perform these steps during each chef run:

  • check if the currently installed version of the software is the same as the one currently defined in the data bag
  • if it matches, do nothing
  • if it differs, update the software

That way, you don't need any actual publish/subscribe architecture but just handle everything during your regular chef runs.

In fact, this general approach is how about all providers in Chef work: check the current state and adapt it if it differs from the intended state as defined by the recipe.