# Check if file exists on client edit

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 -0500 )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 -0500 )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 -0500 )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 -0500 )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 -0500 )edit
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.2572133243083954, "perplexity": 9349.862414497202}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2017-26/segments/1498128323864.76/warc/CC-MAIN-20170629033356-20170629053356-00000.warc.gz"}