Alv*_*ado 2 ruby file-io function puppet
我正试图在puppet中移植一个Ruby脚本.据我所知,实现这一目标的唯一方法是在模块中创建自定义函数.如果有另一种方式,请随时告诉我.我尝试了我的第一个测试,如https://docs.puppetlabs.com/guides/custom_functions.html所示,我宣布了一个新模块:
/etc/puppet/modules/custom_module
Run Code Online (Sandbox Code Playgroud)
并编辑了一个/etc/puppet/modules/custom_module/lib/puppet/parser/functions/newfunction使用以下代码调用的新函数文件:
module Puppet::Parser::Functions
newfunction(:write_line_to_file) do |args|
filename = args[0]
str = args[1]
File.open(filename, 'a') {|fd| fd.puts str }
end
end
Run Code Online (Sandbox Code Playgroud)
然后我在这个清单中/etc/puppet/environments/desarrollo/manifests/des.pp使用了这个内容:
node "develserver" {
write_line_to_file('/tmp/some_file', "Hello world!")
}
Run Code Online (Sandbox Code Playgroud)
最后,当我运行puppet agent -tod它时,它显示以下错误:
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Unknown function write_line_to_file at /etc/puppet/environments/desarrollo/manifests/des.pp:5 on node develserver
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?