How do I check if a chef databag has correct syntax within a ruby script?

420 Views Asked by At

Say that the databag I am using is missing a bracket or comma, is there a way to check that within a script?

1

There are 1 best solutions below

0
On

Maybe its not a direct answer you are expecting , Let me say how I validate the data bags.

I always start with creating a json file which I will use for populating data bag. Let me outline the step I follow and it always worked for me.

  1. Create data bag

    knife data bag create example1

  2. Create json file: /tmp/example1_data.json:

    { "id": "id1", "name": "example1" }

  3. Validate the json file python -mjson.tool /tmp/example1_data.json

This will tell you whether the json file is validate or not

4 . populate data bag items

knife data bag from file example1 /tmp/example1.json