使用厨师食谱,我希望一个节点发出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块中如何标记节点?
未经测试,但我会尝试:
run_context = Chef::RunContext.new(node, {})
run_context.node.tag("failed_tag")
也许更简单:
node.tag("failed_tag")
也可以。 node
应该在ruby_block中可用。