I would do something like this:

```ruby
nodes, start, total = Chef::Search::Query.new.search(:node, "roles:keystone-server AND keystone_config_environment:keystone-config-#{node[cookbook_name][:keystone_instance]}")

if total
  keystone_node = nodes.first
else
  keystone_node = node
end
```