在 Puppet 的自定义模块中,我有
g_iptables
├── files
│ └── fqdn-of-server
├── lib
│ └── puppet
│ └── parser
│ └── functions
│ └── file_exists.rb
└── manifests
└── init.pp
并且我想让模块做一些事情,无论 Puppet Master 上是否存在文件“fqdn-of-server”。谷歌搜索确实给了我一个 file_exists.rb 函数:
#!/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
当放入以下内容时,这确实有效:
$does_fqdn_file_exists = file_exists("/tmp/$fqdn")
if $does_fqdn_file_exists == 1 {
...
}
在我的清单 init.pp 中(当然 $fqdn 是一个因素)。问题是它只适用于客户端(所以如果 /tmp/$fqdn 存在于客户端 $fqdn 上,则 $does_fqdn_file_exists 为 1,它不适用于 puppet master。
另外,我想在这个构造中使用 puppet:/// uri 结构,但到目前为止,我的函数不理解这个 uri。
有人可以帮助我吗?ruby 功能源于网络上的某个人,他声称它检查主文件是否存在,但事实并非如此(至少不是我能看到的)。