1.

What is "execute" resources in Chef? Explain with an example.

Answer»

execute resources in Chef is USED to execute a single command. All commands executed via execute resources are not idempotent and are specific to the environment in which it’s run. We need to USE guards like “not_if”, “only_if” to make the execution of the resource idempotent. During a Chef Client run, guards property verifies the state of the Chef node. "execute" resources could be run alone or in combination with other in-built Chef resources like templates, etc. "execute" resources could be used when we need to reuse existing shell scripts for infrastructure configurations. We need to SPECIFY the command to run the shell script in "execute" resource block.

For EG:

```execute 'apache_test' do      command '/usr/apachectl configtest' end```

“apache_test” is the name provided for the "execute" resource block. The actual command run is “/usr/apachectl configtest”.

Execute resource could have only two actions, nothing and run. If the action SPECIFIED is "run", the command provided is executed. If the action specified is nothing, the command provided in the "execute" block is prohibited from running. script resource is often confused with execute resource. Script resource is used to execute a script using an interpreter provided like bash etc



Discussion

No Comment Found