# Check if file exists on client

Hi, i have to deploy application on WebServer. At the end of the deployment, i specific file appear and i would know how to check if the file had been created or not.

I found two solutions : if file ( "/path/to/file","/dev/null") != ' ' { } or if inline_template(<%= File.exists?(self.lookupvar($path)) %>) { } These solutions work but they search the file on the puppet master only. What can i change to search on client ? edit retag close merge delete ## 3 Answers Sort by » oldest newest most voted Not sure if this helps as we use a git + puppet version (ppg) that runs masterless but the following works for me. I'm not sure if this would work on traditional puppet master setup. Maybe someone else can test the code and comment. $file_foo_exists = inline_template("<% if File.exist?('/path/to/local/file/foo') -%>true<% end -%>")

more

Wow, that's dirty. I like it. Unfortunately this only works for me, if executed locally with puppet apply.

( 2015-01-16 06:24:05 -0600 )edit

Result of your command (file exist) :

puppet apply /tmp/test/mimi.pp Notice: /path/to/file-not-found Notice: /Stage[main]//Notify[/path/to/file-not-found]/message: defined 'message' as '/path/to/file-not-found' Notice: /Stage[main]//Exec[command when file exists]/returns: executed successfully Notice: /path/to/file-found Notice: /Stage[main]//Notify[/path/to/file-found]/message: defined 'message' as '/path/to/file-found' Notice: Finished catalog run in 1.25 seconds

As you can see, both notify are notified and it's a problem for me because i cant solve the problem with "command" parameters of the exec function . To solve my problem, i ...

more

Why don't you use exec with onlyif it's ok and another exec with onlyif it's not ok. I updated my answer with an example.

( 2014-03-28 10:55:43 -0600 )edit

you can try using the onlyif of exec resource.

 exec {'command when file not exists':
command         => "command to solve the problem",
user            => root,
onlyif          => "test ! -f /path/to/file",
path            => ['/usr/bin','/usr/sbin','/bin','/sbin'],
}

exec {'command when file exists':
command         => "command to solve the problem",
user            => root,
onlyif          => "test -f /path/to/file",
path            => ['/usr/bin','/usr/sbin','/bin','/sbin'],
notify          => Notify['/path/to/file  found'],
}


more

I already think about an exec command and the onlyif parameter but i forget the notify parameter ! I will try to solve my problem with it, i have an idea ...(more)

( 2014-03-28 10:02:06 -0600 )edit

You can see the return of your example on my previous answer. I tested with my correction and it's the same, cannot separate both condition.

( 2014-03-31 02:46:53 -0600 )edit

I think i have no choise to use an exec command, another topic talk about my problem and all command as i used work in the PM and never on ...(more)

( 2014-03-31 03:28:37 -0600 )edit