# Why I cannot search by recipes attribute only. Other attributes in search are still working

**URL:** <https://discourse.chef.io/t/why-i-cannot-search-by-recipes-attribute-only-other-attributes-in-search-are-still-working/4332>\
**Category:** Chef Infra (archive)\
**Created:** [August 20, 2013, 6:27am UTC](https://discourse.chef.io/t/why-i-cannot-search-by-recipes-attribute-only-other-attributes-in-search-are-still-working/4332 "2013-08-20T06:27:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vladimir\_Skubriev](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/vladimir_skubriev/32/263_2.png) [@Vladimir\_Skubriev](https://discourse.chef.io/u/Vladimir_Skubriev)\
**Post date:** [August 20, 2013, 6:27am UTC](https://discourse.chef.io/t/why-i-cannot-search-by-recipes-attribute-only-other-attributes-in-search-are-still-working/4332/1 "2013-08-20T06:27:36Z")

</div>

$knife search node “recipes:cftp”

knife search node “hostname:zeus” -l | grep -C 10 recipes  
metric: 256  
proto: kernel  
state: unknown  
type: vnet  
ohai\_time: 1376978220.81941  
os: linux  
os\_version: 3.5.0-34-generic  
platform: ubuntu  
platform\_family: debian  
platform\_version: 12.04  
recipes:  
apt  
ntp  
cftp  
cnfs::server  
cinotify  
nut  
fail2ban  
csquiddebproxy::server  
csquiddebproxy  
cbacula::client

OR other example:

knife search node “roles:ntp\_server” -l | grep -C 10 roles  
apt  
ntp  
cftp  
cnfs::server  
cinotify  
nut  
fail2ban  
csquiddebproxy::server  
csquiddebproxy  
cbacula::client  
roles:  
ntp\_server  
nut\_apcrt5000xl\_serverroom\_server  
uptime: 6 days 21 hours 09 minutes 00 seconds  
uptime\_seconds: 594540  
virtualization:  
role: host  
system: kvm

What is the difference between roles and recipes attributes. Why with  
recipes search are not work ?

Thank you very much.

–  
Best regards,

CVisionLab System Administrator  
Vladmir Skubriev

---

<div class="post-metadata">

**Author:** ![Ranjib](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/ranjib/32/1040_2.png) [@Ranjib](https://discourse.chef.io/u/Ranjib)\
**Post date:** [August 20, 2013, 7:00am UTC](https://discourse.chef.io/t/why-i-cannot-search-by-recipes-attribute-only-other-attributes-in-search-are-still-working/4332/2 "2013-08-20T07:00:06Z")

</div>

Recipes and roles are two node attributes, populated during node building,  
as part of chef run (check client.rb for phases in a chef run). Iteresting  
values of these two attributes comes from run list expansions, which  
populates an array of recipe as it parses the items in run list. Note, both  
are automatic attributes, some thing similar to ohai.  
Now,  
if you want to check all recipes against a node, if you can use the  
run\_context.loaded\_recipes (most probably). this trick will work as long as  
you are searching against the current running node and the recipe you are  
searching is included before the code block where you are checking this.

We internally use a handler that exposes these info as  
node.chef\_metrics.loaded\_recipes (with few other staff).

> <https://github.com/chef/chef/blob/main/lib/chef/node.rb#L243>

> <https://github.com/chef/chef/blob/main/lib/chef/node.rb#L331>

> <https://github.com/chef/chef/blob/main/lib/chef/node.rb#L332>

> <https://github.com/chef/chef/blob/main/lib/chef/run_list/run_list_expansion.rb#L148>

On Mon, Aug 19, 2013 at 11:27 PM, Vladimir Skubriev \<[skubriev@cvisionlab.com](mailto:skubriev@cvisionlab.com)

> wrote:

> $knife search node "recipes:cftp"
> 
> knife search node "hostname:zeus" -l | grep -C 10 recipes  
> metric: 256  
> proto: kernel  
> state: unknown  
> type: vnet  
> ohai\_time: 1376978220.81941  
> os: linux  
> os\_version: 3.5.0-34-generic  
> platform: ubuntu  
> platform\_family: debian  
> platform\_version: 12.04  
> recipes:  
> apt  
> ntp  
> cftp  
> cnfs::server  
> cinotify  
> nut  
> fail2ban  
> csquiddebproxy::server  
> csquiddebproxy  
> cbacula::client
> 
> OR other example:
> 
> knife search node "roles:ntp\_server" -l | grep -C 10 roles  
> apt  
> ntp  
> cftp  
> cnfs::server  
> cinotify  
> nut  
> fail2ban  
> csquiddebproxy::server  
> csquiddebproxy  
> cbacula::client  
> roles:  
> ntp\_server  
> nut\_apcrt5000xl\_serverroom\_\*\*server  
> uptime: 6 days 21 hours 09 minutes 00 seconds  
> uptime\_seconds: 594540  
> virtualization:  
> role: host  
> system: kvm
> 
> What is the difference between roles and recipes attributes. Why with  
> recipes search are not work ?
> 
> Thank you very much.
> 
> --  
> Best regards,
> 
> CVisionLab System Administrator  
> Vladmir Skubriev

---

<div class="post-metadata">

**Author:** ![Bryan\_McLellan](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/bryan_mclellan/32/81_2.png) [@Bryan\_McLellan](https://discourse.chef.io/u/Bryan_McLellan)\
**Post date:** [August 20, 2013, 2:54pm UTC](https://discourse.chef.io/t/why-i-cannot-search-by-recipes-attribute-only-other-attributes-in-search-are-still-working/4332/3 "2013-08-20T14:54:48Z")

</div>

On Tue, Aug 20, 2013 at 2:27 AM, Vladimir Skubriev  
[skubriev@cvisionlab.com](mailto:skubriev@cvisionlab.com) wrote:

> What is the difference between roles and recipes attributes. Why with  
> recipes search are not work ?

In addition to Ranjib's explanation, there's documentation here:

> **[About Search](https://docs.chef.io/chef_search/)**
>
> Search indexes allow queries to be made for any type of data that is indexed by the Chef Infra Server, including data bags (and data bag items), environments, nodes, and roles.

> **[About Search](https://docs.chef.io/chef_search/)**
>
> Search indexes allow queries to be made for any type of data that is indexed by the Chef Infra Server, including data bags (and data bag items), environments, nodes, and roles.

Bryan
