DYNAMIC VARIBALE FILE IN ANSIBLE

darshil shah
1 min readApr 30, 2021

Hello forks ,

Here i am again with new concept of ansible called dynamic variable file !

Requirement : -

we need dynamic variable fil because suppose we need to launch a http webserver and we have 2 targetted nodes one OS i sredhat and second OS is ubantu . so , for installing httpd in redht we use package name httpd while ubantu uses apach2 as a package name to install httpd !

Firstly we will create two variable files in which as per os required we will set two diffrent package name .

Ubuntu.yml
package: apache2
web_port: 80
RedHat.yml
package: httpd
web_port: 80

how we call neded file dynamically ? :- we will use ansible facts and we will fetch the distribution name which gives OS name so we can call needed OS variable file vice versa on run time dynamically !

That’s how we can use dynamic inventory on the run time as per OS by using ansible facts !

--

--

darshil shah

Integration is key , and thats what i love to do !