[chef] Re: search in 0.9.8


Chronological Thread 
  • From: Ash Berlin < >
  • To:
  • Subject: [chef] Re: search in 0.9.8
  • Date: Mon, 27 Sep 2010 11:45:51 +0100

On 27 Sep 2010, at 10:55, Mike Scherbakov wrote:
Hi, 

What changes I missed in search statement syntax?
I'm trying to use search to find all nodes which have hpc::client recipe in chef 0.9.8:

clients = search(:node, "recipe:hpc::client)

The recipe is part of the run_list attribute, so you need to search in run_list[]. You also need to escape things ( '[' in particular) to solr with "". I find the easiest way of doing this is to use ruby's alternate quoting syntax. For example:

    nodes = search(:node, %Q{run_list:"role[#{app["server_roles"][0]}]" AND app_environment:#{node[:app_environment]}},

More simply (following what you are attempting to do):

    clients = search(:node %q{run_list:"recipe[hpc::client]"}

(The difference between %q{} and %Q{} is the same as between ' ' and " ".)

HTH
-ash

but getting Internal Server Error. In 0.8.x versions it worked. In log file on the chef server: 
FATAL: Search Query to Solr '/solr/select?rows=1000&sort=X_CHEF_id_CHEF_X+asc&start=0&indent=off&wt=ruby&fq=%2BX_CHEF_database_CHEF_X%3Achef+%2BX_CHEF_type_CHEF_X%3Anode&q=%2A' failed

clients = search(:node, "recipe:hpc") works just fine. I also tried "run_list:recipe\[hpc::client\]", the same error. What is the right way to use search? 

As a temporary solution, I use following _expression_:
clients = search(:node, "*:*").select { |e| e.run_list.run_list_items.select{ |i| i.name == "hpc::client" }.any? }.map{ |e| e["ipaddress"] }

Thanks,
--
Mike Scherbakov,
Grid Dynamics





Archive powered by MHonArc 2.6.16.

§