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

3

1 Answer 1

5
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.

Sign up to request clarification or add additional context in comments.

3 Comments

NMDV, but do not encourage poor questions by writing answers.
@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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.