Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 如何将linux命令输出到chef属性_Ruby_Chef Infra_Recipe - Fatal编程技术网

Ruby 如何将linux命令输出到chef属性

Ruby 如何将linux命令输出到chef属性,ruby,chef-infra,recipe,Ruby,Chef Infra,Recipe,我想将命令输出到chef属性中。有人能帮我在execute资源或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 #

我想将命令输出到chef属性中。有人能帮我在execute资源或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

如何在上述代码中使用属性。

中给出了您问题的答案。只要稍加修改,如果我理解正确,你的问题可以这样解决:

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

请添加一些代码,以便我们可以看到您面临的问题似乎是个问题,但仍然不清楚您想要什么。实际问题似乎是
command='cat{fileName}“
where@SASI应该使用双引号来启用解析(即,
command=“cat#{fileName}”
)此IMHO至少回答了您的问题。如果你描述你的问题,我们可能会找到一个更优雅的解决方案。谢谢斯蒂芬金。。我的命令是“sudo su-grid+ASM asmcmd lsdsk-G data”,我必须以grid用户身份登录并进入+ASM进程并运行该命令。您能帮助我如何在recipe中运行它吗。@user3886612编辑您的问题以描述用例,这样我们就可以重新打开vote@SASI在评论中重复你自己也无济于事。在你的问题下面有一个编辑按钮来更新它。看看你以后如何使用这些信息也会很有趣。