我想将命令输出到 chef 属性中。有人可以帮助我如何在执行资源或 bash 资源中设置它。
ruby_block "something" do
block do
#tricky way to load this Chef::Mixin::ShellOut utilities
Chef::Resource::RubyBlock.send(:include, Chef::Mixin::ShellOut)
command = 'cat #{fileName}'
command_out = shell_out(command)
node.set['my_attribute'] = command_out.stdout
end
action :create
end
如何在上面的代码中使用属性..
最佳答案
您问题的答案在 How can I put the output of a Chef 'execute resource' into a variable 中给出了相当多的答案.通过微小的修改,如果我理解正确的问题,你的问题可以这样解决:
ruby_block "something" do
block do
#tricky way to load this Chef::Mixin::ShellOut utilities
Chef::Resource::RubyBlock.send(:include, Chef::Mixin::ShellOut)
command = 'cat /etc/hostname'
command_out = shell_out(command)
node.set['my_attribute'] = command_out.stdout
end
action :create
end
将 command
的内容替换为您要运行的命令,将 my_attribute
的内容替换为您要设置的属性。
关于ruby - 如何将 linux 命令输出到 chef 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29721575/