Ansible Playbook that will dynamically load the variable file named same as OS name and just by using the variable names it will configure target nodes.

In this article, we will create a dynamic Ansible playbook for deploying a webpage in any type of OS without using the “when” keyword.

The need for the above-mentioned playbook is that there are different name of the software and services in the different Operating Systems. So we cannot directly hardcode the name of software and services in the Playbook as it varies os to os.

For Example:

  • The name of Apache Web Server in Redhat 8 is httpd.
  • And the name of Apache Web Server in Ubuntu 20 is apache2.

So we will use concept of Ansible Facts and will get the name of the OS with version using facts.

Command to see facts is:

ansible -m setup <IP of Managed Node>

We can get the name of OS from Key “ansible_distribution” and the version of OS from Key “ansible_distribution_major_version” of facts.

Now we will create a vars file with os_name.yml and include it in our dynamic playbook.

Now we will dynamically include these var files in our playbook.

Run the Playbook.

It will configure the webserver in all nodes (despite different OS).

For Github Link Click Here.




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

An Image Classifier With Keras

Are you an OCD software developer?

Registry DB Cleanup in WSO2 API Manager

Bootstrapping Process of MVC Core

What is AIOps: the next level of DevOps services

How to deploy micro-services on kbernetes, hands on tutorial !

CS 371p Spring 2020: Week of 3/30

Understanding Scheduler Resilience in JD Edwards

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Karan Agrawal

Karan Agrawal

More from Medium

SuiteCRM installation in Ubuntu Server 20.04.4 LTS VPS [2022 Guide]

The difference between dpkg, apt and aptitude

Deepin 20.5 — Agile Development of Mail

Cybersecurity and Hegemonic Powers