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. )

Description: Configure Apache webserver in RedHat and Ubuntu OS using Ansible Playbook. For RedHat OS we have httpd as a package name whereas for Ubuntu OS we have apache2 package for apache webserver.

AWS Console

Launched two instances of Redhat and Ubuntu/Debian OS

ansible facts for RedHat

We are going to use two variable from the ansible facts i.e distribution and distribution_major_version in the ansible playbook to load the variable file dynamically.

Create a variable file for Redhat and Ubuntu in a format like (<distribution>-<distribution_major_version>.yml)

(Note: It is case sensitive)

ansible facts for Ubuntu

I created different html file for Ubuntu (ubuntu.html) and RedHat (redhat.html) OS

and

This is the main ansible playbook

After running the PlayBook check the webserver configured or not

RedHat WebServer
Ubuntu WebServer

THANK YOU!!!