Hello Chef community!
We've been looking into gathering the values a chef recipe maps and pushes to resources. We'd like to write something that runs within our recipe codebase that extracts that information after a successful/failed Chef-client run.
In hopes to illustrate:
[High level flow of events]
-
Chef node runs chef-client using recipe [ABC], defining the property node_name as 'Joe' -->
-
Recipe [ABC] passes node_name 'JoesComputer' onto a custom Resource [XYZ] --->
-
Resource [XYZ] uses an action to fill-in the properties passed to it into another Resource [123] (example: Resource [123] is a dsc_resource) --->
-
dsc_resource [123] has a required property named 'hostname' (which will be ' dsc_resource [123]')
-
dsc_resource [123] maps all properties passed to it and the node runs through dsc with hostname set to ' JoesComputer'
Though crudely described, chef-client is essentially doing this and only logging it during execution.
We want to extract the final mapped properties of our resources that chef is 'translating' from the recipe level.
Digging through the repos, we found something that might be what we'
re looking for in run_context: chef/lib/chef/run_context.rb at main · chef/chef · GitHub
We think that either method immediate_notification_collection, or resource_collection at some point would be able to provide us with that information.
There was chat that a compile-converge existed at one point, but no longer exists.
Though likely not pretty, even having an array of hashtable output to sift through would be wonderful.
We've been playing around with making a copy of a recipe to run that intentionally fails on our nodes to extract the errors for each resource. That looks to be hitting the ErrorInspectors module under ln.47 here:
We thought we could be cheeky and try to wrap the recipes to utilize a lazy evaluation, but not getting any hits.
Reaching out here in hopes someone has done something similar.
Thanks for reading!