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_requiredAll lessons in this course
- Run a Task Only when True
- Branch on OS Family Facts
- Combining Conditions with and / or
- Register a Result, Then Decide