How to search node info in the chef server

Hi,

I want to get a node list with role[os-controller] in it’s run list, so I
tried “knife search” command at my chef server CML however I got a weird
result as follow:

[root@chefsrv ~]# knife search node role:os-controller2 items foundNode
Name: centos-10-145-88-153Environment: _defaultFQDN: IP:
10.145.88.153Run List: recipe[keepalived],
recipe[haproxy::tcp_lb]Roles: Recipes: keepalived,
haproxy::tcp_lb, keepalived::default, haproxy::install_packagePlatform:
centos 6.5Tags: Node Name: centos-10-145-88-152Environment:
testingFQDN: IP: 10.145.88.152Run List:
recipe[keepalived], recipe[haproxy::tcp_lb],
role[os-controller]Roles: Recipes: keepalived, haproxy::tcp_lb,
keepalived::default, haproxy::install_packagePlatform: centos
6.5Tags: [root@chefsrv ~]#

In my understanding, chef server should only return one node info with
role[os-controller] (here is centos-10-145-88-152), but it return two
nodes. I have no idea how to figure it out.

If someone can point it out, it will be much appreciated.

Thanks,
Sam

chef saves a two computed attributes, aka recipes and roles as part of run
list expansion. so, you want to search against 'roles:foo' (plural).
also some thing in your recipes sets an attribute (may be nested) 'role' ,
which might explains the first hit.
something like:
node[:a][:role] = 1,

On Wed, Mar 26, 2014 at 3:05 PM, Sam Su sam.debian@gmail.com wrote:

Hi,

I want to get a node list with role[os-controller] in it's run list, so I
tried "knife search" command at my chef server CML however I got a weird
result as follow:

[root@chefsrv ~]# knife search node role:os-controller2 items foundNode
Name: centos-10-145-88-153Environment: _defaultFQDN: IP:
10.145.88.153 Run List: recipe[keepalived],
recipe[haproxy::tcp_lb]Roles: Recipes: keepalived,
haproxy::tcp_lb, keepalived::default, haproxy::install_packagePlatform:
centos 6.5Tags: Node Name: centos-10-145-88-152 Environment:
testingFQDN: IP: 10.145.88.152Run List:
recipe[keepalived], recipe[haproxy::tcp_lb],
role[os-controller]Roles: Recipes: keepalived, haproxy::tcp_lb,
keepalived::default, haproxy::install_package Platform: centos
6.5Tags: [root@chefsrv ~]#

In my understanding, chef server should only return one node info with
role[os-controller] (here is centos-10-145-88-152), but it return two
nodes. I have no idea how to figure it out.

If someone can point it out, it will be much appreciated.

Thanks,
Sam

Hi Ranjib,

Thank you for your explanation.

If that is my case, do you have any idea to solve the problem?

Thanks,
Sam

On Wed, Mar 26, 2014 at 3:12 PM, Ranjib Dey dey.ranjib@gmail.com wrote:

chef saves a two computed attributes, aka recipes and roles as part of run
list expansion. so, you want to search against 'roles:foo' (plural).
also some thing in your recipes sets an attribute (may be nested) 'role' ,
which might explains the first hit.
something like:
node[:a][:role] = 1,

On Wed, Mar 26, 2014 at 3:05 PM, Sam Su sam.debian@gmail.com wrote:

Hi,

I want to get a node list with role[os-controller] in it's run list, so I
tried "knife search" command at my chef server CML however I got a weird
result as follow:

[root@chefsrv ~]# knife search node role:os-controller2 items foundNode
Name: centos-10-145-88-153Environment: _defaultFQDN: IP:
10.145.88.153 Run List: recipe[keepalived],
recipe[haproxy::tcp_lb]Roles: Recipes: keepalived,
haproxy::tcp_lb, keepalived::default, haproxy::install_packagePlatform:
centos 6.5Tags: Node Name: centos-10-145-88-152 Environment:
testingFQDN: IP: 10.145.88.152Run List:
recipe[keepalived], recipe[haproxy::tcp_lb],
role[os-controller]Roles: Recipes: keepalived, haproxy::tcp_lb,
keepalived::default, haproxy::install_package Platform: centos
6.5Tags: [root@chefsrv ~]#

In my understanding, chef server should only return one node info with
role[os-controller] (here is centos-10-145-88-152), but it return
two nodes. I have no idea how to figure it out.

If someone can point it out, it will be much appreciated.

Thanks,
Sam

i think i mentioned

knife search node roles:os-controller

On Wed, Mar 26, 2014 at 4:04 PM, Sam Su sam.debian@gmail.com wrote:

Hi Ranjib,

Thank you for your explanation.

If that is my case, do you have any idea to solve the problem?

Thanks,
Sam

On Wed, Mar 26, 2014 at 3:12 PM, Ranjib Dey dey.ranjib@gmail.com wrote:

chef saves a two computed attributes, aka recipes and roles as part of
run list expansion. so, you want to search against 'roles:foo' (plural).
also some thing in your recipes sets an attribute (may be nested) 'role'
, which might explains the first hit.
something like:
node[:a][:role] = 1,

On Wed, Mar 26, 2014 at 3:05 PM, Sam Su sam.debian@gmail.com wrote:

Hi,

I want to get a node list with role[os-controller] in it's run list, so
I tried "knife search" command at my chef server CML however I got a weird
result as follow:

[root@chefsrv ~]# knife search node role:os-controller2 items foundNode
Name: centos-10-145-88-153Environment: _defaultFQDN: IP:
10.145.88.153 Run List: recipe[keepalived],
recipe[haproxy::tcp_lb]Roles: Recipes: keepalived,
haproxy::tcp_lb, keepalived::default, haproxy::install_packagePlatform:
centos 6.5Tags: Node Name: centos-10-145-88-152 Environment:
testingFQDN: IP: 10.145.88.152Run List:
recipe[keepalived], recipe[haproxy::tcp_lb],
role[os-controller]Roles: Recipes: keepalived, haproxy::tcp_lb,
keepalived::default, haproxy::install_package Platform: centos
6.5Tags: [root@chefsrv ~]#

In my understanding, chef server should only return one node info with
role[os-controller] (here is centos-10-145-88-152), but it return
two nodes. I have no idea how to figure it out.

If someone can point it out, it will be much appreciated.

Thanks,
Sam

I tried the cmd but still no expected result:

[root@chefsrv ~]# knife search node 'roles:os-controller'0 items
found[root@chefsrv ~]#

When I tried the command as below, I can get my ideal result:

*[root@chefsrv ~]# knife search node 'run_list:role[os-controller]'1
items foundNode Name: centos-10-145-88-152Environment:
testingFQDN: IP: 10.145.88.152Run List:
recipe[keepalived], recipe[haproxy::tcp_lb],
role[os-controller]Roles: Recipes: keepalived, haproxy::tcp_lb,
keepalived::default, haproxy::install_packagePlatform: centos
6.5Tags: [root@chefsrv ~]# *

So I used it in my cookbook:
pool_members = search(:node, "run_list:role[#{service['role']}] AND
chef_environment:#{node.chef_environment}") || []

When I run it, I got the error as follow:

It is weird for me, if someone can point it out and share some experience,
I will be much appreciated.

Thanks,
Sam

On Wed, Mar 26, 2014 at 4:10 PM, Ranjib Dey dey.ranjib@gmail.com wrote:

i think i mentioned

knife search node roles:os-controller

On Wed, Mar 26, 2014 at 4:04 PM, Sam Su sam.debian@gmail.com wrote:

Hi Ranjib,

Thank you for your explanation.

If that is my case, do you have any idea to solve the problem?

Thanks,
Sam

On Wed, Mar 26, 2014 at 3:12 PM, Ranjib Dey dey.ranjib@gmail.com wrote:

chef saves a two computed attributes, aka recipes and roles as part of
run list expansion. so, you want to search against 'roles:foo' (plural).
also some thing in your recipes sets an attribute (may be nested) 'role'
, which might explains the first hit.
something like:
node[:a][:role] = 1,

On Wed, Mar 26, 2014 at 3:05 PM, Sam Su sam.debian@gmail.com wrote:

Hi,

I want to get a node list with role[os-controller] in it's run list, so
I tried "knife search" command at my chef server CML however I got a weird
result as follow:

[root@chefsrv ~]# knife search node role:os-controller2 items
foundNode Name: centos-10-145-88-153Environment: _defaultFQDN:
IP: 10.145.88.153 Run List: recipe[keepalived],
recipe[haproxy::tcp_lb]Roles: Recipes: keepalived,
haproxy::tcp_lb, keepalived::default, haproxy::install_packagePlatform:
centos 6.5Tags: Node Name: centos-10-145-88-152 Environment:
testingFQDN: IP: 10.145.88.152Run List:
recipe[keepalived], recipe[haproxy::tcp_lb],
role[os-controller]Roles: Recipes: keepalived, haproxy::tcp_lb,
keepalived::default, haproxy::install_package Platform: centos
6.5Tags: [root@chefsrv ~]#

In my understanding, chef server should only return one node info with
role[os-controller] (here is centos-10-145-88-152), but it return
two nodes. I have no idea how to figure it out.

If someone can point it out, it will be much appreciated.

Thanks,
Sam

After replaced '/' with '//', I finally got the chef search function work.

On Wed, Mar 26, 2014 at 5:03 PM, Sam Su sam.debian@gmail.com wrote:

I tried the cmd but still no expected result:

*[root@chefsrv ~]# knife search node 'roles:os-controller'0 items
found[root@chefsrv ~]# *
When I tried the command as below, I can get my ideal result:

  • [root@chefsrv ~]# knife search node 'run_list:role[os-controller]'1
    items foundNode Name: centos-10-145-88-152Environment: testing
    FQDN: IP: 10.145.88.152Run List: recipe[keepalived],
    recipe[haproxy::tcp_lb], role[os-controller]Roles: Recipes:
    keepalived, haproxy::tcp_lb, keepalived::default, haproxy::install_package
    Platform: centos 6.5Tags: [root@chefsrv ~]# *

So I used it in my cookbook:
pool_members = search(:node, "run_list:role[#{service['role']}] AND
chef_environment:#{node.chef_environment}") || []

When I run it, I got the error as follow:
chef search error - Pastebin.com

It is weird for me, if someone can point it out and share some experience,
I will be much appreciated.

Thanks,
Sam

On Wed, Mar 26, 2014 at 4:10 PM, Ranjib Dey dey.ranjib@gmail.com wrote:

i think i mentioned

knife search node roles:os-controller

On Wed, Mar 26, 2014 at 4:04 PM, Sam Su sam.debian@gmail.com wrote:

Hi Ranjib,

Thank you for your explanation.

If that is my case, do you have any idea to solve the problem?

Thanks,
Sam

On Wed, Mar 26, 2014 at 3:12 PM, Ranjib Dey dey.ranjib@gmail.comwrote:

chef saves a two computed attributes, aka recipes and roles as part of
run list expansion. so, you want to search against 'roles:foo' (plural).
also some thing in your recipes sets an attribute (may be nested)
'role' , which might explains the first hit.
something like:
node[:a][:role] = 1,

On Wed, Mar 26, 2014 at 3:05 PM, Sam Su sam.debian@gmail.com wrote:

Hi,

I want to get a node list with role[os-controller] in it's run list,
so I tried "knife search" command at my chef server CML however I got a
weird result as follow:

[root@chefsrv ~]# knife search node role:os-controller2 items
foundNode Name: centos-10-145-88-153Environment: _defaultFQDN:
IP: 10.145.88.153 Run List: recipe[keepalived],
recipe[haproxy::tcp_lb]Roles: Recipes: keepalived,
haproxy::tcp_lb, keepalived::default, haproxy::install_packagePlatform:
centos 6.5Tags: Node Name: centos-10-145-88-152 Environment:
testingFQDN: IP: 10.145.88.152Run List:
recipe[keepalived], recipe[haproxy::tcp_lb],
role[os-controller]Roles: Recipes: keepalived, haproxy::tcp_lb,
keepalived::default, haproxy::install_package Platform: centos
6.5Tags: [root@chefsrv ~]#

In my understanding, chef server should only return one node info with
role[os-controller] (here is centos-10-145-88-152), but it return
two nodes. I have no idea how to figure it out.

If someone can point it out, it will be much appreciated.

Thanks,
Sam

Sorry, just made a typo '/', it should be ''.

On Wed, Mar 26, 2014 at 8:25 PM, Sam Su sam.debian@gmail.com wrote:

After replaced '/' with '//', I finally got the chef search function work.

On Wed, Mar 26, 2014 at 5:03 PM, Sam Su sam.debian@gmail.com wrote:

I tried the cmd but still no expected result:

*[root@chefsrv ~]# knife search node 'roles:os-controller' 0 items
found[root@chefsrv ~]# *
When I tried the command as below, I can get my ideal result:

  • [root@chefsrv ~]# knife search node 'run_list:role[os-controller]'1
    items foundNode Name: centos-10-145-88-152Environment: testing
    FQDN: IP: 10.145.88.152Run List: recipe[keepalived],
    recipe[haproxy::tcp_lb], role[os-controller]Roles: Recipes:
    keepalived, haproxy::tcp_lb, keepalived::default, haproxy::install_package
    Platform: centos 6.5Tags: [root@chefsrv ~]# *

So I used it in my cookbook:
pool_members = search(:node, "run_list:role[#{service['role']}] AND
chef_environment:#{node.chef_environment}") || []

When I run it, I got the error as follow:
chef search error - Pastebin.com

It is weird for me, if someone can point it out and share some
experience, I will be much appreciated.

Thanks,
Sam

On Wed, Mar 26, 2014 at 4:10 PM, Ranjib Dey dey.ranjib@gmail.com wrote:

i think i mentioned

knife search node roles:os-controller

On Wed, Mar 26, 2014 at 4:04 PM, Sam Su sam.debian@gmail.com wrote:

Hi Ranjib,

Thank you for your explanation.

If that is my case, do you have any idea to solve the problem?

Thanks,
Sam

On Wed, Mar 26, 2014 at 3:12 PM, Ranjib Dey dey.ranjib@gmail.comwrote:

chef saves a two computed attributes, aka recipes and roles as part of
run list expansion. so, you want to search against 'roles:foo' (plural).
also some thing in your recipes sets an attribute (may be nested)
'role' , which might explains the first hit.
something like:
node[:a][:role] = 1,

On Wed, Mar 26, 2014 at 3:05 PM, Sam Su sam.debian@gmail.com wrote:

Hi,

I want to get a node list with role[os-controller] in it's run list,
so I tried "knife search" command at my chef server CML however I got a
weird result as follow:

[root@chefsrv ~]# knife search node role:os-controller2 items
foundNode Name: centos-10-145-88-153Environment: _defaultFQDN:
IP: 10.145.88.153 Run List: recipe[keepalived],
recipe[haproxy::tcp_lb]Roles: Recipes: keepalived,
haproxy::tcp_lb, keepalived::default, haproxy::install_packagePlatform:
centos 6.5Tags: Node Name: centos-10-145-88-152 Environment:
testingFQDN: IP: 10.145.88.152Run List:
recipe[keepalived], recipe[haproxy::tcp_lb],
role[os-controller]Roles: Recipes: keepalived, haproxy::tcp_lb,
keepalived::default, haproxy::install_package Platform: centos
6.5Tags: [root@chefsrv ~]#

In my understanding, chef server should only return one node info
with role[os-controller] (here is centos-10-145-88-152), but it
return two nodes. I have no idea how to figure it out.

If someone can point it out, it will be much appreciated.

Thanks,
Sam