[英]How to get a linux command output to chef attribute
I want to get a command output into a chef attribute.我想将命令输出放入厨师属性中。 Can some one help me how to set that in execute resource or bash resource.有人可以帮助我如何在执行资源或 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 to use attributes in the above code..如何在上面的代码中使用属性..
The answer to your question is pretty mich given in How can I put the output of a Chef 'execute resource' into a variable .您的问题的答案在How can I put the output of a Chef 'execute resource' into a variable 中非常详细。 With tiny modification, if I understand the question right, your problem can be solved like this:稍加修改,如果我理解正确,您的问题可以这样解决:
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
Replace the content of command
with the command that you want to run and my_attribute
with the attribute that you want to set.将command
的内容替换为要运行的命令,将my_attribute
替换为要设置的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.