In this article i use two os Redhat and Ubuntu Os . we know that apache2 keyword use for Ubuntu and httpd keyword use for redhat For installing webserver . So here i use two seperate file and put variable name accordingly Os system By ansible_facts .
Ansible Facts :
Ansible you can retrieve or discover certain variables containing information about your remote systems or about Ansible itself. So here i use
ansible_facts variable to retrive ip of the os’s .
To see Facts of any os Following Command use :
# ansible IPOfos -m setup
"ansible_distribution_major_version" facts use here to know about OS name and its version so that we can create a dynamic playbook for deploying the webpage without using any condition.
Here is use Redhat-8.yml and Ubuntu-20.yml two file File name shoul align with os facts .
When Redhat os come then All variable come from Redhat-8.yml .When Ubuntu then variable come from Ubuntu-20.yml . So now Our Playbook will work as dynamic .
So after creating the Setup.yml run the Playbook
# ansible-playbook setup.yml
Now you can see both managed nodes (RedHat and Ubuntu) have configured and the webpage has deployed as the below clip is showing.
Successfully run ..
Visit my Github Profile :
Contribute to techy-mihir/Os_based_dynamic_ansibleplaybook development by creating an account on GitHub.
😊Thanks For reading ..😊