0Pricing
Ansible Academy · Lesson

Run a Task Only when True

Gate tasks on a boolean condition.

Tasks That Decide

Sometimes a task should run only in certain cases. The when keyword gates a task on a condition you choose. 🚦

The when Keyword

Add when to any task. If the expression is true, the task runs; if false, Ansible skips it and moves on.

- name: Reboot the box
  ansible.builtin.reboot:
  when: reboot_required

All lessons in this course

  1. Run a Task Only when True
  2. Branch on OS Family Facts
  3. Combining Conditions with and / or
  4. Register a Result, Then Decide
← Back to Ansible Academy