911 B
911 B
Async
Run tasks asynchronously to avoid blocking:
Key Parameters
async: Maximum number of seconds to wait for the task to completepoll: Number of seconds to wait between checks (0 means no polling)
Example Playbook
- name: Restart service asynchronously
service:
name: apache2
state: restarted
async: 10
poll: 0
# Check async task status:
# ansible-playbook site.yml --check
Best Practices
- Use async for long-running tasks (e.g., backups, migrations)
- Combine with
ignore_errors: yesfor resilient task execution - Monitor task status using
async_statusmodule - Use
--checkflag to simulate async operations
Troubleshooting
- Check task output with
--verbosity=2 - Use
async_statusto track task progress:- name: Check async task status async_status: jid: "{{ async_jid }}" register: task_result