简体   繁体   English

如何将批处理命令 output 分配给 Chef 配方属性

[英]How to Assign a batch command output to Chef recipe attribute

I have a windows command to check the directory which is updated recently.我有一个 windows 命令来检查最近更新的目录。

for /f "delims=" %a in (' dir C:\Users\Username\cookbooks /ad /od /b ') do set "Last=%a";
echo %Last%;

I would like to assign output of above command to a Chef recipe attribute/cookbook attribute.我想将上述命令的 output 分配给厨师食谱属性/食谱属性。

I did tried to directly execute above command in a batch resource and assign output but failed.我确实尝试在批处理资源中直接执行上述命令并分配 output 但失败了。 Is there a way to do so in Chef cookbook attribute?有没有办法在厨师食谱属性中这样做?

you can run the a command as a part of the cookbook execution and assign the values to a node attributes using shell_out您可以将 a 命令作为说明书执行的一部分运行,并使用shell_out将值分配给节点属性

for instance, it will look something like例如,它看起来像

ruby_block 'foo' do
  block do
    cmd = "your command here"
    shell = Mixlib::ShellOut.new(cmd).run_command
    stdout = shell.stdout
    node.default['my_key'] = stdout
  end
end

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

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