Chef - execute vs bash resource

JahMyst picture JahMyst · Mar 7, 2016 · Viewed 12k times · Source

I used both the execute resource or the bash resource.

Both achieve the same result:

bash 'Execute my script' do 
  user 'root'
  cwd  '/mydir'
  code <<-EOH
    ./myscript.sh
  EOH
end

execute 'Execute my script' do 
  user    'root'
  cwd     '/mydir'
  command './myscript.sh'
end

The only difference I see is that bash actually creates a shell script (named /tmp/chef-script#{date}{#id}) where code is written.

What is the best practice to execute a shell script with Chef between execute or bash resource ?

Answer

coderanger picture coderanger · Mar 7, 2016

For a single script, use an execute. The bash resource is for including the script contents inline in the recipe code.