Ask Your Question
0

How to delete file when exec fail

asked 2015-11-25 02:45:38 -0500

Sunny gravatar image

There is a request when I using puppet, the working flow are as below: 1. place a file to a defined location, such as /home/workingdir/file1 2. call a command using puppet exec, 3. if the exec is called successfully, the whole working process is done. 4. if the exec is fail, delete the file1 at step 1, because we using a refresh only in the exec, if the file is present, it will prevent puppet to call exec to reinstall the file.

I can not find a solution for that, I'd like to know is any others have this knowledge to handle this situation.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-01-13 21:23:46 -0500

Areson gravatar image

Off the top of my head it seems like having the Exec have some sort of error handling built into the command so that if it fails, the failure is caught and the file is deleted. Example:

try
    do_some_things
catch
        delete_the_file
end

I don't know of anything in Puppet that allows you to do something in response to a resource failing. Another option, though a bit more involved, would be to write your own type that inherits from Exec and allows you to specify an "on failure" command that runs if the command on the Exec fails.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-11-25 02:45:38 -0500

Seen: 107 times

Last updated: Nov 25 '15