Interview Prep/Ansible/Performance and Scale

How do you speed up long-running tasks across many hosts?

IntermediateProductionPerformance and Scale
Answer

Use async with poll: 0 to start the task on all hosts at once, regardless of forks, then wait for completion with async_status.

- ansible.builtin.command: /opt/app/bin/reindex
  async: 7200
  poll: 0
  register: reindex

- ansible.builtin.async_status:
    jid: "{{ reindex.ansible_job_id }}"
  register: job
  until: job.finished
  retries: 240
  delay: 30

Good for patching, backups, large downloads and reindexing. Be careful that starting everything at once can overload shared resources (the mirror, storage), so combine it with throttle where needed.

All Ansible questions Roadmap: Ansible

More on Performance and Scale