In a customized modules on Puppet I have
g_iptables ├── files │ └── fqdn-of-server ├── lib │ └── puppet │ └── parser │ └── functions │ └── file_exists.rb └── manifests └── init.pp
and I want to let the module do something whether or not the file “fqdn-of-server” exist on the Puppet Master. Googling did get me a file_exists.rb function:
#!/usr/bin/ruby require 'puppet' module Puppet::Parser::Functions newfunction(:file_exists, :type => :rvalue) do |args| if File.exists?(args[0]) return 1 else return 0 end end end
and this does work when put in something like:
$does_fqdn_file_exists = file_exists("/tmp/$fqdn") if $does_fqdn_file_exists == 1 { ... }
in my manifest init.pp (of course $fqdn is a facter). The problem is that it works only on the client (so $does_fqdn_file_exists is 1 if the /tmp/$fqdn exist on the client $fqdn, it does not work on the puppet master.
Also, I want to use puppet:/// uri structures in this construct, but thus sofar, my function doesn’t understand this uri.
Can somebody help me ? The ruby function stems from someone on the web, who claims that it checks the file existence on the master, which is not the case (at least not what I can see).
Advertisement
Answer
In the puppet master you could test it like this:
# create a temporary file that may look like this : ]$ cat /tmp/checkfile.pp $does_fqdn_file_exists = file_exists("/tmp/$fqdn") notify{ "Check File = $does_fqdn_file_exists" : } # Then run it : ]$ puppet apply /tmp/checkfile.pp