我有两个名为command_1
和command_2
的execute
资源。
如果command_1
执行失败,我想要运行command_2
,然后再次运行command_1
。
就像这样:
execute 'command_1' do
command "ipa host-del #{machine_name}"
action :run
ignore_failure true
on_failure { notifies :run, 'execute['command_2']', :immediately }
end
execute 'command_2' do
command "ipa host-mod --certificate #{machine_name}"
action :nothing
notifies :run, 'execute['command_1']', :immediately
end
我该如何用实际有效的替代
on_failure
(如果Chef有这个功能将会很棒)?
not_if
/only_if
块来保护第二个资源,以防止它在第一个资源成功时运行?也就是说,当host-del
失败时,我希望类似于ipa host-list #{machine_name}
的东西包含主机。在not_if { mixlib shellout blabla contains #{machine_name}
中检查这个。 - StephenKing