Ansible Playbook — Target Node Configuration Using Variable File / Name
Hello there, in this article, we will create an ansible Playbook which will dynamically load the variable file named the same as OS_name & just by using the variable names we can configure our target node.
Note: No need to use “when” keyword here
Before starting to deploy such system we will learn about the term known as “Ansible Facts”.
What is Ansible Facts ???
- Ansible facts are data gathered about target nodes (host nodes to be configured) and returned back to controller nodes. Ansible facts are stored in JSON format and are used to make important decisions about tasks based on their statistics. Facts are in an “ ansible_facts ” variable, which is managed by Ansible Engine.
- Ansible facts make it easier for sysadmins to control under what circumstances playbooks will run based on actual system information.
- You can also refer this documentation :
Tasks will be done step by step as followed :
Step 1 : Launching 3 Instances In AWS -
Step 2 : Create inventory file in our Controller node -
Step 3 : Install Ansible in our Controller node -
sudo amazon-linux-extras install ansible2
Step 4 : Create an Ansible configuration file in our Controller node -
Step 5 : To check the list of hosts -
ansible all --list-hosts
Step 6 : To ping our hosts -
ansible all -m ping
Step 7 : Creating the variable file in our controller node —
Step 7.1 : For RedHat OS —
Step 7.2 : For Ubuntu OS —
Step 8 : Creating a playbook to configure webserver -
Step 9 : Creating a Html file as “ web.html ” -
Step 10 : Execute our Ansible playbook using following command -
Step 11 : Our Output on target nodes —
- Finally we created the Ansible playbook which dynamically loads the variable file named the same as OS_name & just by using the variable names we can configure our target nodes.
Thank You for reading & learning with me.