Execute a shell command/script using puppet

AjayKumar picture AjayKumar · Oct 24, 2016 · Viewed 7.4k times · Source

I want to execute a shell command/script using puppet only when a file exists in particular path.

For example if a text file test.txt exists in /root path then puppet will execute shell script, otherwise puppet didn't execute any commands

Answer

Atmesh Mishra picture Atmesh Mishra · Oct 25, 2016

You should have done a little research before posting this question. But nevermind..

exec {"Comment to your resource":
command => 'your command',
provider => shell,
onlyif => '/usr/bin/test -e /path/to/file/test.txt',
}

onlyif will execute the command in Exec if and only if the command executed(in the onlyif) has return code 0.