Search in 0.9.8

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)
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

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

Thanks a lot! This is much more elegant than what I used :slight_smile:
I think this example should be published on wiki to allow others know this
trick.

On Mon, Sep 27, 2010 at 2:45 PM, Ash Berlin ash_opscode@firemirror.comwrote:

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

--
Mike Scherbakov,
Grid Dynamics

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello!

On Sep 27, 2010, at 5:38 AM, Mike Scherbakov wrote:

I think this example should be published on wiki to allow others know this trick

Yes, its a wiki, please add the example to:

http://wiki.opscode.com/display/chef/Search

in the section "Searching for nodes having a given recipe applied".

:smiley:


Opscode, Inc
Joshua Timberman, Technical Evangelist
IRC, Skype, Twitter, Github: jtimberman

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (Darwin)

iEYEARECAAYFAkygrHUACgkQO97WSdVpzT2qNACfUYyO3fp4tvwgePtP/bERHVC0
Z4UAn2VtrGPY0E6U9dCcJHbXy/jyOGnG
=AweB
-----END PGP SIGNATURE-----

On 27 Sep 2010, at 15:38, Joshua Timberman wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello!

On Sep 27, 2010, at 5:38 AM, Mike Scherbakov wrote:

I think this example should be published on wiki to allow others know this trick

Yes, its a wiki, please add the example to:

http://wiki.opscode.com/display/chef/Search

in the section "Searching for nodes having a given recipe applied".

:smiley:

Done: http://wiki.opscode.com/pages/diffpagesbyversion.action?pageId=1179830&selectedPageVersions=39&selectedPageVersions=38