Puppet:如何从代理加载文件 - 第 3 部分
Puppet : How to load file from agent - Part 3
使用我之前查询中的函数(参见下面的参考资料),我能够从代理中提取文件并执行必要的任务。但是,这会影响系统上的所有用户,因为它会抛出一个异常,指出找不到该文件。无论如何我可以向这个 ruby 函数添加一些像 unless file_exists ....
这样的逻辑吗?
我的层次结构如下所示。我不理解为什么它会影响其他甚至不在 "mymodules".
中的用户
Root
modules
mymodules
lib
facter
ruby_function1.rb
ruby_function2.rb
modules_by_userxx1
modules_by_userxx2
modules_by_userxx3
....
参考:
应 Dominic 的要求,添加参考代码:
# module_name/lib/facter/master_hash.rb
require 'json'
Facter.add(:master_hash) do
setcode do
# return content of foo as a string
f = File.read('/path/to/some_file.json')
master_hash = JSON.parse(f)
master_hash
end
end
我假设你是在谈论之前答案中的自定义事实而不是 Ruby 函数,在这种情况下,添加一个 File.exist?
条件:
# module_name/lib/facter/master_hash.rb
require 'json'
Facter.add(:master_hash) do
setcode do
if File.exist?('/path/to/some_file.json')
# return content of foo as a string
f = File.read('/path/to/some_file.json')
master_hash = JSON.parse(f)
master_hash
end
end
end
提问时请附上完整的错误信息(带有 filename/line 编号)和源代码。
自定义事实在模块中传送,但全部同步到用于发现数据的代理。
在对节点进行分类之前,在代理上同步并 运行 事实,因为它们可用于做出分类和目录决策,例如基于主机名或 OS。因为分类之前的事实运行,还不可能知道将要应用哪个类(可能还有模块),所以在每个节点上运行应该是安全的环境。
使用我之前查询中的函数(参见下面的参考资料),我能够从代理中提取文件并执行必要的任务。但是,这会影响系统上的所有用户,因为它会抛出一个异常,指出找不到该文件。无论如何我可以向这个 ruby 函数添加一些像 unless file_exists ....
这样的逻辑吗?
我的层次结构如下所示。我不理解为什么它会影响其他甚至不在 "mymodules".
中的用户Root modules mymodules lib facter ruby_function1.rb ruby_function2.rb modules_by_userxx1 modules_by_userxx2 modules_by_userxx3 ....
参考:
应 Dominic 的要求,添加参考代码:
# module_name/lib/facter/master_hash.rb
require 'json'
Facter.add(:master_hash) do
setcode do
# return content of foo as a string
f = File.read('/path/to/some_file.json')
master_hash = JSON.parse(f)
master_hash
end
end
我假设你是在谈论之前答案中的自定义事实而不是 Ruby 函数,在这种情况下,添加一个 File.exist?
条件:
# module_name/lib/facter/master_hash.rb
require 'json'
Facter.add(:master_hash) do
setcode do
if File.exist?('/path/to/some_file.json')
# return content of foo as a string
f = File.read('/path/to/some_file.json')
master_hash = JSON.parse(f)
master_hash
end
end
end
提问时请附上完整的错误信息(带有 filename/line 编号)和源代码。
自定义事实在模块中传送,但全部同步到用于发现数据的代理。
在对节点进行分类之前,在代理上同步并 运行 事实,因为它们可用于做出分类和目录决策,例如基于主机名或 OS。因为分类之前的事实运行,还不可能知道将要应用哪个类(可能还有模块),所以在每个节点上运行应该是安全的环境。