0

Am I right in thinking that probably there is no option to change the value from the command line?

For example something like this:

knife data bag edit my_data_bag host1 ...action "upgrade"

So then second line will be changed from "remove" to "upgrade":

{
    "id": "host1",
    "action": "remove"
}

I know that I can do it from file, but I wanted to provide simpler process for different teams. It would be easier to provide command and not files to edit. It requires some understanding to edit json file and passing to the knife. Also there can be difficulties to edit json for hundreds of boxes.

Maybe you see a good way to simplify this? The goal is to provide simple process like few commands rather than editing files.

StephenKing
  • 36,187
  • 11
  • 83
  • 112
laimison
  • 1,409
  • 3
  • 17
  • 39
  • You may craft something around `knife exec` ... But that sounds a bad pattern with high risks (databags item are replaced on server side, not merged. Race conditions will appear if you have many users changing the same item and some modifications will be lost) – Tensibai Feb 22 '16 at 16:12

1 Answers1

1

As there is no direct way to modify it through knife, I would recommend to programmatically change the file using the jq utility.

Based on a simple script, you could read input from the user, change the JSON file accordingly and then call knife data bag from file without needing the user to directly invoke knife.

Another option - and I personally would prefer this - would be that the modified JSON file is pushed via Git, which then triggers a CI server (e.g. Jenkins), which then updates the data bag. This would make your setup easier, if not everyone needs access to the Chef server.

StephenKing
  • 36,187
  • 11
  • 83
  • 112
  • Thanks for the suggestion. As a second option, how the user can change the value from "remove" to "upgrade"? If I understood correctly Jenkins can invoke knife to update data bag using prepared json file. Wanted to get more details about the beginning of it. – laimison Feb 22 '16 at 17:18