Ansible playbook to dynamically configure packages according to OS

Vivek Singare
2 min readSep 30, 2021

--

with help of variable files and ansible facts for OS distribution

Automation makes it easy..! For same use case, instead of writing separate playbooks OS wise we can do it with only single play. Suppose for installing same package on many different OS we have mention package name according to that OS (as package name varies from OS to OS). Here’s the logic- Use variable files and ansible facts for OS distribution : vars_files & nsible_facts[‘distribution’]

Let’s do it with one use case, for ex I have to launch two apache webservers one on redhat while other on ubuntu. So launched both instances and had ready ansible controller (in my case) on aws.

Here’s what we are gonna do: make both target host entries in inventory. Make two variable files named not other than distribution names according to OS type stating the package name which we have to install. And webpage to deploy for sure.

Write playbook- ansible/play.yml at main · gitviveks/ansible (github.com)

Check if playbook and host connectivity is good:

and play it…

Finally both webservers are up and working:

Conclusion: with help of variable files and ansible facts for OS distribution we can launch same package on different OS.

GitHub: ansible/Ansible facts — distribution at main · gitviveks/ansible (github.com)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Vivek Singare
Vivek Singare

No responses yet

Write a response