Unable to define top level field "automatic" in a chef knife search node

196 Views Asked by At

I would like to specifically use the automatic_name:server in the command line "knife search node".

Any advise on how to accomplish this, would be greatly appreciated.

When coding against the server, node.automatic['name'] is available. Also, when exporting to json, the jq query shows that automatic is part of the server data held within chef. So, not sure why knife search node does not recognize/honor automatic.

The following shows that the knife search does not return when automatic is declared.

# knife search node -i "automatic_name:server"
0 items found

# knife search node -i "name:server"
1 items found

# knife node show server -Fj -l > server.json
# jq '.automatic.name' server.json
"server"

Thanks in advance. wcm

1

There are 1 best solutions below

0
seshadri_c On

The knife search subcommand searches the data "indexed" by the Chef server. Also the multi-level (deep) JSON structure is flattened to top-level:

A nested field appears deeper in the JSON data structure. For example, information. about a network interface might be several layers deep: node['network']['interfaces']['en1']. When nested fields are present in a JSON structure, Chef Infra Client will extract those nested fields to the top-level, flattening them into compound fields that support wildcard search patterns.

Consider a node's following "automatic" attributes in JSON:

  "automatic": {
    "kernel": {
      "os_info": {
        "truncated": "lines",
        "build_number": "17763",
        "code_set": "1252",
        "truncated": "lines"
      }
    }
  } 

If I wanted to search on build_number or code_set, I would search it as (if) it is available at top-level:

~$ knife search node "build_number:17763"
1 items found

~$ knife search node "code_set:1252"
1 items found

In your case also, "automatic" is being honored. The server information is flattened to the top-level, and is searchable without having to prefix it with automatic.