繁体   English   中英

如何获得一个 linux 命令输出到厨师属性

[英]How to get a linux command output to chef attribute

我想将命令输出放入厨师属性中。 有人可以帮助我如何在执行资源或 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替换为要设置的属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM