0

I have a data_bag with 40+ items and need to add certain parameters to most of them.

Is there a way to edit, e.g. with knife, all data_bag items? So far, all I can see is to have each item open in my editor.

berkes
  • 26,996
  • 27
  • 115
  • 206

1 Answers1

1

You can go through all of them with cycle and save each into file by calling

for item in <item1> <item2> <item3> ; do
  knife data bag show <data_bag> $item -Fj > my_data_bag/$item.json
done

Then add the required parameters into every json file by copy/paste or some macro. And update the bag items on chef-server by calling:

knife data bag from file <data_bag> my_data_bag/*.json
Draco Ater
  • 20,820
  • 8
  • 62
  • 86
  • 1
    You probably want to use the `-Fj` option to generate JSON data as the default output format is YAML. – Tim Potter Nov 18 '13 at 23:08
  • Thanks, added it to the answer. – Draco Ater Nov 19 '13 at 09:00
  • Also, Chef 11 has incorporated knife-essentials so you could do: `knife download data_bags/*` then edit each of the data bag json files and `knife upload data_bags/*`. Reference here: https://github.com/jkeiser/knife-essentials – cassianoleal Nov 19 '13 at 09:44