I have developed many automation solutions as shell scripts and it has been successfully being used in Prod/Dev environments. With Chef being introduced, I need to start using Chef as a future automation solution.

As a First Step, I am trying to integrate existing shell script solution to run within Chef and then convert the shellcodes to the chef at the later point.

I am new to Chef and have taken the basic fundamental course. So, Please help me how to run the existing shell scripts in Chef as a starting point.

I just need some basic examples, so that I can start to build from there.


1 Answer 1


From https://docs.chef.io/resource_execute.html,

execute 'my_script1' do
  command '/usr/local/bin/script1.sh'

This will call your script on each chef run.

  • Thanks Jason. To run above, i need to create cookbook and its respective resources,recipes etc., directories right? I may need step by step example with very simple example to understand the start to end including chef directories and its files involved. Commented Dec 7, 2016 at 20:57
  • 1
    A step-by-step on how to create a cookbook is a bit large in scope here, you can find lots of tutorials on Youtube or around the internet. Basically you'd have a cookbook that has a metadata.rb (see the examples), a 'files/default' directory and a 'recipes/default.rb' file. You'd put your script in files/default/. In default.rb, which would have a 'cookbook_file' resource that places the script onto the host, and the above execute command. You'd then upload the cookbook to the chef server and add recipe[COOKBOOKNAME] to the runlist of your node. Commented Dec 8, 2016 at 4:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .