Creating an Ansible Playbook which will dynamically load the variable file named same as OS_Name just by using the variable names
Before we implement let’s have a brief idea about this task.
What is ansible?
Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows.
What is ansible playbook?
An Ansible® playbook is a blueprint of automation tasks — which are complex IT actions executed with limited or no human involvement. Ansible playbooks are executed on a set, group, or classification of hosts, which together make up an Ansible inventory.
What are ansible facts ?
Ansible facts are system properties that are collected by Ansible when it executes on a remote system. The facts contain useful details such as storage and network configuration about a target system.
Task: Creating an Ansible Playbook which will dynamically load the variable file named same as OS_name just by using the variable names
First we would launch two OS on AWS cloud such that one is RedHat and the other is ubuntu.
We could configure them for running web server separately.
Now we will update our inventory file with the IP addresses of the OS launched on the AWS server.
We have to create two different variable files in the YML format and keep the file name same as the OS i.e. RedHat and Ubuntu so that they will have the package name used in them for deploying web server over the Internet.
And then 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, then replace the package name as httpd in the case of RedHat and apache2 in the case of Ubuntu.
Now run the Ansible Playbook
It worked perfectly as it is not showing any error
Now we can open it in our chrome browser and see that our web page is displayed according to the Linux OS.
Thank you!!!