-1

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.

Sven
  • 98,649
  • 14
  • 180
  • 226
CoolChap007
  • 13
  • 1
  • 3

1 Answers1

1

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

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

This will call your script on each chef run.

Jason Martin
  • 5,023
  • 17
  • 24
  • 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. – CoolChap007 Dec 07 '16 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. – Jason Martin Dec 08 '16 at 04:05