0
votes

I have two ruby blocks at the end of a recipe:

ruby_block 'set permissions for app dir' do
  block do
    require 'fileutils'
    FileUtils.chown_R 'user01', 'user01', '/mnt/app/'
  end
  action :run
end

ruby_block 'configure node app session' do
  block do
    cmd = "sudo su - user01 -c \"/mnt/app/http-app-/bin/app create /mnt/app/http-app/#{node['hostname']}\" && sudo su -c 'systemctl enable app' && sudo su -c 'systemctl start app'"
exec(cmd)
  end
  action :run
  not_if "stat -c %U /mnt/app/#{node['hostname']} |grep app"
end

A couple strange things are happening. One, I cannot add any code after the last block... it will not run if added. Two, when the cookbook runs the recipe never ends with if the run failed or was successful. Bootstrapping the system a second time will prove to finish successful... but ssh'ing to the box and running chef-client comes back with an empty run list.

Can anyone explain this behavior? How can i fix it?

1

1 Answers

1
votes

exec() is not what you think. That's a Ruby core method which calls the actual exec() syscall, which replaces the current process with something new. What you want is our shell_out!() helper which runs a subcommand and returns and object with the results.