✍Create an Ansible Playbook which will dynamically load the variable file named same as OS_name.

Priya Soni
6 min readApr 18, 2021

HELLO EVERYONE✌✌,

In this article, I will demonstrate How we can Create an ansible playbook which dynamically load the variable file named in same as os name.

And I will also show how to create our ansible playbook from the scratch . So , At the last we will Create An Ansible Playbook that will be doing each and everything for us.

✍TASK DESCRIPTION :

🔰 Create an Ansible Playbook which will dynamically
load the variable file named same as OS_name and just by
using the variable names we can Configure our target node.

(Note: No need to use when keyword here.)

Before doing any practical implementations It’s a good practice to create one directory to store all the files.

This directory is also known as our Workspace. In my system I created one workspace called “task14.3”. I am putting everything in this workspace and at the end of this article I will provide the GitHub link, from where you can download this workspace and also use it.

TO CHECKING THE ANSIBLE VERSION:

NOW, WE NEED TWO DIFFERENT TYPES OF OS.

IN MY CASE I AM USING MANAUL WAY TO LAUNCH EC2 INSTANCES OVER AN AWS CLOUD BUT YOU CAN ALSO USE ANSIBLE PLAYBOOK FOR LAUNCHING TWO DIFFERENT TYPES OF EC2 INSTANCES LIKE REDHAT LINUX AND UBUNTU FOR THIS TASK DEMONSTRATION.

THESE ARE THE FOLLOWING STEPS TO LAUNCH EC2 INSTANCES OVER AN AWS CLOUD:

STEP : 1

LOGIN TO YOUR AWS ACCOUNT

✍NEXT :

✍NEXT :

FOR AN UBUNTU OS:

✍NEXT :

✍NEXT :

✍NEXT :

✍NEXT :

✍NEXT :

✍NEXT :

✍NEXT :

✍NEXT :

✍NEXT :

✍NEXT :

SO, FINALLY WE HAVE SUCCESSFULLY LAUNCH UBUNTU OS OVER AN AWS CLOUD.

✍NEXT :

FOR REDHAT OS

✍NEXT :

✍NEXT :

✍NEXT :

✍NEXT :

✍NEXT :

✍NEXT :

✍NEXT :

✍NEXT :

✍NEXT :

SO, FINALLY WE HAVE SUCCESSFULLY LAUNCH REDHAT OS OVER AN AWS CLOUD.

✍NEXT :

STEP : 2

TO UPDATE THE IP’S IN THE INVENTORY FILE .

# vim ip.txt

STEP : 3

TO UPDATE THE ANSIBLE CONFIGURATION FILES.

# vim /etc/ansible/ansible.cfg

STEP : 4

YOU CAN ALSO VERIFY THE CONNECTION USING BELOW COMMAND.

# ansible -m ping all

STEP : 5

TO CRAETING TWO VARIABLE FILES.

# vim RedHat-8.yml

# vim Ubuntu-20.yml

STEP : 6

TO PROTECT A FILE AGAINST ACCIDENTAL OVERWRITING.

# chmod 400 aws_ansible.pem

STEP : 7

TO CREATE THE TEST FILE FOR CHECKING PURPOSE.

# vim test.yml

STEP : 8

TO RUN THE TEST RUN.

# ansible-playbook — syntax-check test.yml

# ansible-playbook test.yml

✍NEXT :

STEP : 9

TO CREATING OUR FINAL PLAYBOOK FOR CONFIGURE WEBSERVER ON REDHAT AND UBUNTU OS OVER AN AWS CLOUD.

THIS WOULD DYNAMICALLY LOAD THAT PARTICULAR VARIABLE FILE AS PER OS NAME ANSIBLE GETS FROM FACTS.

# vim task14.3.yml

STEP : 10

TO RUN THE TEST RUN.

# ansible-playbook — syntax-check task14.3.yml

# ansible-playbook task14.3.yml

✍NEXT :

SO, FINALLY OUR ANSIBLE PLAYBOOK RUN SUCCESSFULLY.

NOW, CHECKING FOR THE WEBPAGES.

TO ACCESS THE WEBPAGE:

ip/index.html

✍NEXT :

Finally I have successfully completed my this task. Thank you Vimal Daga sir for giving me such a great task. Sir your mentorship is a God gift for me to enhance my skills and I am very blessed because you are my mentor.

So guys, In the upcoming days I am going to be publish a lots of blogs and articles on different different automation tools and other technologies, So definetely follow me on Medium as well as on linkedin.

I have also provide the link of my Github repository for this task which is given below for your reference.

So, Here is my linkedin profile if you have any queries definitely comment below or DM me on linkedin.

SEE YOU IN THE NEXT BLOG WITH SOME AMAZING TASKS.

THANK YOU🙏🙏 GUYS FOR READING MY BLOG…

SIGNING OF FORM MY SIDE 👋👋

KEEP LEARNING🙇‍♂️📖🙇….

KEEP SHARING✌✌…

--

--