有三种方式。
模块 Puppet::Parser::Functions newfunction(:getconf, :type => :rvalue, :doc => 2010-09-29 getconf 函数接受一个参数,即 配置设置并返回该设置的值。 它类似于 --configprint 命令行参数 返回配置设置,除非它公开此信息 到语言。 END_HEREDOC 做 |参数| 如果 args.length != 1 那么 raise Puppet::ParseError, ("错误:getconf() 只接受一个参数") 结尾 傀儡[参数[0]] end # 做 |args| 结束#模块 #EOF
把它放在你的 puppet 服务器的 libdir ( /var/puppet/lib/puppet/parser/functions/getconf.rb
)中一个名为“getconf.rb”的文件中,并从一个清单中访问它
# somemanifest.pp
$myvar = getconf("ssldir")
notify {"set ssldir to ${myvar}":}
Run Code Online (Sandbox Code Playgroud)
2. 在 Puppet 2.6 中它更容易,因为整个设置设置都可以作为 访问${settings::somevar}
,所以清单很简单:
# 26manifest.pp
$myvar = $settings::ssldir
notify {"set ssldir to $myvar":}
Run Code Online (Sandbox Code Playgroud)
3. 在 puppet 0.25 中,您可以使用内联模板:
# 25manifest.pp
$myvar = inline_template("<%= Puppet.settings[:ssldir] %>")
notify {"set ssldir to ${myvar}":}
Run Code Online (Sandbox Code Playgroud)
方法 2 和 3 感谢这个关于 puppet-users 的线程