One way:

$path

onlyif => "powershell.exe -ExecutionPolicy ByPass -command \"if (Test-Path 
${path}) { exit 1;}  else { exit 0; }\""

if puppet get exit 0 this finish without any error, so the path exist.

for more info go powershell console and run command get-help test-path



On Friday, October 10, 2014 4:17:04 PM UTC-3, Stella wrote:
>
> Hi all,
>
> I am using Puppet 3.6.2. I am trying to write a puppet module, which will 
> replace a file with source template ONLY IF this file already exists. If 
> this file doesn't exist, don't do anything. 
>
> I have got it to work with the "exec" command, but that requires to use 
> some command/script outside of Puppet. 
> I want to find out if Puppet has any built-in function to achieve this 
> purpose? 
> I tried with "replace", but "replace" will create the file if the file 
> doesn't exist. That's not I want.
>
> Here is the example "exec" code:
>
>   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': }
>
>
> Thanks a lot !
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/fba2459b-d6ac-48ec-a81b-83086a26245a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to