jmvbxx
jmvbxx

Reputation: 1046

How to run a bash script file in chef?

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

How do I link it to get it to run in my main default recipe? It needs to run as sudo because I'm on an ubuntu system.

Upvotes: 13

Views: 17711

Answers (2)

coderanger
coderanger

Reputation: 54267

You can also include the script directly in your recipe if it isn't too long via the bash resource. By default any program run by Chef uses the same user as Chef is running as, which is usually root already. You can use the user parameter to things like execute and bash to switch to a different user or just explicitly state that it should be root to make things self-documenting a tad.

Upvotes: 3

jmvbxx
jmvbxx

Reputation: 1046

After searching high and low I finally found an 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!

Upvotes: 20

Related Questions