🔰 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.)

Let’s start this task very simple task the approach i used is with the concept of var_files.

Before I start explaining my start First lets see what all files we have for this task.

ANSIBLE CONFIGURATION FILE

INVENTORY FILE

These are the aws instances I’m using here and that’s why I am using ssh_private_key. Note the ansible_user image to image this might change so can check this user on aws instance part. Their select on the instance click on connect their they show the user_name.

Redhat user_name

These are the instances I’ll be using.

RedHat.html

Ubuntu.html

These are my variable files

YML FILE (setup.yml)

hosts: all -: this part contains two users as we already seen in the above inventory file.

become: true -: using privilege escalation so that we can use sudo power to configure the webserver.

var_files: in this we are using variable name ansible_distribution which we get during gathering of fact if it’s RedHat our RedHat.html file will be called. Why it’s important becaure different distributions contains different different package and service name and this cause issue because to install any package we must know the name of the package and for that we first know the name of distribution we are using.

Note !!

If u have some dependencies error this may occur due to ….

You are running this playbook in newly launched or provisioned instance this might fails due to extrapackages ( Ex. python) needed for ansible in the instances. For that U’ll have to add extra line of code in the starting of the yml code.

Ping the instances

ansible all -m ping

LETS RUN THE PLAYBOOK!!

OUTPUT ….

  1. RedHat Instance

2. Ubuntu Instance

TASK COMPLETED…..

For any query ping me and connect with me on LinkedIn www.linkedin.com/in/vineet-negi

--

--

--

★ Aspiring DevOps Engineer ★ Technical Volunteer @LinuxWorld ★ Technical Content Writer @Medium ★ ARTH Learner

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

An Introduction to AWS Security Groups

Top 5 Container-Based Tools For Deploying Internet of Things

NLP with Python

Agile vs. Zombies

Python for Absolute Beginners : Getting Started

Stop Putting Style, Scripts, BASE64 Images And SVG In Your Markup!

Chibi Adventurer Union NFT

Day 24 — Creating a Retro Game Over Behavior

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
Vineet Negi

Vineet Negi

★ Aspiring DevOps Engineer ★ Technical Volunteer @LinuxWorld ★ Technical Content Writer @Medium ★ ARTH Learner

More from Medium

“ONCE A MAPPER,YOU WILL ALWAYS BE.”

Classes during lockdown

Dexing Signals from noise — Personal Reflection

Spawning the Speed Boost