Ansible Playbook — Target Node Configuration Using Variable File / Name

Source : Owner

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”.

  • 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 :

https://www.redhat.com/sysadmin/playing-ansible-facts

Tasks will be done step by step as followed :

vim ip.txt
ip.txt
sudo amazon-linux-extras install ansible2
vim ansible.cfg
ansible.cfg
ansible all --list-hosts
ansible all -m ping
vim RedHat.yml
vim Ubuntu.yml
vim task14.3.yml
14.3.yml
vim web.html
ansible-playbook task14.3.yml
  • 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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store