Tools: Smart Playbooks: Handling Ubuntu and CentOS in one go with Ansible (2026)
One of the biggest hurdles in automation is environmental drift—specifically when your fleet isn't running the same OS.I recently tackled this in an enterprise environment. I wanted to deploy a web stack, but my nodes are a mix of Ubuntu 24.04 and CentOS. Since Ubuntu uses apt and Apache is called apache2, while CentOS uses dnf and Apache is called httpd, a simple script wouldn't cut it. Enter Ansible Conditionals.By using the when statement tied to the ansible_distribution fact, I built a 'smart' playbook that:Detects the OS automatically.Runs apt tasks for Ubuntu and dnf for CentOS.Installs the correct package names for each. It’s a small logic jump, but it’s the difference between a playbook that works on one machine and a playbook that works on a thousand. Next up on my journey: Implementing Handlers to make these updates even more efficient! 🚀 Templates let you quickly answer FAQs or store snippets for re-use. as well , this person and/or