`"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.
More on Modules, Idempotency and Handlers
`ERROR! The requested handler 'Restart nginx' was not found in either the main handlers list nor in the listening handlers list`BeginnerA handler named `restart {{ app_service }}` is never found when notified as `restart myapp`AdvancedA `command` task reports `changed` on every run, and the Molecule idempotence check failsBeginner`curl ... | tar xz` fails on the host but the `shell` task reports successIntermediate`lineinfile` appends the same line again on every runIntermediate`lineinfile` with `backrefs: true` reports `ok` but the line was never addedIntermediate