Search code examples
chef-infrachef-recipeknife

Getting node information from chef recipe


Is it possible to easily access the information about the node (similar to knife node show) from a recipe without running knife through the "execute" resource? I would like to do this in order to add information about the current runlist and maybe some more details regarding the node into motd for convenience.


Solution

  • Specifically for the run_list, if you do not care about order, the most straight forward way would likely be to get this from the Ohai attributes.

    node['recipes']
    node['roles']
    

    See: http://docs.getchef.com/ohai.html

    If you do care about order, then you may have to operate off of the node object.

    runlist = node.run_list
    

    Which may not be as apparent from the docs.

    You can access the rest of the node information in a similar manner.