ANSIBLE PLAYBOOK WHICH USES A VARIABLE FILE SAME AS OS NAME AND CONFIGURE TARGET NODE USING IT.

Himanshu Yadav
2 min readJan 23, 2021

Ansible is a great tool for automation as it is very intelligent and just need SSH to do tasks inside a system. It automatically finds what type of os system is having and run Commands according to that. It creates a RAL (Resource Abstraction Layer) which figures out the os of target node and convert our given task to that os specific Command almost 99% of time.

But when working with multiple OSes, inevitably there will be packages, configuration files and service calls that are vastly different than one another.here can even be instances in which sub-versions of OSes can have major differences, such as service vs. systemctl in CentOS 6 vs. 7.

So to solve that problem we make use of RAL and create files which contains package , services according to the name of OS.

Here we create a file for our Redhat8 system and name it as Redhat8.

Now we create variables inside this file which are specific to a Redhat OS

Now we make use of RAL and by using Ansible facts we know the os name and version and use their name as file in var_files so file in var_files changes according to os name and version and vra_files only takes that file which is named as Given os and version and thus uses variables specific to that os. In my case its Redhat8.

So now we write a Ansible-playbook using these variables to run some tasks for us.

Now when we run it finds these variable values and run tasks accordingly. Here we have started a httpd service using thise variables.

That’s it.

Thank you.

TASK#14.3

--

--