Conditionals in Ansible
- Conditionals in ansible allows to execute tasks based on condtion.
- Conditions in Ansible are generally based on
- Facts
- Variables
- module results
- Basic syntax
tasks:
- name: Run this task only if os is Debian Based
debug:
msg: "This is debian based os"
when: ansible_facts['os_family'] == "Debian"
- File/Folder existence checks
- stat
- glob
- Refer Here for lookups
- Refer Here for playbook with conditionals and handler changes
- Now we have adopted the handlers and conditionals to not execute the steps everytime Refer Here
- Exercise: Try rewriting the playbook to make it work for redhat as well.
