我想将命令输出转换为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
如何在上面的代码中使用属性..
答案 0 :(得分:18)
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
。