Basic conditionals withwhen
The simplest conditional statement applies to a single task. Create the task, then add awhenstatement that applies a test. Thewhenclause is a raw Jinja2 expression without double curly braces (seeReferencing simple variables). When you run the task or playbook, Ansible evaluates the test for all hosts. On any host where the test passes (returns a value of True), Ansible runs that task. For example, if you are installing mysql on multiple machines, some of which have SELinux enabled, you might have a task to configure SELinux to allow mysql to run. You would only want that task to run on machines that have SELinux enabled: