How to make an Ansible Playbook that dynamically imports the vars file by the OS name
Let’s start, before going ahead you have to ensure your ansible setup,
step1: Run the following command -:)
Here,
Instead of localhost, you can use any group,
Here you have to see two things one is “ansible_distribution” and the other is “ansible_distribution_version”.
ansible_distribution = Amazon
ansible_distribution_version=2
so the vars file for this instance would be = Amazon-2.yml
Note-:) we use (.yml) in each ansible file because the understand this data structure.
step2: Now create a variable file after doing the above step 1-:)
step3: Now write the variables inside the vars file-:)
step4: Now write the main playbook -:)
Note-: for the main file you can give any filename
Note-: main thing here only which is in yellow color.
We just import the file by using ansible facts, exact same syntax you have to use, between the distribution and distribution version you have to use “-”
step5: Let’s run the play-:)
here they import, and successfully did according to the tasks assigned,
Keep Learning Keep Sharing
MD MOQADDAS