0
votes

Just wondering, if its possible to search for a node before that node has completed the chef-client run.

Going by the chef docs: https://docs.getchef.com/essentials_nodes_chef_run.html

When all of the actions identified by resources in the resource collection have been done, and when the chef-client run finished successfully, the chef-client updates the node object on the Chef server with the node object that was built during this chef-client run. (This node object will be pulled down by the chef-client during the next chef-client run.) This makes the node object (and the data in the node object) available for search.

The chef-client always checks the resource collection for the presence of exception and report handlers. If any are present, each one is processed appropriately

So for example, I have a recipe that searchs for nodes with a role called "webserver". Im creating the chef node via pychef, and filling some attributes, and runlists (including that role in the run_list). Then launching the chef-client from the mahchine, it always fails to find any nodes with that role, as it has not been saved, so its not available for search.

Its easy to see with a knife search as the roles attribute of the returned search are empty (roles are still on the run_list) and when the chef-client finishes, then the roles are moved to the proper place, node.roles.

Is there a way I can force the node to be saved, before doing the search so it will appear in the results? Keeping the chef node in the chef server works, but it could be deleted some day and the search would not work anymore.

Thanks!

1
Nope. It's not possible. - sethvargo

1 Answers

1
votes

In general this is a bad idea for several reasons.

  1. Any Chef Server that uses the ACLs system (Enterprise Chef, Chef Server 12) has issues where manually creating node objects will break the permissions. The can be corrected manually, but this is a complex task.
  2. If your query is using the roles or recipes expanded forms, those have to be manually populated since that step is usually done by chef-client during run list expansion and then just saved back to the server.
  3. Having partial results in the search index often leads to service discovery failures where non-working services end up in production rotations.