Chef search provides the ability to query data indexed on Chef Server. The search query runs on Chef Server and search results are returned to clients. Queries can be invoked by using
knife on the command line or from within a recipe. Typical queries are usually inventory related, such as a count and system names of all the computers that have particular operating system configurations or software installed. For example, searches for versions of the openssl library vulnerable to the Heartbleed Virus were quite popular as we were writing this book.
Let’s start by performing a search query with
knife on the command line. Use the chef-playground directory you created in Chapter 11. Use the same dual command prompt setup you used there. Start the
chef-zero server on an open port in one window. We will be using port 9501 in the examples in this chapter:
chef-zero --port 9501
Then, in the other window, make the chef-playground directory the current working directory and run the
knife upload nodes command to populate Chef Server with some test data about nodes:
knife upload nodesCreated nodes/susu.json Created nodes/atwood.json Created nodes/snowman.json
You can also perform searches in production on the command line with the
knife search command. The search query syntax with
knife is in the following form:
$ knife search <index> <search_query>
The index can be one of the following: ...