如何获得Linux命令输出到Chef属性 [英] How to get a linux command output to chef attribute

查看:80
本文介绍了如何获得Linux命令输出到Chef属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将命令输出输入Chef属性。有人可以帮我如何在执行资源或bash资源中设置它吗。

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.

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. 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

替换命令的内容使用您要运行的命令,并使用 my_attribute 使用要设置的属性。

Replace the content of command with the command that you want to run and my_attribute with the attribute that you want to set.

这篇关于如何获得Linux命令输出到Chef属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆