有条件地标记Chef节点

问题描述 投票:0回答:1

使用厨师食谱,我希望一个节点发出http请求。如果请求失败,我想将其记录下来,并让节点用失败代码标记自身。

ruby_block 'connectivity_precheck' do
  block do
    Chef::Resource::RubyBlock.send(:include, Chef::Mixin::ShellOut)
    command = '/bin/curl -o /tmp/connectivity_check.txt --silent --connect-timeout 30 -k https://host.domain.com:4890'
    command_out = shell_out(command)
    if ::File.exist?('/tmp/connectivity_check.txt')
      Chef::Log.info("Connectivity confirmed.")
    else
      Chef::Log.info("Connectivity failed.")
      ???Command to Tag???
    end
  end
  action :create
end

由于我使用的是红宝石块,所以不能使用“标签”。在ruby块中如何标记节点?

ruby tags chef
1个回答
0
投票

未经测试,但我会尝试:

run_context = Chef::RunContext.new(node, {})
run_context.node.tag("failed_tag")

也许更简单:

node.tag("failed_tag")

也可以。 node应该在ruby_block中可用。

© www.soinside.com 2019 - 2024. All rights reserved.