Ansible Playbook which will dynamically load the variable file named same as OS_name:

Hey Connection…!!!🙋‍♀️

Task14.3
👩‍💻Here this is my another blog based on
Creating an Ansible Playbook which will dynamically load the variable file named same as OS_name and just by using the variable names we can Configure our target node without using keyword “when”.

📝Description:
✔To get the variable in which ansible stores the os_name of the host.
✔creating two variable files for each OS type
for Ubuntu: Ubuntu-20.yml
for RedHat: RedHat-8.yml
So on…
✔Creating a main playbook to configure webserver over Redhat and Ubuntu OS which would dynamically load that particular variable file as per OS name ansible retrieve from facts.

Description:

here, we are creating a playbook in such a way that it will retrieve the OS name for example if it is a Redhat OS then you package for httpd server is “httpd” but if you want the same for ubuntu OS then again the package name changes which is “apache”

So, we can do one thing that we can save this OS name in a variable OS_name then create two variable file one for Redhat OS and Ubuntu OS containing respective package name for Apache webserver.

dynamically load this variable file to the playbook.

Lets start…

Step1: Updated ips of systems in inventory

You can verify the connection using command

#ansible -m ping all

Step 2: To get the variable in which ansible stores the osname of the host

we need to go through the collected facts using command

#ansible all -m setup

Here, you can get the name and version of OS since you need to name variable file as <osname-version.yml>

ansible_distribution and ansible_distribution_version as the variables

Step 3: creating two variable files

for Ubuntu: Ubuntu-20.yml

for RedHat: RedHat-8.yml

Step 4: Creating final playbook to configure webserver over Redhat and Ubuntu OS.

this would dynamically load that particular variable file as per OS name ansible gets from facts.

I have add this to my webpage

Running the playbook we get

Now, checking for the webpage

Thankyou so much …!!!!

Hope you find it interesting…!!!!

Thankyou so much Vimal Daga Sir

--

--

--

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

Recommended from Medium

Data Structures in Python: Introduction

Why my blog is on Medium

Instructions for Deploying Public Unscoped Packages to NPM

Certified Kubernetes Administrator (CKA) exam tips and lessons learned

GSoC 2021 with NumFOCUS: NetworkX, Blog 0.0

Up for a challenge? Unit testing y’all!

Good Programmer Notes — p1

How real-time data anchoring finally puts legacy ERP systems to work.

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
anjali pandey

anjali pandey

More from Medium

Extract, Transform, Load (ETL) for Powerbank in Shopee

Prime Editing, the Future of Medicine??!

Chapter 10 — Step 2: Release (for Dave)

AltoTech — Dash and Plotly