Files
ansible/async.md

911 B

Async

Run tasks asynchronously to avoid blocking:

Key Parameters

  • async: Maximum number of seconds to wait for the task to complete
  • poll: 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

  1. Use async for long-running tasks (e.g., backups, migrations)
  2. Combine with ignore_errors: yes for resilient task execution
  3. Monitor task status using async_status module
  4. Use --check flag to simulate async operations

Troubleshooting

  • Check task output with --verbosity=2
  • Use async_status to track task progress:
    - name: Check async task status
      async_status:
        jid: "{{ async_jid }}"
      register: task_result