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 ?
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.
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.
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.
For a single script, use an execute
. The bash
resource is for including the script contents inline in the recipe code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With