Search code examples
rubychef-infrarecipe

Chef - execute vs bash resource


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 ?


Solution

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