[英]Use knife commands from ruby without bash
I'm trying to remove the following bash command from my ruby script: 我正在尝试从我的ruby脚本中删除以下bash命令:
nodes = "knife search 'chef_environment:#{env} AND recipe:#{microservice}' -i 2>&1 | tail -n 2"
node = %x[ #{nodes} ].split
node.each do |n|
puts n
end
And replace it with something like this: 并将其替换为以下内容:
node = Chef::Knife.search("chef_environment:#{env} AND recipe:#{microservice}").split
Is this possible? 这可能吗? Is there any documentation regarding Chef::knife library in ruby and how to use it?
是否有关于Ruby中的Chef :: knife库的文档以及如何使用它?
To access a chef server, you could try to use the ridley gem, which is also used by Berkshelf and thus generally up-to-date. 要访问厨师服务器,您可以尝试使用ridley gem,Berkshelf也使用ridley gem,因此通常是最新的。
A usage example could be: 一个使用示例可能是:
ridley = Ridley.from_chef_config('/path/to/knife.rb')
ridley.search(:node, "chef_environment:#{env} AND recipe:#{microservice}")
See the documentation of the gem for a more detailed description of its options. 请参阅gem的文档以获取有关其选项的更详细说明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.