How to run a bash script file in a chef?

I wrote a short bash script and saved it in files/default/bash.sh

How do I bind it to run it in my main default recipe? It should work like sudo because I am on an ubuntu system.

+5
source share
2 answers

After searching high and low, I finally found the answer:

 cookbook_file "/tmp/lib-installer.sh" do source "lib-installer.sh" mode 0755 end execute "install my lib" do command "sh /tmp/lib-installer.sh" end 

Thanks to this link !

+12
source

You can also include the script directly in your recipe if it is not too long using a bash resource . By default, any program executed by Chef uses the same user as Chef, as a rule, it is already root. You can use the user parameter for things like execute and bash to switch to another user or simply explicitly indicate that it must be root in order to make things self-documenting.

+1
source

Source: https://habr.com/ru/post/1209839/


All Articles