How to run very long ansible tasks

ansiblescheduled-tasksssh

I have following ansible role tasks: "Task 1", "Task 2", "Task 2.1", "Task 2.2", "Task 3"

I need run them, but all these tasks need a lot of time to complete (from 1 hour to 12 hours) and they must go in special sort order (I mean, that "Task 2.1" must start only after "Task 2" and so on)

How can I do this?

Best Answer

For a long running task use Ansible's Asynchronous mode to effectively background the task.

- name: 'YUM - fire and forget task'
  yum: name=docker-io state=installed
  async: 1000
  poll: 0
  register: yum_sleeper

Then follow it up with another task that checks the status of the backgrounded task.

- name: 'YUM - check on fire and forget task'
  async_status: jid={{ yum_sleeper.ansible_job_id }}
  register: job_result
  until: job_result.finished
  retries: 30

Example taken from Ansible official docs: http://docs.ansible.com/ansible/playbooks_async.html

Related Question