Knife search weirdness. What am I doing wrong here?


#1

I wrote an ohai plugin that puts crontab data in node attributes. The
idea was that I wanted to be able to use knife to search for servers
with particular cron jobs. Unfortunately, knife search isn’t
cooperating with me. :confused:

You can see below that using a wildcard for search will return a
result, but specifying something that is obviously in the output below
yields no results. Am I just getting the syntax wrong?

bash-3.2$ knife search node “hostname:dc02vg0039nr* AND
crontabs_root_all_lines:*” -a crontabs
1 items found

crontabs:
root:
all_lines: # Chef Name: chef-client

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
SHELL=/bin/bash
36 * * * * /usr/local/bin/chef-client > /dev/null 2>&1
crons: [“36 * * * * /usr/local/bin/chef-client > /dev/null 2>&1”]
id: dc02vg0039nr.internal

bash-3.2$ knife search node “hostname:dc02vg0039nr* AND
crontabs_root_all_lines:chef” -a crontabs
0 items found

O’RLY? WTF? :slight_smile:

Thanks
John


#2

I think you can only use one * in a search term.

knife search node “crontabs_root_all_lines:chef
or crontabs_root_all_lines:chef
” -a crontabs

On Tue, Feb 14, 2012 at 1:46 PM, John Alberts john.m.alberts@gmail.comwrote:

I wrote an ohai plugin that puts crontab data in node attributes. The
idea was that I wanted to be able to use knife to search for servers
with particular cron jobs. Unfortunately, knife search isn’t
cooperating with me. :confused:

You can see below that using a wildcard for search will return a
result, but specifying something that is obviously in the output below
yields no results. Am I just getting the syntax wrong?

bash-3.2$ knife search node “hostname:dc02vg0039nr* AND
crontabs_root_all_lines:*” -a crontabs
1 items found

crontabs:
root:
all_lines: # Chef Name: chef-client

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
SHELL=/bin/bash
36 * * * * /usr/local/bin/chef-client > /dev/null 2>&1
crons: [“36 * * * * /usr/local/bin/chef-client > /dev/null 2>&1”]
id: dc02vg0039nr.internal

bash-3.2$ knife search node “hostname:dc02vg0039nr* AND
crontabs_root_all_lines:chef” -a crontabs
0 items found

O’RLY? WTF? :slight_smile:

Thanks
John


#3

Yeah, I think you are right.

Well, this kind of sucks. :frowning: It ruins my idea of trying to search for
a cronjob. There is no way to actually have knife search that field.
I tried using ‘*chef’ to match the chef-client line, but that returned
0 results as well.

Does anyone know if there is a way to match a substring in a value?

So if my key has a value “blah blah chef-client blah blah”, I can find it?

John

On Tue, Feb 14, 2012 at 2:28 PM, andi abes andi.abes@gmail.com wrote:

I think you can only use one * in a search term.

knife search node “crontabs_root_all_lines:chef
or crontabs_root_all_lines:chef
” -a crontabs

On Tue, Feb 14, 2012 at 1:46 PM, John Alberts john.m.alberts@gmail.com
wrote:

I wrote an ohai plugin that puts crontab data in node attributes. The
idea was that I wanted to be able to use knife to search for servers
with particular cron jobs. Unfortunately, knife search isn’t
cooperating with me. :confused:

You can see below that using a wildcard for search will return a
result, but specifying something that is obviously in the output below
yields no results. Am I just getting the syntax wrong?

bash-3.2$ knife search node “hostname:dc02vg0039nr* AND
crontabs_root_all_lines:*” -a crontabs
1 items found

crontabs:
root:
all_lines: # Chef Name: chef-client

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
SHELL=/bin/bash
36 * * * * /usr/local/bin/chef-client > /dev/null 2>&1
crons: [“36 * * * * /usr/local/bin/chef-client > /dev/null 2>&1”]
id: dc02vg0039nr.internal

bash-3.2$ knife search node “hostname:dc02vg0039nr* AND
crontabs_root_all_lines:chef” -a crontabs
0 items found

O’RLY? WTF? :slight_smile:

Thanks
John


John Alberts


#4

On Tuesday, February 14, 2012 at 2:40 PM, John Alberts wrote:

Yeah, I think you are right.

Well, this kind of sucks. :frowning: It ruins my idea of trying to search for
a cronjob. There is no way to actually have knife search that field.
I tried using ‘*chef’ to match the chef-client line, but that returned
0 results as well.

Does anyone know if there is a way to match a substring in a value?

So if my key has a value “blah blah chef-client blah blah”, I can find it?

John

On Tue, Feb 14, 2012 at 2:28 PM, andi abes <andi.abes@gmail.com (mailto:andi.abes@gmail.com)> wrote:

I think you can only use one * in a search term.

knife search node “crontabs_root_all_lines:chef
or crontabs_root_all_lines:chef
” -a crontabs

You can definitely have more than one wildcard character in a search term. For example:

As for your search issue, putting too much data in the node will probably trigger this bug:

http://tickets.opscode.com/browse/CHEF-2346


Dan DeLeo


#5

can you make your ohai plugin smarter in terms of parsing the cron lines,
and split the timing info from the actual command?
if you produce something like:

[ { “timing”: " * * * *" , “cmdline”: “chef-client”… } { …} ]

On Tue, Feb 14, 2012 at 5:40 PM, John Alberts john.m.alberts@gmail.comwrote:

Yeah, I think you are right.

Well, this kind of sucks. :frowning: It ruins my idea of trying to search for
a cronjob. There is no way to actually have knife search that field.
I tried using ‘*chef’ to match the chef-client line, but that returned
0 results as well.

Does anyone know if there is a way to match a substring in a value?

So if my key has a value “blah blah chef-client blah blah”, I can find it?

John

On Tue, Feb 14, 2012 at 2:28 PM, andi abes andi.abes@gmail.com wrote:

I think you can only use one * in a search term.

knife search node “crontabs_root_all_lines:chef
or crontabs_root_all_lines:chef
” -a crontabs

On Tue, Feb 14, 2012 at 1:46 PM, John Alberts john.m.alberts@gmail.com
wrote:

I wrote an ohai plugin that puts crontab data in node attributes. The
idea was that I wanted to be able to use knife to search for servers
with particular cron jobs. Unfortunately, knife search isn’t
cooperating with me. :confused:

You can see below that using a wildcard for search will return a
result, but specifying something that is obviously in the output below
yields no results. Am I just getting the syntax wrong?

bash-3.2$ knife search node “hostname:dc02vg0039nr* AND
crontabs_root_all_lines:*” -a crontabs
1 items found

crontabs:
root:
all_lines: # Chef Name: chef-client

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
SHELL=/bin/bash
36 * * * * /usr/local/bin/chef-client > /dev/null 2>&1
crons: [“36 * * * * /usr/local/bin/chef-client > /dev/null
2>&1”]

id: dc02vg0039nr.internal

bash-3.2$ knife search node “hostname:dc02vg0039nr* AND
crontabs_root_all_lines:chef” -a crontabs
0 items found

O’RLY? WTF? :slight_smile:

Thanks
John


John Alberts


#6

Why even try to find systems by what crontab they have? Surely this is
overcomplicating things.

Adjust the cron from a recipe. Run the recipe from a role. Search for
the system with the role… profit?

Regards,

–AJ

On 15 February 2012 11:45, andi abes andi.abes@gmail.com wrote:

can you make your ohai plugin smarter in terms of parsing the cron lines,
and split the timing info from the actual command?
if you produce something like:

[ { “timing”: " * * * *" , “cmdline”: “chef-client”… } { …} ]

On Tue, Feb 14, 2012 at 5:40 PM, John Alberts john.m.alberts@gmail.com
wrote:

Yeah, I think you are right.

Well, this kind of sucks. :frowning: It ruins my idea of trying to search for
a cronjob. There is no way to actually have knife search that field.
I tried using ‘*chef’ to match the chef-client line, but that returned
0 results as well.

Does anyone know if there is a way to match a substring in a value?

So if my key has a value “blah blah chef-client blah blah”, I can find it?

John

On Tue, Feb 14, 2012 at 2:28 PM, andi abes andi.abes@gmail.com wrote:

I think you can only use one * in a search term.

knife search node “crontabs_root_all_lines:chef
or crontabs_root_all_lines:chef
” -a crontabs

On Tue, Feb 14, 2012 at 1:46 PM, John Alberts john.m.alberts@gmail.com
wrote:

I wrote an ohai plugin that puts crontab data in node attributes. The
idea was that I wanted to be able to use knife to search for servers
with particular cron jobs. Unfortunately, knife search isn’t
cooperating with me. :confused:

You can see below that using a wildcard for search will return a
result, but specifying something that is obviously in the output below
yields no results. Am I just getting the syntax wrong?

bash-3.2$ knife search node “hostname:dc02vg0039nr* AND
crontabs_root_all_lines:*” -a crontabs
1 items found

crontabs:
root:
all_lines: # Chef Name: chef-client

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
SHELL=/bin/bash
36 * * * * /usr/local/bin/chef-client > /dev/null 2>&1
crons: [“36 * * * * /usr/local/bin/chef-client > /dev/null
2>&1”]
id: dc02vg0039nr.internal

bash-3.2$ knife search node “hostname:dc02vg0039nr* AND
crontabs_root_all_lines:chef” -a crontabs
0 items found

O’RLY? WTF? :slight_smile:

Thanks
John


John Alberts


#7

hu!
Guess I’m out of date… I recall this was a restriction at some point. Is
this a recent change? (or am I loosing my mind?)

On Tue, Feb 14, 2012 at 5:45 PM, Daniel DeLeo dan@kallistec.com wrote:

On Tuesday, February 14, 2012 at 2:40 PM, John Alberts wrote:

Yeah, I think you are right.

Well, this kind of sucks. :frowning: It ruins my idea of trying to search for
a cronjob. There is no way to actually have knife search that field.
I tried using ‘*chef’ to match the chef-client line, but that returned
0 results as well.

Does anyone know if there is a way to match a substring in a value?

So if my key has a value “blah blah chef-client blah blah”, I can find
it?

John

On Tue, Feb 14, 2012 at 2:28 PM, andi abes <andi.abes@gmail.com (mailto:
andi.abes@gmail.com)> wrote:

I think you can only use one * in a search term.

knife search node “crontabs_root_all_lines:chef
or crontabs_root_all_lines:chef
” -a crontabs

You can definitely have more than one wildcard character in a search term.
For example:

https://github.com/danielsdeleo/knife-plugins/blob/master/grep.rb#L20

As for your search issue, putting too much data in the node will probably
trigger this bug:

http://tickets.opscode.com/browse/CHEF-2346


Dan DeLeo


#8

Or even better if you really need this information (which I can
actually think of reasons), have the data in ohai look like this:

“cron”:{
“some_job_name”:{
“minute”:"",
“hour”:"",
“day”:"",
“command”:“foo command.sh arg1”

You get the idea. it doesn’t express cleanly but it works and, like I
said, I can see a use case over doing it in a cookbook.

On Tue, Feb 14, 2012 at 5:45 PM, andi abes andi.abes@gmail.com wrote:

can you make your ohai plugin smarter in terms of parsing the cron lines,
and split the timing info from the actual command?
if you produce something like:

[ { “timing”: " * * * *" , “cmdline”: “chef-client”… } { …} ]

On Tue, Feb 14, 2012 at 5:40 PM, John Alberts john.m.alberts@gmail.com
wrote:

Yeah, I think you are right.

Well, this kind of sucks. :frowning: It ruins my idea of trying to search for
a cronjob. There is no way to actually have knife search that field.
I tried using ‘*chef’ to match the chef-client line, but that returned
0 results as well.

Does anyone know if there is a way to match a substring in a value?

So if my key has a value “blah blah chef-client blah blah”, I can find it?

John

On Tue, Feb 14, 2012 at 2:28 PM, andi abes andi.abes@gmail.com wrote:

I think you can only use one * in a search term.

knife search node “crontabs_root_all_lines:chef
or crontabs_root_all_lines:chef
” -a crontabs

On Tue, Feb 14, 2012 at 1:46 PM, John Alberts john.m.alberts@gmail.com
wrote:

I wrote an ohai plugin that puts crontab data in node attributes. The
idea was that I wanted to be able to use knife to search for servers
with particular cron jobs. Unfortunately, knife search isn’t
cooperating with me. :confused:

You can see below that using a wildcard for search will return a
result, but specifying something that is obviously in the output below
yields no results. Am I just getting the syntax wrong?

bash-3.2$ knife search node “hostname:dc02vg0039nr* AND
crontabs_root_all_lines:*” -a crontabs
1 items found

crontabs:
root:
all_lines: # Chef Name: chef-client

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
SHELL=/bin/bash
36 * * * * /usr/local/bin/chef-client > /dev/null 2>&1
crons: [“36 * * * * /usr/local/bin/chef-client > /dev/null
2>&1”]
id: dc02vg0039nr.internal

bash-3.2$ knife search node “hostname:dc02vg0039nr* AND
crontabs_root_all_lines:chef” -a crontabs
0 items found

O’RLY? WTF? :slight_smile:

Thanks
John


John Alberts


#9

On Tue, Feb 14, 2012 at 4:45 PM, Daniel DeLeo dan@kallistec.com wrote:

You can definitely have more than one wildcard character in a search term. For example:

https://github.com/danielsdeleo/knife-plugins/blob/master/grep.rb#L20

As for your search issue, putting too much data in the node will probably trigger this bug:

http://tickets.opscode.com/browse/CHEF-2346

That’s right. I completely forget about knife grep. I use that and it
works fine for me. I must be hitting the Chef bug you mentioend.
Thanks for pointing that out.

John


#10

On Tue, Feb 14, 2012 at 4:49 PM, AJ Christensen aj@junglist.gen.nz wrote:

Why even try to find systems by what crontab they have? Surely this is
overcomplicating things.

Adjust the cron from a recipe. Run the recipe from a role. Search for
the system with the role… profit?

Very true and I do this for most things. The reason for this is I
have a very legacy infrastructure that is only partially automated and
I need to get a list of servers that have a particular cron job that
was manually entered.

John


#11

On Tuesday, February 14, 2012 at 3:13 PM, andi abes wrote:

hu!
Guess I’m out of date… I recall this was a restriction at some point. Is this a recent change? (or am I loosing my mind?)

In Chef 0.8.x and 0.9.x, you could have multiple wildcards, but you could not have wildcards in the key part of the query, and you could not have a wildcard at the start of the value part of the query. Thanks to the new “no fields” index layout, you can now have wildcards in the key (but not at the beginning of the key) and anywhere in the value.

See also: http://www.opscode.com/blog/2012/01/20/post-hoc-index-design-from-regex-to-peg/


Dan DeLeo

On Tue, Feb 14, 2012 at 5:45 PM, Daniel DeLeo <dan@kallistec.com (mailto:dan@kallistec.com)> wrote:

On Tuesday, February 14, 2012 at 2:40 PM, John Alberts wrote:

Yeah, I think you are right.

Well, this kind of sucks. :frowning: It ruins my idea of trying to search for
a cronjob. There is no way to actually have knife search that field.
I tried using ‘*chef’ to match the chef-client line, but that returned
0 results as well.

Does anyone know if there is a way to match a substring in a value?

So if my key has a value “blah blah chef-client blah blah”, I can find it?

John

On Tue, Feb 14, 2012 at 2:28 PM, andi abes <andi.abes@gmail.com (mailto:andi.abes@gmail.com) (mailto:andi.abes@gmail.com)> wrote:

I think you can only use one * in a search term.

knife search node “crontabs_root_all_lines:chef
or crontabs_root_all_lines:chef
” -a crontabs

You can definitely have more than one wildcard character in a search term. For example:

https://github.com/danielsdeleo/knife-plugins/blob/master/grep.rb#L20

As for your search issue, putting too much data in the node will probably trigger this bug:

http://tickets.opscode.com/browse/CHEF-2346


Dan DeLeo