Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 289
JahMyst Avatar asked Mar 07 '16 19:03

JahMyst


People also ask

What is Bash execute?

On Unix-like operating systems, exec is a builtin command of the Bash shell. It lets you execute a command that completely replaces the current process. The current shell process is destroyed, and entirely replaced by the command you specify. Options and arguments.

What are phases of Chef execution?

There are two stages to a chef run though. A compile phase, to organise what resources need to be run and resolve all variables. Then a run phase where each resource is actually executed.

What are chef resources?

Chef resource represents a piece of the operating system at its desired state. It is a statement of configuration policy that describes the desired state of a node to which one wants to take the current configuration to using resource providers.


1 Answers

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

like image 124
coderanger Avatar answered Oct 03 '22 06:10

coderanger