4

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

Luka Kerr
  • 4,161
  • 7
  • 39
  • 50
AjayKumar
  • 59
  • 1
  • 1
  • 5
  • 3
    What part of [the documentation for the `Exec` resource type](https://docs.puppet.com/puppet/latest/reference/type.html#exec) confuses you in this regard? – John Bollinger Oct 24 '16 at 15:12

1 Answers1

4

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.

Atmesh Mishra
  • 527
  • 10
  • 26
  • NMDV, but do not encourage poor questions by writing answers. – John Bollinger Oct 25 '16 at 13:15
  • @JohnBollinger In that case down-vote the question, flag the question or edit it to make it better. Don't go on down-voting correct answers just because you can. – Atmesh Mishra Oct 25 '16 at 17:12
  • As I said, Not My DownVote (on your answer). For what it's worth, I *did* downvote the question, as is called for for one that shows complete absence of research effort; someone else has upvoted it for no apparent reason. I'm just suggesting a possible reason for the downvote on your answer, regardless of whether it was strictly-speaking appropriate. And you can expect sometimes to collect such DVs if you choose to answer bad questions. – John Bollinger Oct 25 '16 at 17:42