Steve Bennett
Steve Bennett

Reputation: 126827

Convert Chef recipe to series of Bash commands?

Typically, one wants to convert Bash scripts to Chef. But sometimes (like, right now) you need to do the opposite. Is there an automatic way to get the list of commands run for a given Chef cookbook on a given configuration?

I'm not trying to end up with something with the full functionality of the Chef cookbook. I want to end up with a small set of commands that reproduce this particular installation on this particular environment. (The reason in this case is I need to separate out the 'sudo' commands and get them run by someone else. I do have sudo access on a machine that I could run Chef on to carry out this task though.)

Upvotes: 1

Views: 1154

Answers (1)

Andrea Campi
Andrea Campi

Reputation: 456

I doubt you can do that in general, and even if you could, it would likely be more work than implementing what you need in Chef.

For example, even something as simple as creating a configuration file is implemented in Chef as ruby code; you would need to figure out a way to turn that into echo "…" > /etc/whatever.com. Doing that for all resources would be a major undertaking.

It seems to me that what you should actually do is modify any Chef cookbook that you use to run commands as a different user.

Things like template and file are pretty easy: the file will be created as root, and then chown-ed to the correct user. execute resources (which run commands) can be configured to run the command with su simply by specifying the user:

execute "something" do
  command "whoami"
  user "nobody"
end

It might take you a while to figure out, but once you get the hang of it it's pretty easy; much easier than converting to bash.

Upvotes: 4

Related Questions