Task Description: Create 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.
Note: No need to use when keyword here.
Approach we are going to use will be:
1st we will create a var file (variable file) to store variable and for that we will be using the jinja templating.
STEP-1: Updating Inventory File.

STEP-2: Creating the var-file.

STEP-3: Writing a Playbook
Now we would import the variable file in the YML file by writing {{ ansible distribution }} which would eventually be replaced by the exact same name of the Linux OS. And it would then replace the package name as httpd in the case of RedHat and apache2 in the case of Ubuntu.

STEP-4: Executing Playbook

Tadaaa….Setup and Task is all completed with zero erros, Hope you guys learned and enjoyed.