如何获取linux命令输出到chef属性

我想将命令输出转换为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 

如何在上面的代码中使用属性..

您的问题的答案非常明确我如何将Chef’执行资源’的输出放入变量中 。 通过微小的修改,如果我理解正确的问题,您的问题可以像这样解决:

 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替换为要设置的属性。