I am using ansible to do the following:
---
# 1. Target localhost to spin up a cloud server
- name: Spinup droplet
hosts: local
connection: local
tasks:
- name: Include spinup tasks from computation droplet role
include_tasks: ../roles/computation_droplet/tasks/spinup.yml
#2. Target the cloud server to run a script
- name: Run computation script
? hosts: computation_host
? remote_user: root
tasks:
- name: Include computation script tasks
? ? include_tasks: ../roles/script/tasks/compute.yml
#3. Target a second cloud server to move the script result onto it
- name: Move result onto file server
? hosts: file_server
? remote_user: root
? tasks:
? ? - copy:
? ? ? ? src: /tmp/fetched/computation_droplet/root/computation/output/out.csv
? ? ? ? dest: /root/out.csv
#4. Target localhost to destroy the cloud server
- name: Spindown droplet
hosts: local
connection: local
tasks:
- name: Include spindown tasks from computation droplet role
include_tasks: ../roles/computation_droplet/tasks/spindown.yml
This all works fine, but I want to have step 4 run even if there is a failure in steps 2 or 3, and none of the solutions seem to work.
I can't seem to fit this into a block (to use always:
) because a block requires a task list. And I have to have all these steps in separate plays because they target different hosts. I can't run tasks within a single block targeting different hosts, correct?
The same seems to apply to doing force_handlers: true
-- that can only be used as part of the tasks:
logic, which I can't seem to use because of the different target hosts.
Is it possible to always run a play as a cleanup step even in the event of failure in a prior play? Or is it possible to have different tasks in a single task list target different hosts? Either one would get me what I'm trying to do, but I can't seem to find any examples of either.
Thanks a lot for any tips.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…