LOGBOOK

HELP

Quiz Entry - updated: 2026.11.12

How does the when statement decide whether a task runs?

when takes a condition: if it is true the task runs, if it is false the task is reported as skipped (not failed) and the play continues.

The simplest condition is a boolean variable:

- name: Simple Boolean Task Demo
  hosts: all
  vars:
    run_my_task: true

  tasks:
    - name: httpd package is installed
      ansible.builtin.dnf:
        name: httpd
      when: run_my_task

Two details are worth knowing:

  • The value of when is already a Jinja2 expression, so you write when: run_my_task, not when: "{{ run_my_task }}". The braces are redundant and Ansible warns about them.
  • A skipped task is a normal outcome. It shows as skipping: in the output and counts under skipped= in the recap; it neither fails the host nor notifies handlers.

Go deeper:

From Quiz: ITIA / Ansible Task Control: Loops, Conditionals, Handlers and Error Handling | Updated: Nov 12, 2026