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.
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.
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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With