Use it when configuring, checking or troubleshooting Tasks in Ansible.
Tasks · Ansible
Ansible tasks are ordered action declarations that invoke modules or action plugins with arguments and controls such as conditionals, loops, delegation, retries, tags and error rules.
1. Tasks call modules with arguments.
2. Name every task.
3. Use register to capture results.
4. when for conditions.
5. assert for validations.
task → module → result
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
task selection → variable/argument resolution → execution host/context → module/action → result flags/data → handlers/dependents → target read-back
Healthy evidence: selection and execution context are explicit, arguments resolve correctly, result data is understood and target state confirms the task outcome.
Step 2 Failure modes and next checks Narrow the fault
Suspicious evidence: hidden skip/delegation, wrong resolved argument, misleading changed flag, loop-item failure or relying on task name/status alone.
Step 3 Common mistakes Narrow the fault
- Tasks without names.
command/shellwhere a module exists.
Step 4 Where it fails Narrow the fault
Where Tasks usually goes wrong: module/action identity, args, delegation/privilege, changed/failed semantics and target read-back.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Task listed ≠ task executed; tags, when clauses and host failure state can skip it.
- ok/changed ≠ service acceptance; module result describes the task contract only.
- Task name ≠ action identity; inspect module/action and arguments.
- Task executed for inventory host ≠ executed on that host when delegation/local actions apply.
ansible-playbook site.yml --list-tasks— tasks- Task names descriptive — logs
- register + assert for checks — validation
ReferenceWhat it is1 section · depth on demand
Core model
For a task, separate selection, effective arguments/variables, execution host, module result flags and target read-back; task metadata can change whether, where and how the action runs.
ReferenceImportant terms & boundaries2 sections · depth on demand
What this shows and what it does not
A task result shows the invoked action reported a state for a specific host/item/context; it does not automatically show end-to-end workload success.
In depth
In Ansible, a task calls one module with arguments and is the smallest unit of work in a play. Tasks run in order on all targeted hosts, and each returns ok, changed, failed or skipped.
- name: Ensure chrony is installed
ansible.builtin.package:
name: chrony
state: present
register: pkg
when: ansible_os_family == 'RedHat'
notify: restart chronyd
| Keyword | Effect |
|---|---|
register | Save the result for later tasks |
when | Run conditionally |
notify | Trigger a handler on change |
loop | Repeat over a list |
failed_when / changed_when | Override result evaluation |
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Ansible > Tasks. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.ansible.com/ansible/latest/ · confidence 94%Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Tasks Ansible boundary map
Fast input/selection, execution/result and target-proof boundaries for Tasks.
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Inputs / selection | Correct inventory, hosts, variables/facts and content are explicit | Wrong scope, stale facts, hidden precedence or content-version drift |
| Execution | Connection, privilege, module/task context and ordering match intent | Unreachable, wrong execution host, privilege/plugin failure or misleading skip/change state |
| Result semantics | Per-host/item results are preserved and interpreted correctly | Aggregate recap hides partial/skipped/handled failures |
| Target proof | Resource/workload read-back and rerun confirm convergence | Green Ansible status treated as end-to-end acceptance |
Deep reference
Healthy vs suspicious evidence
Output interpretation
For Tasks, rely on structured fields and stable IDs (module/action identity, args, delegation/privilege, changed/failed semantics and target read-back) rather than text formatted for display.