I'm having a problem with Chef and sh script. My sh script doing a few things and for each step, it echoes a message that something was done successfully or not. I want run this script in Chef, but it doesn't work and I can't see anything in the logs except that script was run with success which is not true. Here is how I'm doing this:
cookbook_file "/tmp/myLib.rpm" do
source "myLib.rpm"
mode '0775'
action :create
end
cookbook_file "/tmp/install.sh" do
source "install.sh"
mode '0755'
action :create
end
execute "installing my lib" do
command "sh /tmp/install.sh"
user 'root'
live_stream true
action :run
end
The script is done with success, but inside log I can see only:
Loading cookbooks [[email protected]]
INFO: *** Chef 12.18.31 ***
INFO: Storing updated cookbooks/security/recipes/install-mylib.rb in the cache.
INFO: Storing updated cookbooks/security/metadata.rb in the cache.
INFO: Storing updated cookbooks/security/files/default/install.sh in the cache.
INFO: Storing updated cookbooks/security/files/default/myLib.rpm in the cache.
INFO: Processing cookbook_file[/tmp/myLib.rpm] action create (security::install-mylib line 1)
INFO: Processing cookbook_file[/tmp/install.sh] action create (security::install-mylib line 7)
INFO: cookbook_file[/tmp/install.sh] created file /tmp/install.sh
INFO: cookbook_file[/tmp/install.sh] updated file contents /tmp/install.sh
INFO: cookbook_file[/tmp/install.sh] mode changed to 755
INFO: Processing execute[installing my lib] action run (security::install-mylib line 13)
INFO: execute[installing my lib] ran successfully
I can't see any echo from install.sh and work from this script is not done. When I run this script directly on the machine, everything work.
Any help or ideas would be really appreciated.
A better option to run a script would be to use the script resource. Although
executeresource should also work just fine.Try running your script with the
scriptresource, like below: