rp346
rp346

Reputation: 7068

How to chef search for role with OR

I want to search nodes with role "mapreduce-datanode" & "mapreduce-namenode".

So i tried following :

hadoop_nodes = search(:node, "role:mapreduce-datanode OR role:mapreduce-namenode AND chef_environment:#{node.chef_environment} AND domain:#{node['domain']}")

Is this correct way to do ?

Thanks.

Upvotes: 0

Views: 81

Answers (1)

Tejay Cardon
Tejay Cardon

Reputation: 4223

If you want "mapreduce-datanode" & "mapreduce-namenode", as you state, then why are you using an OR?

If you really want an AND, then you want:

hadoop_nodes = search(:node, "role:mapreduce-datanode AND role:mapreduce-namenode AND chef_environment:#{node.chef_environment} AND domain:#{node['domain']}")

If you want the union of the two sets (ie you really did mean OR) then try this:

hadoop_nodes = search(:node, "(role:mapreduce-datanode OR role:mapreduce-namenode) AND chef_environment:#{node.chef_environment} AND domain:#{node['domain']}")

Upvotes: 1

Related Questions