I want to perform certain tasks even if I fail to execute them in the middle.

Asked 2 years ago, Updated 2 years ago, 142 views

I would like to automatically start the server that is normally stopped, run the recipe, and then return it to stop

I couldn't use roles and pretasks well, so I put them all together by playbook

-import_playbook:playbooks/start-instances.yml
- import_playbook:<Recipe you want to do>
- import_playbook:playbooks/stop-instances.yml

I wrote it like this, but if the recipe fails in the middle, the stop process will not be carried out.
Must be stopped manually

The ignore_errors option is only available at the task level.
I think it's strange to write it in the recipe I want to do, but
Is there a way to stop processing errors in import_playbook?

Task-level processing is not possible because start-instances.yml, stop_instances is launched by tapping the AWS command from the outside of the target instance (ansable execution server), and the recipe execution host is different

This is an optional-playbook 2.9.4

ansible

2022-09-30 15:57

1 Answers

I think you can use block/resque.

-block:
    - import_playbook:playbooks/start-instances.yml
    - import_playbook:<Recipe you want to do>

  rescue:
    - import_playbook:playbooks/stop-instances.yml

If the operation in the block fails, the operation in the rescue is performed.


2022-09-30 15:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.