假设我在 puppet 中有一个创建自定义事实的模块。但要做到这一点,它需要package_a
安装一个包。根据这个包是否存在,它将决定生成事实。
此软件包作为配置文件中 puppet 运行的一部分安装。因此,最初不会从模块生成事实。
一旦安装了用于生成自定义事实的包,有没有办法通知 puppet 收集这些事实,以便可以在以下配置文件中使用它?
添加自定义事实的模块:
Facter.add(:custom_facts) do
confine do
exists = Facter::Core::Execution.which('package_a') != nil
Puppet.debug "Testing custom_facts fact applicable? #{exists.inspect}"
true
end
setcode do
to_ret = {}
result = JSON.parse(Facter::Core::Execution.execute('package_a some command'))
Puppet.debug "Facts returned by command: #{result.inspect}"
result.each do |key,value|
to_ret[key]={
'value' => value['value'],
}
end
to_ret
end
end