# Searching a data bag

**URL:** <https://discourse.chef.io/t/searching-a-data-bag/1959>\
**Category:** Chef Infra (archive)\
**Created:** [July 5, 2011, 2:07pm UTC](https://discourse.chef.io/t/searching-a-data-bag/1959 "2011-07-05T14:07:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ItsMikeE](https://avatars.discourse-cdn.com/v4/letter/i/d6d6ee/32.png) [@ItsMikeE](https://discourse.chef.io/u/ItsMikeE)\
**Post date:** [July 5, 2011, 2:07pm UTC](https://discourse.chef.io/t/searching-a-data-bag/1959/1 "2011-07-05T14:07:55Z")

</div>

I have created a databag called demo\_databag  
I then loaded up a json file as detailed below:  
{“id”:“demo\_value”,  
“hosts”:[  
{“host”:“[host0.pinnacle.co.uk](http://host0.pinnacle.co.uk)”, “ip”:“3.2.3.4”, “aliases”:[“host1”]},  
{“host”:“[host1.pinnacle.co.uk](http://host1.pinnacle.co.uk)”, “ip”:“3.2.3.5”, “aliases”:[“host2”]},  
{“host”:“[host2.pinnacle.co.uk](http://host2.pinnacle.co.uk)”, “ip”:“3.2.3.6”, “aliases”:[“host3”]},  
{“host”:“[host3.pinnacle.co.uk](http://host3.pinnacle.co.uk)”, “ip”:“3.2.3.7”, “aliases”:[“host4”]}  
]  
}

In my recipe I am doing a search on the databag  
I will probably use a node attribute for the search, but for the moment it is  
just a string

I have tried:

allhosts = search(“demo\_databag”, “id:demo\_value”)

searchstring = "id:demo\_value"  
allhosts = search(“demo\_databag”, searchstring)

allhosts = search(“demo\_databag”, "demo\_value)

In all cases I get a return code of 256 and the loop I have written to process  
the values in the databag does not run

What am I doing wrong?
