DevOps / Ansible Interview questions
Explain the lifecycle of a task in an Ansible play?
A single task moves through templating, module dispatch, execution, and result handling before Ansible considers it complete for a given host.
Before anything runs, Ansible evaluates the task's when condition (if any); if false, the task is marked skipped and nothing further happens for that host. Otherwise, module arguments are templated with Jinja2 using currently known variables and facts, and the module is dispatched to the host - respecting any become or delegate_to directives that change who executes it or where. The module runs its check-then-act logic and returns a result; if register is set, that result is stored in a variable for later tasks to reference, and if the task both notify-ed a handler and reported changed, that handler is queued to run at the end of the play. This entire sequence happens independently, per host, which is why a task can succeed on one host and fail on another within the same play.
More Related questions...