Knife search weirdness. What am I doing wrong here?

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

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

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

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

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

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

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:

knife-plugins/grep.rb at master · danielsdeleo/knife-plugins · GitHub

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

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

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:

knife-plugins/grep.rb at master · danielsdeleo/knife-plugins · GitHub

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

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

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: Post-Hoc Index Design: From Regex to PEG - Chef Blog | Chef

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

knife-plugins/grep.rb at master · danielsdeleo/knife-plugins · GitHub

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