DevOps Classroom notes 12/Aug/2025

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.
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%