[英]puppet custom fact for facter
Trying to write a custom facter module: 尝试编写自定义facter模块:
Facter.add("something_status") do
setcode do
$string_to_parse = Facter::Util::Resolution.exec('somecommand --print ')
... do something to string
return something-new
end
end
Very new to ruby... what would be the proper syntax to do something with this? 对ruby来说很新...用这个做什么的正确语法是什么?
You are not far away from doing it.. you dont need $ before variable names and you should not end with return. 你离它不远了..在变量名之前你不需要$,你不应该以return结束。 Latest var on scope will be retrieved by Facter. 最新的范围var将由Facter检索。
Below it's an example code that analyze uname output and returns a fact with a string about kernel version and ipv6 support of it. 下面是一个示例代码,它分析uname输出并返回一个带有关于内核版本和ipv6支持的字符串的事实。
It's just an example but it works, just tried it. 这只是一个例子,但它有效,只是试了一下。
Facter.add("customer") do
setcode do
kernel_release = Facter::Util::Resolution.exec('/bin/uname -r')
# Get version
if kernel_release =~ /^3.2/
answer = "Latest Kernel"
elsif kernel_release =~ /^3.0/
answer = "3.0 Kernel"
elsif kernel_release =~ /^2.6/
answer = "Decent Kernel"
else
answer = "Unknown Kernel"
end
if answer =~ /ipv6/
answer += " with IPV6 Support"
else
answer += " without IPV6 Support"
end
end
end
Good Luck! 祝好运!
Some useful links for you: Ruby Wikibooks Control Structures , more ruby info 一些有用的链接: Ruby Wikibooks Control Structures , 更多ruby信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.