I'm managing some scripts that can only be run on one server. I've decided the best way to single out one host that is assigned to a given role is by doing a search and then choosing the first element in the array returned.
Like this:
q = "roles:thumper"
arr = search(:node, q, filter_result: { fqdn: ['fqdn'] }).map { |n| n['fqdn'] }
# => ["1.example", "2.example"]
arr.first
# "1.example"
This works well in reality and chef-shell, but has difficulties in Test Kitchen where I am being returned an HTTP 500 on the search command.
================================================================================
Recipe Compile Error in /tmp/kitchen/cache/cookbooks/test/recipes/full.rb
================================================================================
Net::HTTPFatalError
-------------------
500 "Internal Server Error"
I am using chef_zero with the vagrant driver. Is there anything special that must be done to let search functionality work in this type of scenario?
Integration json:
{
"id": "thumper",
"environment": "food",
"run_list": ["role["thumper]"],
"automatic": {
"fqdn": "thumper",
"ipaddress": "10.10.10.10",
"roles": ["thumper"],
"environment": "food"
}
}
Fixtures data is just calling the relevant cookbooks
include_recipe 'test_helpers'
include_recipe 'role_thumper'