I’ve used Chef data bags before, but this morning I’ve been banging my head against them trying to figure out this error:
Chef::Exceptions::ValidationFailed: Data Bag Items must contain a Hash or Mash!
This was coming from the following line in my recipe:
dbi = data_bag_item('aw', 'staging')
And my data bag (in aw/staging.json
) looked like this:
{
"password": "foo"
}
Clearly that was a hash! Eventually I noticed this line from the Chef documentation:
Each item in the bag gets its own JSON file. The only structural requirement of items is that they have an id.
So I changed my data bag to this:
{
"id": "aw-staging"
"password": "foo"
}
Still no good! After yet more struggle and pain, as I was starting to thrash around, it started working! Pretty much by accident, I had a data bag like this:
{
"id": "staging"
"password": "foo"
}
Was the problem that IDs can’t contain a hyphen? No, it turns out that the ID must match the name of the file (minus .json
). What a nasty trick! So I’m writing this post to help the next poor soul fighting against this unhelpful error message.
I also filed a ticket with Opscode asking them to improve their documentation.
blog comments powered by Disqus Prev: Alien Words: Vocabulary Game for Greek and Latin Next: best_in_place Javascript Callbacks