Ask Your Question

Check if file exists on client

asked 2014-03-28 08:43:50 -0600

stikcos gravatar image

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 flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2014-11-14 11:32:33 -0600

scoffland gravatar image

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 -%>")
edit flag offensive delete link more


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

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

answered 2014-03-28 10:46:16 -0600

stikcos gravatar image

updated 2014-03-31 02:48:25 -0600

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)

edit flag offensive delete link 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.

Renan Vicente gravatar imageRenan Vicente ( 2014-03-28 10:55:43 -0600 )edit

answered 2014-03-28 09:29:09 -0600

updated 2014-03-28 10:54:55 -0600

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'],
    notify          => Notify['/path/to/file not found'],         

  notify {'/path/to/file not found': }

 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'],         

  notify {'/path/to/file not found': }
edit flag offensive delete link 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)

stikcos gravatar imagestikcos ( 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.

stikcos gravatar imagestikcos ( 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)

stikcos gravatar imagestikcos ( 2014-03-31 03:28:37 -0600 )edit

Your Answer

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

Add Answer

Question Tools


Asked: 2014-03-28 08:43:50 -0600

Seen: 29,180 times

Last updated: Mar 31 '14