Chef - launching a resource with other resources

I have two resources executecalled command_1and command_2.

If it command_1does not work, I want to start command_2and then restart command_1.

Mostly like this:

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

How can I replace on_failure(it would be great if the chef had this) with what really works?

+4
source share
1 answer

It is best to put command_2 first and then protect it by checking if it needs to be run or not. I'm not sure what this command does, but if you can somehow make sure if it is necessary or not, then you can do so.

, command_2, - :

execute 'command_1' do
  command "ipa host-del #{machine_name} && touch /tmp/successful"
  action :run
  ignore_failure true
end

execute 'command_2' do
  command "ipa host-mod --certificate  #{machine_name}"
  action :run
  notifies :run, 'execute['command_1']', :immediately
  not_if { ::File.exist? '/tmp/successful' }
end

file '/tmp/successful' do
  action :delete
end

command_1, , touch /tmp/successful. command_2 , /tmp/successful . IF command_2 , command_1 . , file /tmp/successful

+2

Source: https://habr.com/ru/post/1630006/


All Articles