There isn't a built-in function, so I'd write a function, put it in lib/puppet/parser/functions in your module, enable pluginsync in puppet.conf (so the custom function get synced to the agents), and then use the function in the manifest.
Something as simple as: require"puppet" module Puppet::Parser::Functions newfunction(:bueller, :type => :rvalue) do |args| File.exists?(args[0]) end might work. Improve as needed. Consult: https://docs.puppetlabs.com/guides/custom_functions.html. Thanks! On Fri, Oct 10, 2014 at 12:37 PM, Juan Andres Ramirez <[email protected] > wrote: > 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 > <https://groups.google.com/d/msgid/puppet-users/fba2459b-d6ac-48ec-a81b-83086a26245a%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- 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/CAOzFSfHUGoWP153r2HTcznNiUeOh_AQRjPrrpQBPoHxqTcZ7ZA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
