[chef] Listing all cookbooks used in an environment


Chronological Thread 
  • From: DV < >
  • To:
  • Subject: [chef] Listing all cookbooks used in an environment
  • Date: Mon, 6 May 2013 15:43:39 -0700

Hey all,

So I've been trying to write a script which will show me which cookbooks are used in an environment that are not version-locked.

I thought I have it all figured out, with the following command fetching a list of cookbooks used in an environment. It collects "recipes" attribute of all nodes in the environment and extracts cookbook names:

knife search node "chef_environment:${CHEF_ENVIRONMENT}" -a recipes| grep -v -e ^id -e ^recipes -e found$ -e ^$ | awk -F':' '{print $1}' | sed 's/^ *//; s/; */;/g' |sort|uniq

The command does its job, but it has a major downside: it doesn't list cookbooks that are not explicitly listed in the "recipes" attribute. So, for example, if "tomcat" cookbook calls "java" cookbook, and "tomcat" cookbook is assigned to some node in the environment, the command above will list "tomcat" but not "java".

Is there a better way to fetch a list of cookbooks? Or should I add logic to resolve cookbook dependencies? Thanks.

--
Best regards, Dmitriy V.



Archive powered by MHonArc 2.6.16.

§