Interview Prep/Ansible/Modules, Idempotency and Handlers

`"msg": "async task did not complete within the requested time - 300s"`

AdvancedTroubleshootingModules, Idempotency and Handlers
Answer

Likely causes → The job really took longer than async: 300 (a large backup, an OS upgrade), or it hangs waiting for input (apt prompting about a config file, a script waiting on stdin).

Diagnose → Log in and look at the process. The async job's output is in ~/.ansible_async/<jid> of the become user.

Fix → Fire the job and check on it separately, with a realistic upper bound:

- ansible.builtin.command: /opt/backup/run.sh
  async: 3600
  poll: 0
  register: job
- ansible.builtin.async_status:
    jid: "{{ job.ansible_job_id }}"
  register: st
  until: st.finished
  retries: 120
  delay: 30

Make commands non-interactive (DEBIAN_FRONTEND=noninteractive, -y, </dev/null).

Prevent → Use async for anything that runs longer than the SSH keepalive window, and clean up with async_status: mode=cleanup.

All Ansible questions Roadmap: Ansible

More on Modules, Idempotency and Handlers