Condition Handling

Conditionals helps us evaluate a variable and take some action on the basis of the outcome. We can execute some part of the role or playbook depending up on the definition of the variable.

Example:

---
- yum: package=httpd state=installed
  when: ansible_os_family == "RedHat" 

- apt: package=apache2 state=installed
  when: ansible_os_family == "Debian"

This is very useful to write OS agnostic roles.