Automation With Ansible Playbooks - Narendra Kumar Reddy Polu

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1102

Transcript

00:00:00.000
00:00:05.100
Hi friends, welcome to Automation
with Ansible Playbooks course

00:00:05.100
00:00:08.199
and this is Narendra instructor for this
course.

00:00:08.199
00:00:11.800
Friends, I am designing this course
based on my experience

00:00:11.800
00:00:15.700
and believe me this is what will cause
to learn how to write Playbooks

00:00:15.700
00:00:17.800
from basic to advanced level.

00:00:17.800
00:00:21.200
I mean, by including different concepts
of your playbooks

00:00:21.200
00:00:28.100
like files, templates, handlers, rule,
wall and so many concepts.
00:00:28.100
00:00:31.400
Friends learning and Ansible engine is
not a big task.

00:00:31.400
00:00:34.700
The big task is how do to Implement
playbooks for different

00:00:34.700
00:00:37.600
environments based on requirement?

00:00:37.600
00:00:42.700
Anyway, here you will get clearer
exposure to implement playbooks

00:00:42.700
00:00:47.500
from basic to advanced level based on
your requirement.

00:00:47.500
00:00:50.800
And I will start this course from
Ansible engine.

00:00:50.900
00:00:53.500
Once it is done with Ansible engine
then we'll enter into

00:00:53.500
00:00:56.700
implementation of Playbooks part.

00:00:56.700
00:01:00.800
And friends, we know that in many
organizations or environments.

00:01:00.800
00:01:05.200
There are so many tasks which we
used to do it manually.

00:01:05.200
00:01:08.800
So, the primary focus of this course is
to understand how

00:01:08.800
00:01:12.800
we can automate different tasks
through playbooks to make

00:01:12.800
00:01:16.000
our environment free from manual
intervention.

00:01:16.000
00:01:18.900
So, that is our primary focus in this
course.

00:01:18.900
00:01:24.200
Anyway, before going to start with our
course, you need some prerequisite.
00:01:24.200
00:01:27.100
They are, you should have some
minimum knowledge

00:01:27.100
00:01:30.200
on any Unix-like based operating
system,

00:01:30.200
00:01:37.900
because your Ansible is an open-
source software available for Linux based systems.

00:01:37.900
00:01:40.800
That's why you should have some
minimum knowledge on any

00:01:40.800
00:01:45.200
Unix-like base do operating systems
along with that.

00:01:45.200
00:01:50.000
You should have some knowledge on
any Cloud or VMware, because

00:01:50.000
00:01:54.200
See, we know that ansible is used to
work with multiple servers at a time.

00:01:54.200
00:01:57.700
Now, while practicing you have some
number of servers

00:01:57.700
00:01:59.700
in your hand, right?

00:01:59.700
00:02:04.600
So that's why while practicing to get
number of servers, right?

00:02:04.600
00:02:06.600
I am using either cloud or VMware.

00:02:06.700
00:02:10.300
I mean, I'm going to create number of
servers from Cloud

00:02:10.300
00:02:11.600
or VMware.

00:02:11.600
00:02:14.500
Anyway, I will create from AWS Cloud,
but you can you can

00:02:14.500
00:02:20.300
take any Cloud or VMware just to
launch our number of servers, right.
00:02:20.300
00:02:25.200
and then, see basically Ansible is
going to perform

00:02:25.200
00:02:27.600
any task based on modules.

00:02:27.600
00:02:31.500
I mean, whatever the task you want to
perform through Ansible.

00:02:31.500
00:02:35.200
You can perform by using modules
concept.

00:02:35.200
00:02:39.800
Sometimes you may not find default
module to perform your tasks.

00:02:39.800
00:02:42.800
So, at the time you can develop your
own modules, if

00:02:42.800
00:02:45.900
you know some programming
knowledge, but it's not mandatory

00:02:45.900
00:02:49.400
because most of the times you are
going to use default modules.

00:02:49.400
00:02:52.200
But if you want, if you want to develop
your own modules,

00:02:52.200
00:02:55.200
you should have some programming
knowledge.

00:02:55.200
00:03:01.300
So that programming maybe Python
or Ruby or C++ or Bash?

00:03:01.300
00:03:06.600
But it's better to learn Python, because
Ansible itself, it is developed with Python.

00:03:06.600
00:03:09.600
So, if you know Python you can easily
understand Ansible

00:03:09.700
00:03:12.600
and then you can easily develop your
own modules,

00:03:12.600
00:03:15.600
but it's not mandatory, right, fine.
00:03:15.600
00:03:19.300
[No audio.]

00:03:19.300
00:03:23.900
Friends mastering automation with
Ansible and Ansible Playbooks

00:03:23.900
00:03:25.700
is a step-by-step journey.

00:03:25.700
00:03:30.400
That's why, I divided the entire course
content into some parts.

00:03:30.400
00:03:35.300
So, in part one, we are going to see
introduction part with Ansible

00:03:35.300
00:03:37.300
and then deploying Ansible

00:03:37.300
00:03:42.800
and these are the concept we are
going to cover in this part 1

00:03:42.800
00:03:46.000
Right, then in part two.

00:03:46.000
00:03:50.900
We are going to work completely with
Playbooks.

00:03:50.900
00:03:55.200
So, and here we are going to see
these are the concepts under

00:03:55.200
00:03:58.000
your Playbooks.

00:03:58.000
00:04:01.900
So, once it is done, then we are
entering into part 3.

00:04:01.900
00:04:05.900
So here we are going to see, building
own modules and then

00:04:05.900
00:04:11.700
implementing some Ansible Playbooks
for AWS cloud. Right.

00:04:11.700
00:04:18.000
So guys, this is my entire raw course
content, in this course. Okay.

00:04:18.000
00:04:20.200
Okay guys. Thank you for watching
this video.
Transcript
00:00:00.000
00:00:02.000
Friends,

00:00:02.000
00:00:05.900
here we are going to discuss about
introduction to Ansible.

00:00:05.900
00:00:08.500
Anyway, before going to start with this
concept.

00:00:08.500
00:00:12.900
I want to tell you a story, before
Ansible or any other configuration

00:00:12.900
00:00:16.500
management tools, with simple task.

00:00:16.500
00:00:22.200
So, my task is, first of all just assume
that we have hundred servers in our environment

00:00:22.200
00:00:30.900
and we need to configure or install a
two packages of vim and wget on all these hundred servers.

00:00:30.900
00:00:34.300
Right, first let me start with one server
00:00:34.300
00:00:38.300
now to install these 2 packages on
one server.

00:00:38.300
00:00:41.400
What are the manual steps we have in
our hand.

00:00:41.400
00:00:43.700
So, first step we need to log into that
server.

00:00:43.700
00:00:50.900
Second step, we need to check it
maybe if already vim or wget packages are there or not.

00:00:50.900
00:00:55.700
If they are not then we need to install
using some commands.

00:00:55.700
00:00:58.000
Right.

00:00:58.000
00:01:02.000
So, simply we are going to install vim
and wget command

00:01:02.000
00:01:06.300
on one server by taking these steps
and assume that this

00:01:06.300
00:01:09.500
process took 6 minutes of time for one
server,

00:01:09.500
00:01:12.700
but we have 100 servers then.

00:01:12.700
00:01:18.600
You're going to take 600 minutes,
which is equals to 10 hours of time.

00:01:18.600
00:01:22.000
Right. Now, instead of manual steps.

00:01:22.000
00:01:25.600
I am trying to automate this with some
Shell Script , because

00:01:25.600
00:01:28.600
I assume that we are good at Shell
Script.

00:01:28.600
00:01:31.700
Now, I am trying to automate these
tasks with Shell Script.
00:01:32.700
00:01:35.300
Now for that, I implemented 2 Shell
scripts

00:01:35.300
00:01:41.200
1 Shell Script is just to install your vim
and wget, on one server.

00:01:41.200
00:01:43.700
Now, if you know Shell Script for 1
server.

00:01:43.700
00:01:47.300
Now, what I am doing is I am writing
one more Shell Script

00:01:47.300
00:01:48.400
in this Shell Script.

00:01:48.400
00:01:51.300
I'm doing is, in a list of servers . txt file.

00:01:51.300
00:01:55.600
I'm going to mention all my 100
servers, now with the help of For Loop,

00:01:55.600
00:01:58.600
I am taking one by one server and I
am trying to copy this

00:01:58.600
00:02:02.500
script to your remote server, then and I
am trying to install,

00:02:02.500
00:02:05.800
that script on your remote server so
that you are going to

00:02:05.800
00:02:10.500
install, your vim and wget packages
on each and every server.

00:02:10.500
00:02:15.300
Right, simply your first script is just to
install, but second

00:02:15.300
00:02:18.100
script is whatever the script you have
here that script

00:02:18.100
00:02:21.700
we are copying to remote server and
we are trying to execute

00:02:21.700
00:02:24.500
through ssh that script on remote
server.
00:02:24.500
00:02:29.700
That's it now assume, that you're
going to take 3 minutes

00:02:29.700
00:02:33.300
of time to complete, for each server.

00:02:33.300
00:02:34.400
Then again.

00:02:34.400
00:02:36.900
We have actually 100 of 100 servers
right, then

00:02:36.900
00:02:43.100
it is going to take almost 300 minutes,
which is equals to 5 hours of time.

00:02:43.100
00:02:45.200
We automate it.

00:02:45.200
00:02:49.900
Right, but anyway, to complete our
task this process is taking

00:02:49.900
00:02:54.200
5 hours or 300 minutes of time.

00:02:54.200
00:02:57.100
So, what is the disadvantage here?

00:02:57.100
00:03:00.200
Is there any possibility to reduce your
time to install your

00:03:00.200
00:03:03.200
vim and wgate?

00:03:03.200
00:03:06.400
First of all, try to think about what is
the disadvantage here.

00:03:06.400
00:03:09.100
The disadvantage is first of all, it is an
advantage

00:03:09.100
00:03:12.700
compared to your previous process.
compared to your manual steps,

00:03:12.700
00:03:15.300
but the disadvantage is if you observe
here,

00:03:15.300
00:03:20.700
we are trying to copy, our install script
to your remote server
00:03:20.700
00:03:23.100
and then we are installing, once it is
done

00:03:23.100
00:03:26.600
then we are going to copy same script
to another server

00:03:26.600
00:03:31.400
I mean next server then after
completion of the task comes second server.

00:03:31.400
00:03:33.700
We are going to work with third server.

00:03:33.700
00:03:39.600
I mean, we are executing our task,
serially not parallelly.

00:03:39.600
00:03:42.300
That's why it is going to take 300
minutes of time.

00:03:42.300
00:03:48.200
If you are able to execute this task
parallelly at a time

00:03:48.200
00:03:50.900
on all 100 servers, then you're going
to complete

00:03:50.900
00:03:55.400
your task in 3 minutes instead of 300
minutes.

00:03:55.400
00:04:03.000
Right. Now, to execute our task, to
install simply vim and wget commands

00:04:03.000
00:04:05.600
on all 100 servers parallelly.

00:04:05.600
00:04:09.700
I am going with another way of
automation.

00:04:09.700
00:04:12.300
That is simply with the configuration
management tools.

00:04:12.300
00:04:14.300
[No audio]

00:04:14.300
00:04:18.100
Right see guys, we have different
types of configuration management tools.
00:04:18.100
00:04:19.800
You can go with anyone of that.

00:04:19.800
00:04:22.399
So, in this course, we are going to
work with Ansible.

00:04:23.399
00:04:28.500
Anyway, you have advantages and
disadvantages with each and every tool,

00:04:28.500
00:04:35.400
right, but to work with your Unix-like
systems Ansible is the best way.

00:04:35.400
00:04:43.600
Right, fine. Now, Ansible will execute a
task on all servers parallelly, right?

00:04:43.600
00:04:47.100
So, we know that to execute our task
on one server.

00:04:47.100
00:04:50.700
We are taking 3 minutes of time.

00:04:50.700
00:04:54.400
Now, if you go with Ansible, Ansible is
going to execute your

00:04:54.400
00:04:56.200
tasks and all servers parallelly.

00:04:56.200
00:05:00.200
That means, you are going to
complete your task in 3 minutes

00:05:00.200
00:05:05.000
instead of 300 minutes or 600
minutes.

00:05:05.000
00:05:05.500
Right.

00:05:05.500
00:05:08.800
So that is the advantage one of the
simple advantages of

00:05:08.800
00:05:11.900
your configuration management tools.

00:05:11.900
00:05:15.800
And one more thing generally writing
Shell Script is complex

00:05:15.800
00:05:21.200
compared to Playbooks and
Playbooks are very short, in code length.
00:05:21.200
00:05:25.800
See, I mean Playbooks are nothing
but one of the

00:05:25.800
00:05:31.200
scripting language, scripts to work with
your Ansible, right

00:05:31.200
00:05:33.500
and we will discuss about Playbooks
while going forward for

00:05:33.500
00:05:35.600
time being assume that, like Shell
Script.

00:05:35.600
00:05:37.900
There is a one Playbook.

00:05:37.900
00:05:42.000
Now, writing Shell Script is complex,
compared to your Playbooks

00:05:42.000
00:05:47.700
and moreover, the length of the
Playbooks is very short compared to your Shell Script.

00:05:47.700
00:05:51.600
Let me show you that, first of all, let
me show you the Shell Script,

00:05:51.600
00:05:53.900
which we use to automate our task.

00:05:53.900
00:05:58.500
So, these are the lines we
implemented, in terms of Shell Script, to automate our task.

00:05:58.500
00:06:02.300
Now, if you go with Playbook see that

00:06:02.300
00:06:04.255
we have very a smaller number of
lines.

00:06:04.255
00:06:06.600
[No audio]

00:06:06.600
00:06:10.000
And as of now whatever the Shell
Script you have that Shell Script

00:06:10.000
00:06:14.500
is just to install, by checking vim and
wget packages
00:06:14.500
00:06:18.900
are not there, if they are not then we
are installing suppose.

00:06:18.900
00:06:27.000
I assume, that I need to install latest
version of vim and wget commands

00:06:27.000
00:06:29.400
or packages on my all servers.

00:06:29.400
00:06:32.100
So, I need to add some more lines
here.

00:06:32.100
00:06:38.400
So, suppose if already installed then
where is the existing version of your wget and vim,

00:06:38.400
00:06:43.500
then if that version is less than the
latest version

00:06:43.500
00:06:48.300
then I need to install your latest
version of your vim and wget.

00:06:48.300
00:06:50.600
I mean, I need to add some more lines

00:06:50.600
00:06:55.700
in case, if you want to install latest
version of vim and wget

00:06:55.700
00:06:58.600
packages and all your 100 servers.

00:06:58.600
00:07:04.400
But in Playbook, simply instead of
your, present if you write latest.

00:07:04.400
00:07:07.100
Then it is going to install latest version
in case

00:07:07.100
00:07:09.200
you're server is not having latest
version.

00:07:09.200
00:07:11.300
Then it is going to install latest version.

00:07:11.300
00:07:13.000
If it is already there with the latest
version.
00:07:13.000
00:07:18.500
Then you are Ansible won't do any
modification on the existing version.

00:07:18.500
00:07:22.400
[No audio]

00:07:22.400
00:07:28.100
One of the advantages with your
Ansible or with Ansible with Playbooks.

00:07:28.100
00:07:29.300
Right.

00:07:29.300
00:07:35.700
So, first thing writing playbooks are
very easy to automate a task.

00:07:35.700
00:07:36.600
Second thing.

00:07:36.600
00:07:40.800
You are going to implement your
Playbooks with less number of lines.

00:07:40.800
00:07:42.300
[No audio]

00:07:42.300
00:07:43.000
Right.

00:07:43.000
00:07:44.400
So, not only with your Playbooks.

00:07:44.400
00:07:49.200
I mean not only with your Ansible, you
can use any configuration management tools

00:07:49.200
00:07:52.400
to automate your task for your number
of servers.

00:07:52.100
00:07:54.000
[No audio]

00:07:54.000
00:07:58.100
Right, fine. Now, let me go with your
introduction to Ansible.

00:07:58.100
00:08:03.200
Now, we know that, Ansible is one of
the automation tools.

00:08:03.200
00:08:06.300
Right, just now we automated
something, right?
00:08:06.300
00:08:09.100
Guys, I will be going forward I will
show you, I will execute

00:08:09.100
00:08:11.500
you this task and I will show you, how
much time it is going

00:08:11.500
00:08:16.700
to take to work, with your number of
servers, right, fine.

00:08:16.700
00:08:20.600
Now Ansible is an automation tool,
right?

00:08:19.700
00:08:23.100
[No audio]

00:08:23.100
00:08:26.400
Along with that, it is an open-source.

00:08:26.400
00:08:30.900
So, you can download without buying
any license.

00:08:30.900
00:08:36.100
So, simply Ansible is an open-source
automation tool.

00:08:36.100
00:08:40.100
It is very, very simple to set up and
powerful as well.

00:08:40.200
00:08:42.700
[No audio]

00:08:42.799
00:08:43.299
Right.

00:08:43.299
00:08:47.500
So, if you want to make a setup of
Ansible on your environment,

00:08:47.500
00:08:51.299
it is very simple and it is also powerful

00:08:51.299
00:08:58.500
and Ansible will be helpful to perform
different kind of tasks.

00:08:58.500
00:09:02.900
So. just now we have seen one of the
usages, like a configuration.

00:09:02.900
00:09:06.400
So, if we are configuring all 100
servers with your Ansible.
00:09:06.400
00:09:08.000
[No audio]

00:09:08.000
00:09:11.200
You are vim and wget packages.

00:09:11.200
00:09:16.300
Right, not only for that, you can do
some Application Deployment

00:09:16.300
00:09:23.300
and any Task Automation and also
you can do IT orchestration.

00:09:23.300
00:09:27.900
Right, so through Ansible you can do
these many things and

00:09:27.900
00:09:30.500
this is just simply introduction part
guys, while going forward

00:09:30.500
00:09:36.000
we will see in detail, each and every
point with your Ansible.

00:09:36.000
00:09:37.300
Right. Okay guys.

00:09:37.300
00:09:39.700
Thank you for watching this video.
Transcript
00:00:00.000
00:00:02.500
[no audio] Friends here.

00:00:02.500
00:00:06.300
We are going to discuss about ansible
architecture first.

00:00:06.300
00:00:09.300
Let me show you complete
architecture for your ansible.

00:00:09.600
00:00:12.600
So this is the complete architecture for
your ansible.

00:00:13.400
00:00:16.399
But as of now, I'm not going to explain
about this or picture

00:00:16.900
00:00:19.400
because you don't know so many
things from this architecture.

00:00:20.000
00:00:23.000
So first I want to use simple ansible or
picture with an
00:00:23.000
00:00:27.200
example and while going forward, we
will come to know different

00:00:27.200
00:00:31.500
concepts of your ansible so that I can
add the Mining blocks

00:00:31.700
00:00:33.100
with your ansible or picture.

00:00:33.500
00:00:36.700
So finally we can make complete
architecture offer mowing

00:00:37.100
00:00:38.100
all Concepts.

00:00:39.600
00:00:43.600
Right final friends just assume that
you are having some

00:00:43.600
00:00:45.600
number of servers in your
environment.

00:00:46.200
00:00:46.800
As of now.

00:00:46.800
00:00:50.700
I am taking only three servers not only
three can take any

00:00:50.700
00:00:55.900
number of servers and my intention is
I want to install VI

00:00:55.900
00:01:00.100
M and W get packages on all these
three servers using ansible.

00:01:01.000
00:01:04.099
That means simply I want to manage
all these three servers

00:01:04.099
00:01:05.099
with ansible.

00:01:06.099
00:01:09.300
So that's why I need one extra server
where I am going to

00:01:09.300
00:01:10.400
install my ansible.

00:01:12.300
00:01:17.600
Right now see these three or you are
required servers and
00:01:17.600
00:01:18.500
this is the server.

00:01:18.700
00:01:21.700
So on the top of this I am going to
install my ansible.

00:01:23.100
00:01:27.600
right now for this set of servers.

00:01:27.800
00:01:30.600
We have some terminology in your
ansible architecture.

00:01:30.700
00:01:35.000
That is This Server, I mean where you
install your ansible

00:01:35.000
00:01:38.600
that is called simply ansible engine or
ansible controller

00:01:38.700
00:01:42.800
or ansible master and the servers
which you are going to

00:01:42.800
00:01:45.900
manage with your ansible these
servers remote servers.

00:01:46.000
00:01:51.800
They are called simply ansible nodes
or clients right now

00:01:51.800
00:01:54.500
in your ansible architecture, you know,
two things one is

00:01:54.600
00:01:57.800
ansible engine and second one is
ansible clients.

00:01:59.700
00:02:05.600
Right fine now using your ansible
engine, you're going to

00:02:05.600
00:02:08.400
manage your going to work with all
these three servers.

00:02:08.800
00:02:13.600
So how your ansible engine can
understand that your ansible

00:02:13.800
00:02:15.600
your remote servers information.
00:02:15.800
00:02:20.000
I mean for which servers you're going
to work with your ansible,

00:02:21.000
00:02:25.300
right? So we need to provide the
remote servers IP address

00:02:25.300
00:02:27.500
or fqdn with your ansible engine.

00:02:29.000
00:02:34.400
Now I am going to manage one of file
on your ansible engines

00:02:34.600
00:02:38.700
server. So in that file, I am going to
provide the information

00:02:38.700
00:02:41.900
about your remote servers in terms of
IP address, or maybe

00:02:41.900
00:02:43.800
you can use some fqdn.

00:02:45.400
00:02:49.400
right now we have one file on your
ansible engine so that

00:02:49.400
00:02:55.000
file right consists of the information IP
information or

00:02:56.400
00:03:00.200
Fqdn information about your remote
servers and that file

00:03:00.200
00:03:02.300
is called simply inventory file.

00:03:04.400
00:03:06.500
Right simply inventory file.

00:03:06.700
00:03:07.200
That's it.

00:03:08.600
00:03:13.700
Then we have one more file called
ansible dot C of G or simply

00:03:13.700
00:03:15.400
ansible configuration file.

00:03:16.600
00:03:19.600
See while working with your remote
servers, right?
00:03:19.800
00:03:23.000
So with what user you want to work or
what is the password

00:03:23.000
00:03:26.000
for your remote server user?

00:03:27.700
00:03:31.700
And we have different parameters to
work with your remote

00:03:31.700
00:03:36.300
servers. So all those parameters we
can Define in this ansible

00:03:36.300
00:03:37.300
dot CFG file.

00:03:38.200
00:03:43.500
Not only that you can also provide the
location of your inventory

00:03:43.500
00:03:47.300
file. You can write this inventory file in
any location on

00:03:47.300
00:03:51.900
your host and you can provide that
location or complete path

00:03:51.900
00:03:55.800
of your inventory file in this ansible dot
CFG file so that

00:03:56.000
00:04:00.100
while doing the tasks on your remote
server by your ansible

00:04:00.100
00:04:03.800
engine and selenium can understand
the information about

00:04:03.800
00:04:07.000
inventory. And what is the user to work
with your remote

00:04:07.000
00:04:09.300
servers on what is the password to
work with your remote

00:04:09.300
00:04:10.800
server all those things?

00:04:11.700
00:04:15.900
We take from this ansible dot CFG file,
of course, we have
00:04:15.900
00:04:19.700
different locations, but he is the also
one of the file to

00:04:19.700
00:04:22.899
provide your information about your
remote servers.

00:04:23.899
00:04:26.300
So ansible dot CSV file is very very
important.

00:04:26.399
00:04:30.400
So in this you're providing different
parameters about your

00:04:30.400
00:04:36.100
remote server words, Right fine then
see now.

00:04:37.100
00:04:40.600
We are ready to work with your
remote servers now to work

00:04:40.600
00:04:41.700
with your remote servers.

00:04:41.900
00:04:46.400
So what is the our task install VA M
and W gate now?

00:04:46.900
00:04:53.000
I can run my task on remote server in
terms of commands or

00:04:53.000
00:04:57.200
in terms of a script that means on my
ansible engines are

00:04:57.200
00:05:02.100
were I can write some simple script or
some commands so that

00:05:02.100
00:05:04.700
simple It is called a Playbook or
directly.

00:05:04.700
00:05:06.100
I can provide some commands.

00:05:06.100
00:05:07.900
They are called Rock commands.

00:05:08.500
00:05:11.300
Anyway, your playbook and
commands.
00:05:11.400
00:05:15.400
We are going to implement in terms of
modules modules are

00:05:15.400
00:05:19.500
nothing but just some steps to execute
your tasks on remote

00:05:19.500
00:05:21.000
server. That's it.

00:05:22.100
00:05:25.600
Right now to execute our task on
remote server.

00:05:25.700
00:05:28.500
I mean to install your VA M and W get
packages.

00:05:28.800
00:05:31.600
We have a script or ad hoc
commands.

00:05:31.900
00:05:36.000
Now, we are ready to execute or task
on remote server now

00:05:36.000
00:05:39.600
to execute our task on remote server
will give one instruction

00:05:39.800
00:05:43.200
to your ansible engine just assume
that we have given so

00:05:43.200
00:05:47.100
whenever if you write your answer will
is going to execute

00:05:47.100
00:05:49.600
your task parallely on all servers.

00:05:52.300
00:05:57.300
right fine Now how your answer is
going to connect with your

00:05:57.300
00:06:00.600
remote servers say we are connecting
with your I mean you

00:06:00.600
00:06:03.800
are answerable engine is going to
connect with your remote

00:06:03.800
00:06:06.000
servers and it is going to execute your
task.
00:06:06.700
00:06:09.400
So how it is going to execute how it is
going to connect

00:06:09.400
00:06:13.900
with your remote servers simply by
using your SSH connectivity.

00:06:15.100
00:06:18.700
So whenever if you are giving
instruction to the ansible

00:06:18.700
00:06:22.100
to execute your task on remote
servers and simple we will

00:06:22.100
00:06:26.700
use SSH connectivity to work with
your remote servers.

00:06:27.200
00:06:27.700
That's it.

00:06:29.000
00:06:33.200
So this is the simple ansible
architecture and here you need

00:06:33.200
00:06:35.100
to understand one very very important
point.

00:06:35.100
00:06:41.000
That is just absorb that See, I'm
installing ansible here,

00:06:41.600
00:06:45.100
and I'm not going to install anything on
your ansible nodes

00:06:45.100
00:06:45.900
or clients.

00:06:47.400
00:06:50.500
We are not going to install any
software any piece of software

00:06:50.500
00:06:54.400
or any agent on your remote servers
to work with ansible

00:06:54.800
00:06:56.300
on all these three servers.

00:06:56.800
00:07:01.800
That's why simply simply ansible is
called agentless architecture.
00:07:03.900
00:07:07.800
That means we are not installing any
simple software on your

00:07:07.800
00:07:12.400
remote servers to work from this
ansible engine, right?

00:07:12.400
00:07:15.100
That's why ansible is called agentless.

00:07:16.200
00:07:17.500
Right fine.

00:07:17.600
00:07:21.100
So this is the simple ansible
architecture friends while

00:07:21.100
00:07:21.800
going forward.

00:07:21.800
00:07:24.600
We will come to know different
concepts based on that.

00:07:24.700
00:07:28.000
I will add some more blocks here so
that you can understand.

00:07:28.200
00:07:29.900
What is the architecture of your
ansible.

00:07:31.000
00:07:34.000
Right fine friends in Market.

00:07:34.000
00:07:36.800
We have different types of
configuration management tools

00:07:37.000
00:07:40.200
then why only ansible or what are the
advantages with your

00:07:40.200
00:07:46.200
ansible? See very first one is it is a
free open-source automation

00:07:46.200
00:07:48.200
tool and it is very simple one.

00:07:50.700
00:07:54.400
So you don't need to buy any license
to use your ansible

00:07:54.400
00:07:58.700
engine. Right, and then it is very
simple.
00:07:58.700
00:08:02.900
You can easily understand this ansible
configuration management

00:08:02.900
00:08:07.800
tool. And second one is see you're
going to work with your

00:08:07.800
00:08:08.600
remote servers.

00:08:08.600
00:08:11.500
I mean by using your answer will
engine you're going to connect

00:08:11.500
00:08:13.700
with your ansible nodes or clients.

00:08:14.700
00:08:18.000
To connect with that you no need to
install any extra software

00:08:18.400
00:08:21.400
see by default with your all Enix like
BAE Systems.

00:08:21.400
00:08:26.500
You have openssh simply ansible is
using that software to

00:08:26.500
00:08:29.400
work with your remote servers or to
work with your ansible

00:08:29.400
00:08:30.600
nodes or clients.

00:08:32.700
00:08:35.700
So we don't need to install any extra
software other than

00:08:35.700
00:08:36.500
ansible, right?

00:08:36.700
00:08:39.600
So that is also one of the advantage
that's why we are going

00:08:39.600
00:08:40.600
to select ansible.

00:08:41.900
00:08:46.900
then agentless So to work with your
ansible clients or nodes,

00:08:46.900
00:08:49.799
we are not installing any agent or
software on your remote
00:08:49.799
00:08:51.900
servers or your answer will clients.

00:08:52.200
00:08:53.799
That's why it is called agentless.

00:08:55.000
00:09:02.600
right fine then ansible users python
rml basis in taxes So,

00:09:02.600
00:09:06.100
you know python it is very easy
language, right?

00:09:06.800
00:09:08.900
You can easily understand pythons in
taxes.

00:09:10.100
00:09:13.800
So whenever if you want to write some
scripts, you can easily

00:09:13.800
00:09:17.500
understand your script or you can
easily rip lament your

00:09:17.500
00:09:20.400
scripts to automate your tasks through
your ansible.

00:09:21.700
00:09:26.500
Then anyway it is highly flexible
configuration management

00:09:26.600
00:09:27.800
of for your systems.

00:09:29.700
00:09:34.900
And there are large number of ready
to use modules for your

00:09:34.900
00:09:36.200
system management.

00:09:36.600
00:09:40.500
So if you want to perform any task on
your nodes or clients

00:09:40.500
00:09:43.700
using ansible engine each and every
task you need to execute

00:09:43.700
00:09:45.000
by one module.

00:09:46.500
00:09:49.800
Whatever the task for each and every
task you have em separate
00:09:49.800
00:09:54.700
module so that type of modules we
have large number of modules.

00:09:56.000
00:09:58.700
It's like, you know, if you know python
there are some predefined

00:09:58.700
00:09:59.500
modules, right?

00:09:59.500
00:10:02.000
So what is the advantage with
predefined modules, you know

00:10:02.000
00:10:03.500
need to write code from scratch.

00:10:03.800
00:10:06.000
Just you are going to use existing
module and you are going

00:10:06.000
00:10:07.300
to complete your task.

00:10:07.600
00:10:08.100
That's it.

00:10:09.600
00:10:13.800
And in case if you want to Define your
own modules custom

00:10:13.800
00:10:16.600
modules, you can develop and you
can use them.

00:10:18.200
00:10:21.700
So guys because of all these
advantages and symbol is a popular

00:10:21.700
00:10:25.300
one or because of all these
advantages.

00:10:25.300
00:10:29.000
We are going to use ansible on your
index like BAE Systems.

00:10:29.500
00:10:32.500
Anyway, you can also work with your
windows as well using

00:10:32.500
00:10:33.700
ansible. We will see them.

00:10:35.100
00:10:35.600
Right.
00:10:36.300
00:10:36.900
Okay guys.

00:10:36.900
00:10:38.300
Thank you for watching this video.
Transcript
00:00:00.000
00:00:02.100
Friends here.

00:00:02.100
00:00:05.700
We are going to discuss about ansible
installation and configuration

00:00:05.700
00:00:08.800
part. But before going to enter into this
concept, let me

00:00:08.800
00:00:11.400
show you what is the ansible
architecture.

00:00:11.500
00:00:16.000
Anyway, we have seen a simple
ansible architecture, right?

00:00:16.000
00:00:18.800
So here we are assuming that in our
environment.

00:00:18.800
00:00:20.300
We have suppose three servers.
00:00:20.500
00:00:23.900
Not only three you may have
hundreds servers also, but here

00:00:23.900
00:00:27.300
I'm assuming there are three servers
in my environment and

00:00:27.300
00:00:30.100
I want to manage these three servers
with the help of ansible.

00:00:30.400
00:00:33.600
That's why Going to take one extra
server and on the server.

00:00:33.600
00:00:35.300
I am going to install my ansible.

00:00:36.300
00:00:39.200
Once you install your hands will on the
server right now.

00:00:39.200
00:00:42.400
We are calling This Server as simply
ansible engine or ansible

00:00:42.400
00:00:45.700
controller or controller node or Master
node.

00:00:47.300
00:00:51.300
Right fine now using this ansible you
are going to manage

00:00:51.300
00:00:52.900
your environment servers.

00:00:53.600
00:00:56.700
So now these three servers are called
simply ansible nodes

00:00:56.700
00:00:58.500
or clients or remote nodes.

00:00:58.900
00:01:04.000
So these three servers or going to
manage with the help of

00:01:04.000
00:01:10.900
this ansible engine right now to
manage your three servers

00:01:11.000
00:01:12.100
with the help of ansible.
00:01:12.100
00:01:15.000
You need to provide some information
about your remote servers

00:01:15.000
00:01:19.200
or your answers will notes on your
aunt's will Jen so providing

00:01:19.200
00:01:24.200
that information is called simply
configuration part or simply

00:01:24.200
00:01:28.700
you're configuring ansible such that
you are going to work

00:01:28.700
00:01:29.800
with your remote servers.

00:01:30.600
00:01:34.100
So guys whenever if you want to work
with answerable for

00:01:34.100
00:01:36.300
your environment, you have two steps.

00:01:36.900
00:01:42.000
The first step is installing ansible
second step is configuring

00:01:42.000
00:01:45.400
your ansible why we need to configure
means way to work with

00:01:45.400
00:01:46.300
remote servers.

00:01:46.600
00:01:48.200
We need to work with unstable nodes.

00:01:48.900
00:01:49.400
Right.

00:01:49.600
00:01:53.400
So if you want to work with your
ansible notes some information

00:01:53.400
00:01:56.800
about your unstable nodes you how to
provide on your ansible

00:01:56.800
00:02:00.300
engine so that you are answerable
can understand that.

00:02:00.800
00:02:02.900
Oh, we need to work with zones or
servers.
00:02:03.100
00:02:06.000
So that is simply configuration part,
right?

00:02:06.100
00:02:10.000
So in this video we are going to see
only installation part

00:02:10.100
00:02:10.699
in next video.

00:02:10.699
00:02:15.100
We will see how to configure our
ansible right fine.

00:02:15.800
00:02:19.000
So guys now we are going to install all
ansible.

00:02:20.000
00:02:22.500
So if you want if you want to install
ansible, we need one

00:02:22.500
00:02:24.000
server, right?

00:02:24.000
00:02:26.800
We can take any one of the server to
install your ansible,

00:02:27.100
00:02:31.200
but we have to follow some rules or
we have some prerequisites

00:02:31.600
00:02:34.100
to install your ansible on your server.

00:02:35.200
00:02:38.100
So simply how to select a server such
that that server should

00:02:38.100
00:02:43.500
follows a follow any one of these OS I
mean or distribution.

00:02:43.800
00:02:47.100
I mean either Rachel or sent waves or
Debian or Ubuntu Linux.

00:02:48.100
00:02:55.200
with some python version Right and
windows is not supported

00:02:56.000
00:02:59.300
for control node means if you want
install ansible, you cannot
00:02:59.300
00:03:03.100
install on Windows, of course against
all with some setup.

00:03:03.200
00:03:06.300
We will see that but basically your
windows is not supported

00:03:06.300
00:03:09.800
for the control node right now friends.

00:03:09.800
00:03:12.500
We have different versions with your
ansible suppose if you

00:03:12.500
00:03:16.700
are going to work with ansible 2.4 on
later, then you need

00:03:16.700
00:03:18.400
python 2.6 or either version.

00:03:19.600
00:03:22.200
But if you want to go with latest
version of your answers

00:03:22.200
00:03:25.300
will suppose the latest version as of
now it is 2.8.

00:03:26.100
00:03:28.500
So anyway, we are going to work with
you on a date in this

00:03:28.500
00:03:31.800
course. So if you want to work with the
Torah date, you need

00:03:31.800
00:03:36.800
python version from Python 2.7 or
higher and from Python

00:03:36.800
00:03:39.500
3 3 8 5 or higher versions.

00:03:40.000
00:03:40.500
That's it.

00:03:41.100
00:03:45.800
So now to install your ansible right for
your ansible engine.

00:03:46.000
00:03:47.500
We have some prerequisites.

00:03:47.600
00:03:51.500
They are your OS should be any one
of these distribution
00:03:51.900
00:03:55.000
and you should have some python
version based on your ansible

00:03:55.000
00:03:59.100
version right suppose now we are
going to work with 2.8.

00:04:01.000
00:04:02.900
So if you want to work with you on a
date you should have

00:04:02.900
00:04:07.400
python version either 2.7 are higher or
3.5 or higher.

00:04:08.100
00:04:08.600
That's it.

00:04:09.300
00:04:12.100
And we need to select any one of the
OS so I am going to

00:04:12.100
00:04:14.900
select sent waves here and again
instant ways.

00:04:14.900
00:04:19.000
We have versions like six seven and
eight right like Orajel

00:04:19.000
00:04:20.500
six seven and eight.

00:04:21.200
00:04:24.399
So if you go with either Rachel or sent
waves proceed same

00:04:24.399
00:04:28.399
to install your ansible now, I am going
to work with sent

00:04:28.399
00:04:32.800
ways and I'm going to select the voice
7 That's fine.

00:04:33.100
00:04:36.000
Now if you have a operating system
now, you can install your

00:04:36.000
00:04:39.800
ansible on your operating systems in
three ways.

00:04:40.500
00:04:42.400
You have three ways to install your
ansible.
00:04:43.200
00:04:45.100
So they are using em command.

00:04:45.400
00:04:47.800
So if it is all Rachel of sent ways, we
can go and install

00:04:47.800
00:04:51.300
using M command suppose if it is
open to you can go with

00:04:51.300
00:04:52.900
the apt-get command.

00:04:53.600
00:04:58.000
That is one way second way is using
pipe command basically

00:04:58.000
00:05:00.000
ansible is one python package.

00:05:00.600
00:05:02.900
So that's how you can also install your
ansible using pipe

00:05:02.900
00:05:07.400
command soap is the command to
manage a python packages.

00:05:09.200
00:05:13.200
And we have one more way that is
using compiled file Place

00:05:13.200
00:05:15.300
among these three procedures, right?

00:05:15.300
00:05:18.600
If you are in Shell stage my size nails,
please go with this

00:05:18.800
00:05:22.600
because if you go with either pipe or
here you need to do

00:05:22.600
00:05:23.700
some extra setups.

00:05:25.000
00:05:27.300
But if you go with the m command by
default, you will get

00:05:27.300
00:05:28.600
you will get some files.

00:05:30.100
00:05:34.000
Right, so initially we will go with the m
command procedure.
00:05:35.300
00:05:35.800
Right.

00:05:35.800
00:05:38.300
So while going forward based on
requirement, I will show

00:05:38.300
00:05:41.300
you how to go and work with your
peep and compiled file.

00:05:42.600
00:05:45.800
So the best procedure is as of now
using GM command.

00:05:47.600
00:05:51.600
Fine now we are going to install our
ansible on sent way

00:05:51.600
00:05:54.200
7 using em command same steps.

00:05:54.200
00:05:58.300
You can follow for your scent wave six
right or eight or

00:05:58.300
00:06:00.300
else even maybe for your rhl as well.

00:06:01.800
00:06:02.400
Right.

00:06:02.400
00:06:06.700
Anyway, please try to go with your
scent way 7 or or hl7

00:06:06.700
00:06:07.300
as of now.

00:06:08.100
00:06:10.200
So anyway while going forward I will
also show you how to

00:06:10.200
00:06:13.500
go and work with your or hl8 or send
waves 8.

00:06:14.700
00:06:17.200
So for time being we are going to work
with scent weighs

00:06:17.200
00:06:19.400
7. Right.

00:06:19.400
00:06:23.300
So guys suppose if you want to install
ansible on your any
00:06:23.300
00:06:25.800
one of the operating system, you need
only to go and search

00:06:25.800
00:06:30.600
in any or websites directly can open
your official document

00:06:30.800
00:06:32.100
or the official website.

00:06:32.200
00:06:34.100
That is dogs dot ansible.com.

00:06:34.600
00:06:35.800
Let me open that.

00:06:38.200
00:06:41.700
And simple sorry Doc's dot
ansible.com.

00:06:42.300
00:06:42.500
Now.

00:06:42.500
00:06:45.400
If you open this website you have
information about your

00:06:45.400
00:06:48.800
ansible lands built our Network
galaxies everything you have.

00:06:49.700
00:06:52.500
So as of now what we need
installation part, let me select

00:06:52.500
00:06:55.100
this we have so many things you can
go and search you can

00:06:55.100
00:06:57.100
go and see remaining information
such as well.

00:06:57.300
00:07:00.200
But anyway, we'll go with step-by-step
about all these things.

00:07:00.800
00:07:03.600
So as of now, I am going to work with
installation part.

00:07:03.700
00:07:04.700
Let me show you that.

00:07:06.200
00:07:09.900
Installation guide so observe that this
is the latest version.
00:07:09.900
00:07:11.500
You can also select your version here.

00:07:12.100
00:07:12.900
So 2.8.

00:07:12.900
00:07:15.500
Is there installation guide right?

00:07:15.500
00:07:16.300
Just calm down.

00:07:19.100
00:07:21.500
Control node or your ansible engine.

00:07:22.000
00:07:24.600
So these are the requirements for your
2.8.

00:07:25.400
00:07:29.200
And these are the distributions you
have to take to install

00:07:29.200
00:07:30.800
your ansible engine.

00:07:31.800
00:07:33.200
Right then come down.

00:07:33.700
00:07:35.300
So as of now don't go and work.

00:07:35.400
00:07:37.800
I mean this manage node
requirement.

00:07:37.800
00:07:40.700
We will see these things in your
configuration part of your

00:07:40.700
00:07:45.700
ansible right now installing the control
node or your ansible

00:07:45.700
00:07:49.000
engine right based on your way as you
can go with any one

00:07:49.000
00:07:49.800
of the procedure.

00:07:50.900
00:08:02.600
so as of now, let me show you so this
is my Sent West 7.

00:08:03.300
00:08:04.000
So guys here.

00:08:04.000
00:08:05.900
I am using voice from my VMware.
00:08:06.700
00:08:11.000
So if you want to go on the use from
cloud, yes, you can

00:08:11.000
00:08:13.900
use it from any one of the cloud you
can launch your required

00:08:13.900
00:08:18.000
server, maybe send waves or rhel
right or Ubuntu or Federer

00:08:18.000
00:08:18.800
whatever it may be.

00:08:19.300
00:08:22.100
So I am taking one of the server that is
sent with seven.

00:08:22.100
00:08:24.900
That's it and that to I am creating from
my VMware.

00:08:25.200
00:08:28.400
If you want to create from cloud you
can take it anywhere

00:08:28.400
00:08:29.600
for number of servers.

00:08:29.600
00:08:31.300
I mean for clients clients.

00:08:31.600
00:08:35.299
I will take from cloud but for control no
door for ansible

00:08:35.299
00:08:38.100
engine. I am installing from my
VMware itself.

00:08:39.299
00:08:41.700
Right fine now.

00:08:43.500
00:08:44.799
Let me maximize this.

00:08:46.600
00:08:47.100
Right.

00:08:47.100
00:08:48.799
So now this is my send waves.

00:08:48.799
00:08:50.100
Let me open my terminal.

00:08:51.700
00:08:59.300
just see that Send OS 7.6 dot some
version right?
00:08:59.600
00:09:01.600
So finally we have sent to a seven.

00:09:01.700
00:09:03.500
That's it fine.

00:09:03.800
00:09:04.700
Now friends.

00:09:04.800
00:09:08.100
We are going to install ansible with the
help of em command.

00:09:08.100
00:09:11.400
So that's why we should be the root or
you have a root privileges

00:09:11.400
00:09:13.000
with current user right.

00:09:13.100
00:09:14.900
Anyway, I am going to enter into root.

00:09:20.800
00:09:23.900
Fine now if you want to install ansible,
right?

00:09:24.100
00:09:26.200
First of all, you should have some
python version.

00:09:26.200
00:09:32.700
Let me search for Python 2.7 dot Phi
is there now I am directly

00:09:32.700
00:09:36.900
trying to install my ansible using M
command in this way

00:09:37.800
00:09:40.800
just observe that it is trying to install 2
Dot 4 dot some

00:09:40.800
00:09:44.600
version of your ansible, but I want to
work with eight 2.8.

00:09:45.100
00:09:49.400
So that's why what you have to do is
we need to add one extra.

00:09:50.300
00:09:52.700
Repo for your OS now.

00:09:52.700
00:09:55.100
If You observe here in this page itself,
we have somewhere
00:09:55.200
00:09:58.500
EPL. Right, just click on that EPL.

00:09:59.000
00:10:00.700
Now you are redirecting into this page.

00:10:00.700
00:10:03.600
There is nothing but simply extra
packages for your Enterprise

00:10:03.600
00:10:09.600
Linux now based on your ways or hl7
or six or eight, right?

00:10:09.700
00:10:12.000
So as of now we are using rhel7.

00:10:12.000
00:10:15.900
That's why just simply copy this link
and directly exclude

00:10:15.900
00:10:17.000
this on your ways.

00:10:18.400
00:10:21.800
Now you are going to add one
package for your operating system.

00:10:23.200
00:10:26.500
So after adding your package now try
to install your ansible.

00:10:28.900
00:10:34.100
Now it is going to install 2.8 see that
that's it.

00:10:35.200
00:10:37.900
Now we are going to install latest
version of your ansible

00:10:38.000
00:10:39.000
on your host.

00:10:41.600
00:10:43.700
Right, so it is going to take some time.

00:10:44.900
00:10:46.800
So you have to wait once it is done.

00:10:47.000
00:10:49.900
Then I will show you that so your
answer will installation

00:10:49.900
00:10:54.300
location. And what is the ansible
version you installed everything,

00:10:54.600
00:10:56.400
right? It is almost done.
00:10:56.800
00:10:57.400
Yeah fine.

00:10:57.400
00:10:59.000
It's over right now.

00:10:59.000
00:11:01.900
Just after after installing your ansible
with the help of

00:11:01.900
00:11:05.500
em come and just run ansible space -
hyphen version.

00:11:07.100
00:11:10.900
See that you have ansible to dot a
DOT to version and it

00:11:10.900
00:11:13.600
is going to show you some
configuration file details some

00:11:13.600
00:11:17.600
module such path write some python
modules location then

00:11:17.600
00:11:20.300
executable location nothing but where
your answer below has

00:11:20.300
00:11:21.100
been installed.

00:11:21.700
00:11:23.900
And what is the python version is
going to use anywhere?

00:11:23.900
00:11:27.200
We have to dot 7.5 on host that either
wasn't is going to

00:11:27.200
00:11:29.300
use right.

00:11:30.100
00:11:33.000
So I suppose if you go on install
ansible with pimp you're

00:11:33.000
00:11:36.400
not going to get this details this
highlighted details.

00:11:36.400
00:11:39.300
You are not going to get if you go and
install your ansible

00:11:39.300
00:11:39.800
with people.
00:11:41.700
00:11:43.700
So we are at initial stage, right?

00:11:43.900
00:11:46.700
We need to see what are the required
files by default.

00:11:46.700
00:11:48.900
That's why I'm going to work with em
command.

00:11:49.700
00:11:53.400
Anyway, once you've installed your
ansible just navigate

00:11:53.400
00:11:56.600
into this directory rotate EC by default
under root.

00:11:56.600
00:11:59.200
It is C or ansible director will be
created.

00:11:59.700
00:12:04.000
Just see here what you have you have
three things one is

00:12:04.000
00:12:06.700
roles directory and two files hosts.

00:12:06.700
00:12:08.700
And one more is ansible dot C of G.

00:12:09.200
00:12:10.200
So, these are the important.

00:12:10.300
00:12:14.500
important files for your ansible So you
need to do some configuration

00:12:14.500
00:12:17.900
with this file so that you can work with
your managed nodes

00:12:17.900
00:12:21.100
or client nodes or your remote nodes,
right?

00:12:21.100
00:12:22.900
So that is about configuration part.

00:12:22.900
00:12:24.900
We will see that in our next video.

00:12:25.700
00:12:30.000
So as this is the way how to install
your ansible on your
00:12:30.000
00:12:33.300
scent wave 7 or or hl7, right?

00:12:33.400
00:12:37.400
So I am going to provide the
commands whatever we use to

00:12:37.400
00:12:40.400
install your ansible on the below of this
video in the description

00:12:40.400
00:12:42.200
part. You can go through them and
you can install it.

00:12:42.400
00:12:46.500
Easily this sent to a ansible on your
scent o S7 or rhel

00:12:46.500
00:12:48.900
7. Right.

00:12:49.900
00:12:50.400
Okay.

00:12:50.700
00:12:51.200
Okay guys.

00:12:51.200
00:12:52.600
Thank you for watching this video.
Transcript
00:00:00.000
00:00:04.500
Hi friends, welcome back to Ansible
installation and configuration.

00:00:05.200
00:00:09.300
Friends already be done with Ansible
installation in our previous video.

00:00:09.300
00:00:09.500
Now.

00:00:09.500
00:00:11.800
We are going to work with
configuration.

00:00:11.800
00:00:13.900
Anyway, before going to work with
configuration.

00:00:13.900
00:00:15.300
Let me show you once again,

00:00:15.300
00:00:19.300
to our simple Ansible architecture,
right.

00:00:19.300
00:00:22.500
This is simple Ansible Architecture.
00:00:22.500
00:00:27.000
So, friends, we are assuming that in
our environment we have three servers,

00:00:27.000
00:00:30.500
but in real time you may have
hundreds or thousands of servers.

00:00:30.500
00:00:33.200
So, all those servers we are going to
manage with Ansible.

00:00:33.200
00:00:36.600
That's why we are going to install
somewhere Ansible.

00:00:36.600
00:00:41.900
You can also install on any one of your
Remote nodes or the

00:00:41.900
00:00:45.000
servers, which you are going to
manage with your Ansible,

00:00:45.000
00:00:46.300
but that is not a good practice.

00:00:46.300
00:00:49.700
That's why if you have three servers in
any one moment.

00:00:49.700
00:00:51.300
We are taking one extra server there

00:00:51.300
00:00:54.600
we are going to install Ansible, right.

00:00:54.600
00:00:57.500
Now, we are going to use this server,

00:00:57.500
00:01:01.400
this Ansible engine to work with your
remote nodes for our requirements,

00:01:01.400
00:01:05.900
like configuration, for deployments,
right, fine.

00:01:06.900
00:01:09.900
Now, once you have Ansible on this
server, this is called

00:01:09.900
00:01:12.200
simply Ansible engine or Ansible
controller
00:01:12.200
00:01:16.400
or controller node or simply master
node.

00:01:16.400
00:01:20.000
And the servers, which you are going
to manage by your Ansible.

00:01:20.000
00:01:26.000
Those servers are called simply
Managed nodes or Ansible nodes or clients

00:01:26.000
00:01:27.300
That's fine.

00:01:27.300
00:01:35.000
So, friends here remember that you
should use Unix-like systems or

00:01:35.000
00:01:40.300
server for your Ansible engine only a
Unix-like system right

00:01:40.300
00:01:45.800
can support to install your Ansible
engine, but Managed nodes

00:01:45.800
00:01:49.300
you can take any OS here any server
here.

00:01:49.300
00:01:55.200
It may be Windows server or Linux
server or Ubuntu Server,

00:01:55.200
00:01:59.700
right, or RHEL server, Sentway server
or combination of

00:01:59.700
00:02:04.400
all or maybe same, all are same
servers. No problem.

00:02:04.400
00:02:09.699
Right, you may have this server is
RHEL open type and this

00:02:09.699
00:02:12.800
is open to the recent OS, no problem
and one more server.

00:02:12.800
00:02:15.900
This is Windows. No problem.

00:02:15.900
00:02:18.200
Right. So, you are working nodes.
00:02:18.200
00:02:20.200
I mean to work with your nodes.

00:02:20.200
00:02:21.700
We are using Ansible right?

00:02:21.700
00:02:24.900
So, this here you should have, I mean
to install your Ansible

00:02:24.900
00:02:29.800
you should select any Unix-like
system ways or any Unix-like based server,

00:02:29.800
00:02:33.600
but your remote nodes may be any
server.

00:02:33.600
00:02:37.600
Right, but initially we are going to
select our Ansible nodes.

00:02:37.600
00:02:44.400
Ansible nodes are managed nodes
any like Unix-like base systems,

00:02:44.400
00:02:47.400
but while going forward, I will select
Windows as well.

00:02:47.400
00:02:52.400
All right fine. So guys here.

00:02:52.400
00:02:54.400
Now, just assume that we are going to
work three servers,

00:02:54.400
00:02:56.800
that's why we need four servers right.

00:02:56.800
00:03:03.200
Now, what I am doing is, I already
selected my Ansible engine server, as VMware.

00:03:03.200
00:03:04.800
We observed that in our previous
video,

00:03:04.800
00:03:08.900
I installed my Ansible engine on my
VMWare.

00:03:08.900
00:03:10.500
So, we have VMware server

00:03:10.500
00:03:12.800
there we install my Ansible engine.
00:03:12.800
00:03:16.800
Now, remaining three servers, you can
also create from VMware.

00:03:16.800
00:03:20.100
Right, or you can also create from any
one of the Cloud.

00:03:19.600
00:03:22.900
Now, for your Managed nodes, these
nodes.

00:03:22.900
00:03:25.700
I am going to select my AWS cloud
from there

00:03:25.700
00:03:29.500
I am going to launch my servers.

00:03:29.500
00:03:31.800
Yes, I assume that otherwise, let me
launch.

00:03:31.800
00:03:41.800
[No audio.]

00:03:41.800
00:03:44.700
Let me log in with my AWS cloud.

00:03:44.700
00:03:55.600
[No audio.]

00:03:55.000
00:03:58.200
Right. Let me go with launch Instance
or Running Instances.

00:04:00.200
00:04:02.800
Now let me select launch Instance.

00:04:02.800
00:04:05.200
So, guys for time being what I am
doing is first I'm going

00:04:05.200
00:04:09.600
to create two servers from Amazon
Linux.

00:04:09.600
00:04:12.800
So, if you have three here, we have
somewhere Python, right.

00:04:12.800
00:04:15.100
Just observe that we need three
servers.

00:04:15.100
00:04:19.800
I am going to create two servers with
Python and I will create
00:04:19.800
00:04:23.500
one more server without Python.

00:04:23.500
00:04:26.399
Now, let me select my security group,
guys if you are familiar

00:04:26.399
00:04:30.900
with AWS Cloud just launch your
servers, from here.

00:04:30.900
00:04:33.700
Otherwise, if you are familiar with any
other Cloud, just go

00:04:33.700
00:04:36.500
and launch your Instances from there
only.

00:04:36.500
00:04:40.000
[No audio.]

00:04:40.000
00:04:44.000
Right, we done with two Amazon
Linux servers,

00:04:44.000
00:04:46.100
let me select this as node 1.

00:04:46.100
00:04:48.400
[No audio]

00:04:48.400
00:04:50.200
And this as node 2.

00:04:50.200
00:04:53.200
[No audio.]

00:04:53.200
00:04:55.100
And let me launch one more server.

00:04:55.300
00:05:02.100
Now, I am going to select RHLE8 but
on this you don't have any Python version.

00:05:02.100
00:05:05.200
Right, but you can install, but I want to
show you the difference.

00:05:05.200
00:05:06.100
That's why I'm taking.

00:05:06.100
00:05:09.200
[No audio.]

00:05:09.200
00:05:13.200
Price initially while practicing you can
go with the all
00:05:13.200
00:05:15.800
servers as, maybe RHL.

00:05:15.800
00:05:19.100
Maybe Amazon, Linux maybe Ubuntu,
no problem, right?

00:05:19.100
00:05:24.300
It's bad to select URL, in case if you
are from AWS Cloud,

00:05:24.300
00:05:28.800
just select Amazon Linux for your
practice without getting any confusion.

00:05:28.800
00:05:31.500
[No audio]

00:05:31.500
00:05:36.900
Okay, fine. Now we launched the three
Managed nodes and let me give the

00:05:36.900
00:05:41.000
name for this as node 3.

00:05:41.000
00:05:45.000
Right, Fine. Now, in our hand we have
three Managed nodes and

00:05:45.000
00:05:54.200
one is from your VMware so here we
have Right our Ansible.

00:05:54.500
00:05:55.700
Now, this is Ansible engine.

00:05:55.700
00:05:58.900
So, Ansible engine is on my Local
Host with VMware.

00:05:58.900
00:06:03.900
Now we are having three Managed
nodes, right, fine.

00:06:03.900
00:06:07.500
Now guys, let me show you first, what
are the steps you

00:06:07.500
00:06:13.600
have to take to configure your Ansible.

00:06:13.600
00:06:18.900
So, first thing we need to launch or
select, your required an environment.

00:06:18.900
00:06:21.700
So, if you are going to do practice, just
launch your servers
00:06:21.700
00:06:24.200
if you are going to work with your
existing environment select

00:06:24.200
00:06:27.700
for which servers you are going to
manage with your Ansible just select them.

00:06:27.700
00:06:28.800
That's it.

00:06:28.800
00:06:31.000
So, once if we select, we know that
they are called simply

00:06:31.000
00:06:35.000
Managed nodes or Ansible nodes or
clients.

00:06:35.000
00:06:36.000
Then second thing.

00:06:36.000
00:06:38.400
[No audio.]

00:06:38.400
00:06:42.400
For your Managed nodes, you have
some requirements.

00:06:42.400
00:06:46.000
That is your Managed node should
have some Python

00:06:46.000
00:06:50.300
it maybe Python 2.6 or higher or
Python 3.5 or higher.

00:06:51.400
00:06:53.000
So, that's why I selected a different
servers

00:06:53.000
00:06:55.900
2 servers with Python 1 server is
without Python.

00:06:55.900
00:06:57.500
[No audio.]

00:06:57.500
00:06:59.300
Right fine.

00:06:59.300
00:07:04.800
So, guys generally people will say that
we can manage remote

00:07:04.800
00:07:08.800
nodes or Managed nodes with Ansible
such as that.
00:07:08.800
00:07:12.300
Your remote node should have
Python.

00:07:12.300
00:07:15.400
In case if you don't have Python, we
can't manage with Ansible.

00:07:15.400
00:07:17.300
No, that's not correct.

00:07:17.300
00:07:21.300
Even though if you don't have Python
on your Managed nodes

00:07:21.300
00:07:26.600
still we can work with your Managed
nodes using ROM modules.

00:07:26.600
00:07:29.200
So initially, I'm not going to touch with
this part, but

00:07:29.200
00:07:33.000
while going forward I will show you
how to work with your remote nodes

00:07:33.000
00:07:36.500
if you don't have Python, see
sometimes you may not have Python

00:07:36.500
00:07:42.400
on your remote nodes if we don't, how
we can work with your Ansible.

00:07:42.400
00:07:45.400
So, guys if you have Python on your
remote nodes, then it

00:07:45.400
00:07:47.100
is very easy to write Playbooks.

00:07:47.100
00:07:51.100
If you don't have still, we can write
Playbooks, but with

00:07:51.100
00:07:52.600
some complexity, that's it.

00:07:52.600
00:07:54.600
[No audio.]

00:07:54.600
00:07:58.200
Fine, next thing you know that Ansible
is going to work with
00:07:58.200
00:08:02.000
your remote nodes using ssh
connectivity.

00:08:02.000
00:08:06.500
So anyway, by default it is there with
your Unix-like systems

00:08:06.500
00:08:08.300
your ssh connectivity.

00:08:08.300
00:08:11.800
Now, the thing is your answer is going
to use that and it

00:08:11.800
00:08:14.100
is going to establish a connection with
your remote nodes

00:08:14.100
00:08:17.500
with the help of this ssh connectivity.
Right,

00:08:17.500
00:08:22.900
but to create this connectivity between
your Ansible engine and with your nodes.

00:08:22.900
00:08:24.400
We have two ways.

00:08:24.400
00:08:30.100
One is, we can provide the remote
user username password

00:08:30.100
00:08:33.100
and that is called password
authentication.

00:08:33.100
00:08:36.700
I mean for your Ansible engine, we will
tell this is the user

00:08:36.700
00:08:40.700
and this is the password to work with
your Ansible nodes.

00:08:41.100
00:08:45.000
That is one way second way is
possible less authentication.

00:08:45.000
00:08:47.900
So, you can create your password-
less authentication with

00:08:47.900
00:08:49.700
the help of SSH keys.
00:08:51.400
00:08:51.799
Right.

00:08:51.799
00:08:53.900
So, once it is done, everything is fine.

00:08:53.900
00:08:59.200
Then you have to provide the remote
node or Manage nodes

00:08:59.200
00:09:04.400
IP or FQDN in inventory file of your
Ansible server.

00:09:04.400
00:09:06.100
I mean where you have Ansible
engine, there,

00:09:06.100
00:09:11.400
we need to mention information about
your Managed nodes that

00:09:11.400
00:09:13.900
is like IP or FQDN.

00:09:13.900
00:09:16.500
So anyway, we are practicing so we
are going to select IP

00:09:16.500
00:09:20.300
in case if you are in real time, you can
select your FQDN as well.

00:09:19.500
00:09:22.700
[No audio.]

00:09:22.700
00:09:27.500
So, if you provide FQDN or IP in
inventory file and civilian can understand that.

00:09:27.500
00:09:29.500
Oh, I need to work with so and so
server.

00:09:29.500
00:09:31.100
That's it.

00:09:31.300
00:09:35.200
So, after doing this setup, simply we
can verify, I mean whether

00:09:35.200
00:09:37.900
Ansible is able to connect with your
remote nodes

00:09:37.900
00:09:41.700
or not by using simply this Ansible
command.
00:09:41.700
00:09:44.400
So, here ping is the module for
Ansible and simply this is

00:09:44.400
00:09:46.600
Ansible command.

00:09:46.600
00:09:53.100
So, these are all steps to configure,
but here as of now

00:09:53.100
00:09:56.700
we are going to use password-less
authentication to work

00:09:56.700
00:10:00.600
with your Ansible nodes from your
Ansible engine.

00:10:00.600
00:10:03.100
So, this procedure we will see later.

00:10:03.100
00:10:05.400
So initially just to get some simplicity.

00:10:05.400
00:10:08.400
I am going to work with password-less
authentication.

00:10:08.400
00:10:10.800
So anyway, in real time also, most of
the cases we are going

00:10:10.800
00:10:13.000
to work with password-less
authentication.

00:10:13.000
00:10:15.100
So, in case if you don't have
passedword-less authentication

00:10:15.100
00:10:20.900
between your Ansible engine and
nodes so you can use password authentication. Right

00:10:20.900
00:10:25.600
So, 90% of the organization's they are
going to use this one

00:10:25.700
00:10:27.500
SSH Keys, using SSH keys,

00:10:27.500
00:10:30.000
they are going to provide password-
less authentication between

00:10:30.000
00:10:32.200
your Ansible engine and nodes.
00:10:33.200
00:10:35.300
Right fine.

00:10:35.300
00:10:40.700
Now, let me show you how you can
create password-less authentication.

00:10:40.700
00:10:42.919
Right, for your Ansible

00:10:42.900
00:10:48.900
make sure that for your Ansible how
we can create your password-less authentication.

00:10:48.900
00:10:52.000
So why I'm saying for your Ansible
means, because we are going

00:10:52.000
00:10:54.300
to take one extra step, that step is.

00:10:54.300
00:10:56.300
[No audio.]

00:10:56.300
00:11:02.700
See, this is your Ansible engine and
your Managed nodes.

00:11:02.700
00:11:03.500
Right.

00:11:03.500
00:11:07.500
So, from here you are going to
manage the servers.

00:11:07.500
00:11:10.100
So, this is supposing Linux box.

00:11:10.100
00:11:13.700
So, you know in Linux each and every
thing is I mean if you

00:11:13.700
00:11:17.700
are going to run some service, it is
going to run based on some user.

00:11:17.700
00:11:22.400
Right now, I need to work with my all-
remote nodes with some user.

00:11:22.400
00:11:25.300
I can take a Root user.

00:11:25.300
00:11:28.000
I mean I can work from Root with your
remote nodes
00:11:28.000
00:11:33.000
or any other XYZ or, just to avoid
confusion.

00:11:33.000
00:11:39.000
I am taking simply ansadmin user on
all servers.

00:11:39.000
00:11:42.400
So even this is the practice in real time
as well.

00:11:42.400
00:11:45.400
So sometimes you may use simply
Root.

00:11:45.500
00:11:51.100
I mean you can run your Ansible from
Root otherwise in some organizations.

00:11:51.100
00:11:53.800
They are going to create one extra
user on all the servers

00:11:53.800
00:11:58.400
that is called simply some ansadmin or
maybe any user.

00:11:58.400
00:12:00.800
So, with that user they are going to
operate this Ansible

00:12:00.800
00:12:02.200
with all the remote nodes.

00:12:03.200
00:12:07.900
But remember that sometimes you will
also work with Root.

00:12:07.900
00:12:09.700
I will show you that don't get confused.

00:12:10.200
00:12:12.800
So as of now just assume that we are
going to create

00:12:12.800
00:12:18.000
ansadmin user across all servers and
we are going to provide some password, right.

00:12:18.000
00:12:22.100
First, let me start with my Ansible
engine server.

00:12:22.100
00:12:23.600
So, this is my Ansible engine.
00:12:23.600
00:12:28.200
[No audio.]

00:12:28.200
00:12:30.300
So, guys just to avoid confusion.

00:12:30.300
00:12:37.300
We are going to take one new user,
that user simply am taking ansadmin.

00:12:37.300
00:12:39.900
So, if you want to create any new
user, you should enter into

00:12:39.900
00:12:41.700
Root or a should have a Root
privilege.

00:12:41.700
00:12:43.500
So simply I am entering into Root.

00:12:43.500
00:12:52.300
[Typing.]

00:12:52.300
00:12:54.300
Fine. Right now,

00:12:54.300
00:12:59.000
I am going to create ansadmin.

00:12:59.000
00:12:59.800
Right, then.

00:12:59.800
00:13:05.600
Let me provide password here ans
Okay, ansadmin.

00:13:05.600
00:13:11.800
So, I'm going to provide password as
ANS Alt right 1, 2, 3.

00:13:11.800
00:13:12.900
ANS

00:13:12.900
00:13:19.800
[No audio.]

00:13:19.800
00:13:23.400
I will do one thing.

00:13:23.400
00:13:30.700
And admin Alt right one, two, three
and admin Alt right one two, three.

00:13:30.700
00:13:32.400
Fine.

00:13:32.400
00:13:38.000
So, I created one user and ans engine
server, right?
00:13:38.000
00:13:41.800
And now we need to provide same
user across all the servers.

00:13:41.800
00:13:45.500
Now, let me go and connect with one
by one my Managed nodes.

00:13:45.500
00:13:49.600
So first let me select first Manage
node this one.

00:13:49.600
00:13:54.900
[No audio.]

00:13:54.900
00:13:59.300
So, I'm going to take Get Bash
terminal to connect with the server.

00:13:59.300
00:14:03.000
So, whatever the way you know, you
just go on use

00:14:03.000
00:14:05.000
that way to connect with your remote
nodes.

00:14:05.000
00:14:08.900
I mean Managed nodes right fine.

00:14:08.900
00:14:10.700
So, you guys just for your clarity.

00:14:10.700
00:14:12.700
I want to show you.

00:14:12.700
00:14:15.600
We have Python here that 22.7 .1 6.

00:14:15.600
00:14:17.100
So higher than 2.6.

00:14:17.100
00:14:22.800
So, this is the first Manage node, and
we satisfied with Python condition, right, fine.

00:14:22.800
00:14:24.200
Now, let me enter into Root.

00:14:24.200
00:14:27.900
[No audio.]

00:14:27.900
00:14:36.500
Now, let me create user called
ansadmin and I want to provide password for this.

00:14:36.500
00:14:40.600
So, I am providing password for this
ansadmin, password
00:14:40.600
00:14:41.700
1, 2, 3.

00:14:41.700
00:14:46.100
[Typing.]

00:14:46.100
00:14:47.800
That's it.

00:14:47.800
00:14:51.500
Now, let me connect with second
Managed node.

00:14:50.800
00:14:56.600
[No audio.]

00:14:56.600
00:14:57.600
So, I am again.

00:14:57.600
00:14:59.200
I am going to create a launch.

00:15:01.800
00:15:03.800
Get Bash, new Get Bash Terminal.

00:15:03.800
00:15:07.400
[No audio.]

00:15:07.400
00:15:10.500
Right, let me decrease size so that I
can easily remember

00:15:10.500
00:15:13.900
which is Node 1 and which is Node 2.

00:15:13.900
00:15:15.100
That's fine.

00:15:15.100
00:15:16.100
Now observer here.

00:15:16.100
00:15:17.600
Here Also, we have Python.

00:15:17.600
00:15:19.800
[Typing.]

00:15:19.800
00:15:22.700
So anyway, that is also higher than 2.6
then we satisfied

00:15:22.700
00:15:25.000
with second Manage node as well.

00:15:25.000
00:15:30.900
Now, let me enter into Root and I am
going to create here also.

00:15:30.900
00:15:36.300
ansadmin user let me provide
password as ansadmin
00:15:36.300
00:15:41.000
sorry password for this ansadmin 1 2
3

00:15:39.300
00:15:46.500
[No audio.]

00:15:46.500
00:15:47.200
What happened?

00:15:47.200
00:15:54.800
[No audio.]

00:15:54.800
00:16:01.400
Okay, no problem, ansadmin Alt right
1 2 3.

00:16:01.400
00:16:03.208
Ans

00:16:03.208
00:16:08.010
[Typing.]

00:16:08.000
00:16:08.800
Okay, fine.

00:16:08.800
00:16:10.000
[No audio.]

00:16:10.000
00:16:13.800
Now, let me connect with our
Managed node.

00:16:13.800
00:16:14.500
Where it is?

00:16:14.500
00:16:14.800
Yeah.

00:16:14.800
00:16:27.400
[No audio.]

00:16:27.400
00:16:39.100
So here Okay, fine.

00:16:39.100
00:16:44.300
Now observe that Python, space,
version you don't have any Python, here

00:16:44.300
00:16:44.900
RIight?

00:16:44.900
00:16:52.200
Maybe Python 2, no, Python 3, no
Python 3, so it means simply

00:16:52.200
00:16:54.200
don't have any Python as of now on
this server,
00:16:54.200
00:16:59.500
but no problem, I will show you the
error and then I will try to install

00:16:59.500
00:17:00.600
here Python.

00:17:00.600
00:17:04.900
And then finally, we'll see how we can
work with Python without

00:17:04.900
00:17:08.500
Python, well see without Python after
some time.

00:17:09.000
00:17:10.900
Okay, fine.

00:17:10.900
00:17:15.900
First of all, let me enter into Root and
let me add user

00:17:15.900
00:17:20.500
add ansadmin then let me provide
password for this.

00:17:18.900
00:17:32.599
[Typing.]

00:17:32.599
00:17:37.200
Fine now, we created same user
across all servers including

00:17:37.200
00:17:41.200
your Ansible engine then we created a
password as well.

00:17:41.200
00:17:46.099
The next step is you need to provide
Root privileges to all your users.

00:17:46.099
00:17:50.099
Whatever the user name you created
on all servers. Right.

00:17:50.099
00:17:52.979
Now, let me open first my.

00:17:52.900
00:18:06.300
[No audio.]

00:18:06.300
00:18:07.600
So, we have three right.

00:18:07.600
00:18:12.800
Now, First of all, your username is
ansadmin we created this.
00:18:12.800
00:18:19.100
So, under pseudo file right just go to
down and there, right.

00:18:19.100
00:18:24.300
See you need to provide in this way
ans-admin.

00:18:24.300
00:18:27.500
So, if you are the Linux Admin, you
can understand the meaning for this,

00:18:27.500
00:18:30.800
otherwise simply just remember this,
you need to provide

00:18:31.400
00:18:35.000
your username then, All it goes to All,
then no password for All.

00:18:35.000
00:18:41.700
Right, so let me copy this line and I
will use same line across all

00:18:41.700
00:18:46.800
So all and all now, let me open second
Manager node.

00:18:46.800
00:18:48.400
Just simply go to last.

00:18:48.400
00:18:51.400
[No audio.]

00:18:51.400
00:18:53.500
Right copy and paste it.

00:18:53.500
00:18:55.000
You already you copied the line.

00:18:55.000
00:18:59.900
[No audio.]

00:18:59.900
00:19:06.100
Now come to first node, then go to last
and simply.

00:19:02.900
00:19:09.600
[No audio.]

00:19:09.600
00:19:11.700
That's it, right?

00:19:11.700
00:19:15.200
[Typing.]

00:19:15.200
00:19:19.100
We are done with second, but let me
verify that last line.
00:19:18.200
00:19:21.300
[No audio.]

00:19:21.300
00:19:31.000
Yeah, fine. Now, same way you need
to do it in your Ansible engine as well.

00:19:31.000
00:19:32.400
Anyway, it's not required.

00:19:32.400
00:19:35.200
Yeah, we need to work mainly it is
required here itself.

00:19:35.200
00:19:38.800
[No audio.]

00:19:38.800
00:19:40.700
VI sudo just go to down.

00:19:40.700
00:19:45.700
[Typing.]

00:19:45.700
00:19:51.200
Ctrl N you will go to last, then add that.

00:19:51.200
00:19:52.300
That's it.

00:19:52.300
00:19:54.600
Right, fine.

00:19:54.600
00:19:57.700
Now, we're done with our second step
as well.

00:19:57.700
00:19:59.500
Then third step.

00:19:59.500
00:20:03.200
Make sure that password
authentication, as yes in all servers

00:20:03.200
00:20:08.000
under Root etc ssh sshd config file.

00:20:08.000
00:20:11.800
See by default, is no in case if it is, no,
you just make it as yes.

00:20:11.800
00:20:16.000
So, that we can connect with your
remote notes using password.

00:20:16.000
00:20:20.800
So why we are using this as a yes
means, see we need to exchange our keys.
00:20:20.800
00:20:23.200
So, at that time first, we will try to
connect with your remote

00:20:23.200
00:20:28.300
nodes, using username and
password, so for that.

00:20:28.300
00:20:29.600
Let me open here.

00:20:29.600
00:20:33.900
[Typing.]

00:20:33.900
00:20:39.400
In this file, right just go down on
somewhere search password authentication.

00:20:39.400
00:20:46.800
Yeah, here I have password
authentication as yes, then no problem.

00:20:46.800
00:20:47.100
Right

00:20:47.100
00:20:49.200
[No audio.]

00:20:49.200
00:20:51.100
See that let me highlight that.

00:20:51.100
00:20:55.400
[No audio.]

00:20:55.400
00:20:59.900
Now, let me open my Node 1 and let
me.

00:20:58.400
00:21:02.700
[No audio.]

00:21:02.700
00:21:04.600
Search there.

00:21:04.600
00:21:10.700
so, VI Root etc ssh sshd config file,
right.

00:21:07.600
00:21:17.800
[Typing.]

00:21:17.800
00:21:20.400
Let me search simply password
authentication.

00:21:20.400
00:21:22.100
[No audio.]
00:21:22.100
00:21:25.900
Right, see that here password
authentication is no, in this server, right.

00:21:25.900
00:21:30.300
Now, let me make it as yes.

00:21:28.900
00:21:32.900
[No audio.]

00:21:32.900
00:21:33.500
That's it.

00:21:33.500
00:21:38.900
[No audio.]

00:21:38.900
00:21:42.900
Right. Now, let me connect with
second server and there also,

00:21:42.900
00:21:46.700
one more thing is once if you done
with configuration

00:21:46.700
00:21:53.800
with your SSHD, then you need to
restart your SSHD service.

00:21:53.800
00:22:09.100
systemctl restart sshd Okay, maybe
here sshd system schedule

00:22:09.100
00:22:13.000
is not there then let me use.

00:22:13.000
00:22:15.000
Service, sshd.

00:22:15.000
00:22:17.300
[Typing.]

00:22:17.300
00:22:19.900
Restart, that's fine.

00:22:19.900
00:22:23.500
So, if you don't have maybe this is cat
etc.

00:22:23.500
00:22:25.100
Let me just

00:22:25.100
00:22:32.500
[Background noises.]

00:22:32.500
00:22:35.400
Okay, so this is Amazon Linux, right?

00:22:35.400
00:22:43.500
[Typing.]
00:22:43.500
00:22:44.600
Okay fine.

00:22:44.600
00:22:49.200
So, if you don't have systemctl just
use service command.

00:22:49.200
00:22:58.000
Now, vi with etc ssh sshd config file.

00:22:52.200
00:23:00.800
[Background noise]

00:23:00.800
00:23:02.900
Search here password authentication
here.

00:23:02.900
00:23:03.700
Also, it is no.

00:23:03.700
00:23:06.800
Now, what I am doing is just I'm
making it as yes.

00:23:06.800
00:23:11.500
So, this line I make it as yes, that's
fine.

00:23:11.500
00:23:18.300
So, after that simply use service sshd
restart.

00:23:18.300
00:23:20.800
Done now, let me go with your last
server.

00:23:20.800
00:23:22.500
[No audio]

00:23:22.500
00:23:26.800
So, vi root etc sh sshd config.

00:23:27.500
00:23:31.700
So, he also search with home and
password authentication.

00:23:30.500
00:23:34.800
[Typing]

00:23:34.800
00:23:38.200
See here password authentication is
no.

00:23:38.200
00:23:39.600
Right.

00:23:39.600
00:23:42.300
So, if this is our initial server
somewhere you have password
00:23:42.300
00:23:44.400
authentication of yes, but that is
commanded.

00:23:44.400
00:23:47.900
Now, what you will do is just remove
this command here and add this command.

00:23:47.900
00:23:50.900
Otherwise, you can modify here itself.

00:23:52.200
00:23:53.900
That's it.

00:23:53.900
00:23:56.400
Now here we have systemctl in our
hl8.

00:23:56.400
00:23:58.500
[No audio]

00:23:58.500
00:24:00.800
Then you can use restart sshd.

00:24:00.800
00:24:02.700
[No audio]

00:24:02.700
00:24:05.700
That's it. Right.

00:24:05.700
00:24:10.600
Now we done with our third step as
well. Right.

00:24:10.600
00:24:16.400
Next thing is generate ssh-keys using
ssh-keygen command.

00:24:16.400
00:24:20.200
So where generate this keys, there in
our Ansible engine, there,

00:24:22.400
00:24:29.900
Right. Now, let me, so for which user,
guys that is also an important point

00:24:29.900
00:24:32.200
from ansadmin user you need to
generate these keys,

00:24:32.200
00:24:36.600
because we are going to work with the
ansadmin user not from root user, right.

00:24:36.600
00:24:37.900
So, that's why first

00:24:37.900
00:24:48.500
[Typing]
00:24:48.500
00:24:48.800
Sorry.

00:24:48.800
00:24:55.500
[Typing]

00:24:55.000
00:24:55.400
Right.

00:24:55.400
00:25:02.900
Now we are under ansadmin so here
just move into in cache if we have .ssh.

00:25:02.900
00:25:03.700
Okay, no problem.

00:25:03.700
00:25:11.000
Let me run keygen command just
provide Enter, Enter, Enter, right.

00:25:11.000
00:25:15.800
Now, observe that. So, previously you
don't have . ssh

00:25:15.800
00:25:18.100
now. It has been created at our search
right

00:25:18.100
00:25:20.100
Now, let me enter into .ssh.

00:25:20.100
00:25:22.000
[No audio]

00:25:22.000
00:25:25.700
Now see the files we have ID RSA
and id rsa .pub.

00:25:25.700
00:25:26.500
This is public key.

00:25:26.500
00:25:28.100
And this is private key.

00:25:28.100
00:25:30.600
Now, you need to exchange this key
with your remote nodes

00:25:30.600
00:25:34.800
or Managed nodes so that your
Ansible will connect

00:25:34.800
00:25:38.300
with your remote nodes without having
any password, right.

00:25:38.300
00:25:44.500
Now, we generated our key on your
Ans Ansible engine server.
00:25:44.500
00:25:46.300
Now, we need to exchange our keys.

00:25:46.300
00:25:47.800
Now to exchange your keys

00:25:47.800
00:25:55.600
you need to run command as SSH -
copy - id then your hostname, right.

00:25:55.600
00:25:55.900
Okay.

00:25:55.900
00:25:59.300
Now let me first of all.

00:25:59.300
00:26:02.300
Open my AWS account.

00:26:02.300
00:26:06.600
So this is Node 1 right, Node 1.

00:26:06.600
00:26:09.700
So, for Node 1, observe that this is the
public IP.

00:26:09.600
00:26:13.000
[No audio]

00:26:13.000
00:26:13.900
Right.

00:26:13.900
00:26:18.100
Now our server is from set.

00:26:18.100
00:26:21.400
I mean Ansible server, Ansible union
is there on set ways,

00:26:21.400
00:26:23.400
but these servers are from Cloud.

00:26:23.400
00:26:31.400
So, there is the public IP you have
now, let me go to there ssh copy ID.

00:26:26.400
00:26:37.900
[Typing]

00:26:37.900
00:26:40.000
Right

00:26:40.000
00:26:40.730
Fine

00:26:40.700
00:26:43.600
Now, you have to provide password
for this.
00:26:43.600
00:26:50.206
So already we know we have created
password as ansadmin 1 2 3

00:26:50.200
00:26:54.500
[No audio]

00:26:54.500
00:26:55.400
Right.

00:26:55.400
00:26:59.500
Now we exchanged our key with your
remote node called.

00:26:59.700
00:27:01.500
What is that remote node on Managed
node?

00:27:01.500
00:27:03.800
[No audio]

00:27:03.800
00:27:06.972
This Server, right, fine.

00:27:06.972
00:27:09.200
Now just after that we have to copy

00:27:09.200
00:27:11.200
the same way for remaining servers as
well.

00:27:11.200
00:27:13.700
Now what I am doing is simply, I'm
running ssh.

00:27:13.700
00:27:18.400
[No audio]

00:27:18.400
00:27:23.400
See that you login with your Amazon
Linux server without

00:27:23.400
00:27:29.900
providing password now we created
password-less authentication for this server

00:27:29.900
00:27:30.800
That's it.

00:27:30.800
00:27:35.100
We created password-less
authentication from your Ansible engine to this Server.

00:27:35.100
00:27:40.000
First node the same way, right just
come back to your local server.
00:27:40.000
00:27:52.200
Now, we are on local server, right, now
ssh- copy id now provide your second node, public IP.

00:27:52.200
00:27:57.300
Then see if you are Ansible engine is
also from your AWS account.

00:27:57.300
00:28:00.500
Then you can also provide private ID,
but Ansible engine,

00:28:00.500
00:28:03.500
is there outside of your Cloud, right?

00:28:03.500
00:28:07.500
That is not from your Cloud that is
from my VMware.

00:28:07.500
00:28:09.800
So that's why you need to provide
public IP.

00:28:09.800
00:28:12.500
So, I have taken this, because while
going forward, I mean

00:28:12.500
00:28:15.900
I have taken in this way my
architecture, because while going

00:28:15.900
00:28:20.000
forward you can easily understand
why we need Dynamic inventory file.

00:28:20.000
00:28:24.100
So, for that purpose suppose, I am
taking in this way,

00:28:24.100
00:28:28.500
but whatever it may be finally you
need to provide some your server IP s

00:28:28.500
00:28:34.100
to exchange your keys now, let me do
this for second server as well.

00:28:34.100
00:28:38.300
So, in this, guys by default, if you do in
this way, the public

00:28:38.300
00:28:40.400
key will be copied to your remote
node.

00:28:40.400
00:28:41.300
That's it.
00:28:41.300
00:28:42.600
I mean you are Managed node.

00:28:42.600
00:28:45.800
[No audio]

00:28:45.800
00:28:53.500
Now, let me provide password for this.
Done.

00:28:53.500
00:28:58.600
Now, let me go with your third node as
well

00:28:58.600
00:29:06.800
and let me copy your IPs, guys. This is
your first node IP, right?

00:29:01.600
00:29:09.200
[No audio]

00:29:09.200
00:29:11.900
Okay now and we will get it right here,
from here.

00:29:11.900
00:29:13.700
Now, let me go with third.

00:29:13.700
00:29:15.600
[No audio]

00:29:15.600
00:29:17.400
Sorry.

00:29:17.400
00:29:20.300
I need to take third server IP.

00:29:20.300
00:29:21.300
Yes. I got it.

00:29:21.300
00:29:24.000
[Typing]

00:29:24.000
00:29:28.000
Again, simply ssh copy - ID third
server.

00:29:28.000
00:29:33.100
I mean third Managed node.

00:29:33.100
00:29:43.700
Now, let me provide your password for
this. done.

00:29:43.700
00:29:48.700
Now see that, SSH your remote IP
your Managed IP.
00:29:48.700
00:29:51.800
So, directly or you are able to log into
with that server.

00:29:51.700
00:29:53.500
[No audio]

00:29:53.500
00:29:53.800
Right.

00:29:53.800
00:29:55.600
So, guys this is private IP for that.

00:29:55.600
00:29:58.100
You are giving public IP you're able to
enter into that server.

00:29:58.100
00:30:01.000
Now, this is giving private IP of that
server

00:30:01.000
00:30:03.200
if you want to show you, I can show
you.

00:30:03.200
00:30:08.800
Here restart server c 89 153.

00:30:09.800
00:30:13.600
89 153 that's it. Now, let's come back.

00:30:12.800
00:30:16.900
[Typing]

00:30:16.900
00:30:18.400
So, what are the IPs we used?

00:30:18.400
00:30:20.700
[Typing]

00:30:20.700
00:30:24.600
So, just now here don't right

00:30:24.600
00:30:25.900
Now, let me do one thing.

00:30:25.900
00:30:33.400
[Mouse clicking]

00:30:33.400
00:30:34.900
Just let me copy.

00:30:34.900
00:30:37.300
IPs of your remote nodes.

00:30:37.300
00:30:41.000
That is first one and this is second
one.

00:30:41.067
00:30:44.000
[Background sounds]
00:30:44.000
00:30:44.726
third one

00:30:44.700
00:30:49.000
[Background sounds]

00:30:49.000
00:30:52.800
This is the public IPs of your Remote
Managed nodes.

00:30:53.000
00:30:53.800
Right.

00:30:53.800
00:30:57.400
One, two, three. Fine.

00:30:57.400
00:31:01.400
Now we done with your password-less
authentication as well.

00:31:01.400
00:31:02.549
The next step is

00:31:02.500
00:31:06.300
Here, we also verified this as well
simply by running SSH.

00:31:07.100
00:31:10.700
Here, you can provide user name
under and hostname, but insure of what I have verified.

00:31:10.700
00:31:15.000
Anyway, you are on this user, which
user, ansadmin.

00:31:15.000
00:31:20.300
So, by default if you run SSH any IP

00:31:20.300
00:31:23.500
is also going to consider username as
default, by default ansadmin,

00:31:23.800
00:31:28.200
in case if you want to mention, you
can also mention.

00:31:28.200
00:31:29.700
That's it.

00:31:29.700
00:31:32.600
[No audio]

00:31:32.600
00:31:37.700
Right. So fine. Just come back now,
we are on Ansible engine.

00:31:37.700
00:31:39.000
So, what is our next step?
00:31:39.221
00:31:42.000
[No audio]

00:31:42.000
00:31:45.600
Now we can test connection from
Ansible engine to your Managed

00:31:45.600
00:31:46.900
nodes using, some command.

00:31:46.900
00:31:52.100
But before that right, we have seen
here, provide the Managed

00:31:52.100
00:31:54.700
nodes IPS in the inventory file of your
Ansible.

00:31:57.400
00:31:59.300
So, I missed the step here.

00:31:59.300
00:32:02.800
We need to write here one more extra
step.

00:32:02.800
00:32:11.400
update inventory file, right, with IPs.

00:32:11.400
00:32:14.400
Now, let me do that step.

00:32:14.400
00:32:19.600
So, now we captured all IPs, right?

00:32:19.600
00:32:20.600
So, where is your IPs?

00:32:20.600
00:32:21.400
Here.

00:32:21.405
00:32:23.000
[Typing]

00:32:23.000
00:32:24.800
Now just to enter into here.

00:32:25.300
00:32:29.300
So, guys if you remember in the
installation part of your ansible,

00:32:29.300
00:32:30.800
I showed you something.

00:32:30.800
00:32:32.800
What is that?

00:32:32.800
00:32:37.500
After installation, we moved into etc
ansible, right.
00:32:37.500
00:32:41.900
Now, we have here some files called
ansible .cfg host and rolls.

00:32:41.900
00:32:45.600
So as of now, I am going to use these
files only because they are under root.

00:32:45.600
00:32:48.500
Actually, you need to create separate
files for your requirement.

00:32:48.800
00:32:49.200
Right?

00:32:49.200
00:32:52.100
Simply I'm going to show you by using
these files only so

00:32:52.100
00:32:55.000
from next video next class onwards,
we will try to create

00:32:55.000
00:32:58.700
our own required files.

00:32:58.700
00:33:01.000
So, guys here we have simply host
file, right?

00:33:01.100
00:33:04.100
So, if You observe here, you have
something here as of now

00:33:04.100
00:33:05.500
don't go and observe that.

00:33:05.523
00:33:08.100
[No audio]

00:33:08.100
00:33:11.500
So, you need to mention your IPs here
in this host file

00:33:11.500
00:33:13.200
Now, this is called Inventory file.

00:33:13.200
00:33:22.500
[No audio]

00:33:22.500
00:33:24.300
Okay, so that is Root file.

00:33:24.300
00:33:25.300
Right?

00:33:25.300
00:33:29.800
So anyway, with ansadmin we can
able to work with Root files as well.
00:33:29.800
00:33:32.200
That's why I'm using simply pseudo
hosts.

00:33:33.000
00:33:38.500
[No audio]

00:33:38.500
00:33:42.770
Fine. Now if you observe your host file
just,

00:33:42.770
00:33:46.300
so you have your IPs here.

00:33:46.300
00:33:49.300
I mean, this is the Inventory file, right?

00:33:49.300
00:33:53.000
So, whenever you here on Ansible
command or Playbook, right?

00:33:53.000
00:33:57.800
You are Ansible will try to look this
Inventory file, for your servers locations,

00:33:57.800
00:33:59.400
with servers It has to work

00:33:59.400
00:34:01.800
That information well get from this file,

00:34:01.800
00:34:05.300
but there are different ways to provide
this, right this oh

00:34:05.300
00:34:08.199
Inventory file, but for time being just
simply I mentioned

00:34:08.199
00:34:10.000
my host names.

00:34:10.000
00:34:13.300
I mean IP address of my remote
nodes, right, fine.

00:34:13.300
00:34:15.100
Now, what I can do is simply.

00:34:15.100
00:34:20.100
how you can verify the connectivity,

00:34:20.199
00:34:26.199
simply by running your ansible all -
ping command Right.

00:34:26.100
00:34:27.600
That is the command.
00:34:27.600
00:34:31.199
But if that command is using module,
don't worry about that.

00:34:31.100
00:34:38.699
Let just simply write ansible all - ping
and just see the result.

00:34:38.600
00:34:49.600
[No audio]

00:34:49.699
00:34:51.183
Just wait and see the result.

00:34:51.100
00:34:55.100
[No audio]

00:34:55.100
00:34:58.300
Right see guys for one server.

00:34:58.300
00:35:01.400
You got something, ansible facts.

00:35:01.400
00:35:03.900
So, what is that fact?

00:35:03.900
00:35:06.000
In remote server in this location.

00:35:06.000
00:35:10.600
You have Python, right changed false
you are not doing any modification

00:35:10.600
00:35:12.199
ping result is pong.

00:35:12.199
00:35:17.900
So, if you get for Ping module,
response as pong then it worked perfectly.

00:35:17.900
00:35:22.199
As of now just remember that for Ping.

00:35:22.199
00:35:25.400
This is like a ping command in your
Linux or Unix.

00:35:25.400
00:35:27.400
I'm in in Windows.

00:35:27.400
00:35:31.000
So, for Ping if you got response as
Pong, then we can say that

00:35:31.199
00:35:35.500
now our Ansible is able to
communicate with the server.

00:35:35.500
00:35:39.100
Fine then come to last server.
00:35:39.100
00:35:41.900
So, here also getting same information
means now your Ansible

00:35:41.900
00:35:44.199
is able to communicate with the server
as well.

00:35:44.199
00:35:48.800
Now, if you observe this server
actually, this is.

00:35:46.800
00:35:52.400
Let me show you my AWS Cloud.

00:35:52.400
00:35:55.900
So, this is 206.252.228, right?

00:35:55.900
00:35:59.300
[No audio]

00:35:59.300
00:36:05.200
Node 3, see that. So, in Node 3, we
know that,

00:36:05.200
00:36:07.900
we don't have python, right?

00:36:07.900
00:36:09.700
We don't have python.

00:36:09.700
00:36:15.573
That's what you are getting here is for
node 3.

00:36:15.500
00:36:18.800
See that.

00:36:18.800
00:36:22.100
Your Ansible is able to still
communicate with that server,

00:36:24.300
00:36:28.900
but, okay, these are having some
Python

00:36:28.900
00:36:33.000
under this location, is going to find out
this platform Python.

00:36:33.000
00:36:35.400
[No audio]

00:36:35.400
00:36:38.600
So anyway, it is able to find out your,
Python in this location
00:36:38.600
00:36:42.600
some platform Python, by using that it
is able to do this.

00:36:42.600
00:36:43.816
Let me do one thing.

00:36:43.816
00:36:45.900
[No audio]

00:36:45.900
00:36:48.600
I will do here, what is that path?

00:36:48.634
00:36:51.634
[Mouse clicking]

00:37:09.200
00:37:11.000
Okay, 3.6.8. Is there

00:37:11.000
00:37:11.800
whatever it may be watching,

00:37:11.800
00:37:13.100
Is there somewhere right?

00:37:13.100
00:37:16.900
Now, what I want to do is just for us, to
show.

00:37:16.900
00:37:33.700
[Typing]

00:37:33.700
00:37:37.100
Okay, we have in this way with your
Python on this server.

00:37:37.300
00:37:41.000
Anyway, is Ansible is able to look all
these locations.

00:37:41.000
00:37:42.900
Somewhere it got your Python
version.

00:37:42.900
00:37:43.500
It's working.

00:37:43.500
00:37:46.400
Now, what I want to do is let me
modify this name atleast.

00:37:46.400
00:37:48.400
[No audio]

00:37:48.400
00:37:48.800
Oh.

00:37:48.800
00:37:59.900
[Typing]
00:37:59.900
00:38:01.000
Now, let me try it.

00:38:01.000
00:38:12.800
[Mouse clicking]

00:38:12.800
00:38:18.800
So, if your server, guys, if your Ansible
engine and then

00:38:18.800
00:38:23.300
your remote nodes all are from same
environment

00:38:23.300
00:38:26.800
I mean, from same network, then this
it will

00:38:26.800
00:38:31.100
take very less, fraction of seconds to
work with connect with your remote nodes.

00:38:31.100
00:38:34.300
But here, this is from my VMware,
right, Ansible engine from

00:38:34.400
00:38:38.800
is from my VMware and they are from
your Cloud,

00:38:38.300
00:38:41.600
that's why it is taking some time to
establish a connection?

00:38:41.600
00:38:44.600
That's fine now see the change.

00:38:44.600
00:38:47.500
ansible facts.

00:38:47.500
00:38:50.500
See your Ansible is trying to find out
some Python

00:38:51.900
00:38:56.700
this Python or maybe, you see it is
tried with a different location.

00:38:56.700
00:38:59.900
So, it tried with this location, this
Python name with this

00:38:59.900
00:39:03.800
your Ansible tried with on remote
nodes to find out Python,
00:39:03.800
00:39:07.200
but now actually we don't have
anywhere in this in this way Python.

00:39:07.200
00:39:09.700
We had one of the locations in this
way, but I change

00:39:09.700
00:39:11.500
that on my remote node.

00:39:11.500
00:39:13.900
Now, we don't have Python right now.

00:39:13.900
00:39:18.000
Actually, we have but we don't have
Python with the names

00:39:18.000
00:39:21.300
which Identified by your Ansible
engine.

00:39:21.300
00:39:25.100
So basically, you'll have python in this
location in this way or with this name, with this name.

00:39:25.100
00:39:28.000
These are the possible ways, but we
don't have this possible

00:39:28.000
00:39:29.200
ways on my remote nodes.

00:39:29.200
00:39:34.500
That's why what is your Ansible is
doing observe that error

00:39:34.500
00:39:36.500
What is that error?

00:39:36.500
00:39:42.210
No, such file or directory means
Python is not there, as per your Ansible.

00:39:42.100
00:39:44.300
That's why your Ansible is not able to
work with your

00:39:44.300
00:39:45.500
remote nodes.

00:39:45.500
00:39:46.085
That's it.

00:39:46.085
00:39:48.700
[No audio]

00:39:48.700
00:39:49.500
Right.
00:39:49.500
00:39:52.100
So, if you have Python, then you are
Ansible will work

00:39:52.100
00:39:53.100
with your remote nodes.

00:39:53.100
00:39:56.600
If you don't have then you need to you
work with ROM modules,

00:39:56.600
00:39:59.500
right? So, while going forward I will
show you how to work

00:39:59.500
00:40:01.200
with ROM modules as well.

00:40:01.200
00:40:02.100
If you don't have a Python.

00:40:02.100
00:40:06.400
Yes, you can work with your remote
nodes, but how will see

00:40:06.500
00:40:07.600
while going forward.

00:40:08.700
00:40:11.000
Right, now, let me rerun and see the
result

00:40:11.100
00:40:13.400
just now I created Python location.

00:40:13.480
00:40:16.400
[Background noise]

00:40:16.400
00:40:19.700
And I want to show you one more
thing after running this command.

00:40:19.700
00:40:25.300
Just wait, for URL 206 228.

00:40:25.300
00:40:29.600
See this is the Python location it has
identified on the server, but for remaining servers,

00:40:29.600
00:40:34.500
your Ansible is able to find the location
as user ping Python, right?

00:40:34.500
00:40:39.700
So, what I am doing is on my third
host, simply, I'm installing.

00:40:37.500
00:40:42.300
[Typing]
00:40:42.300
00:40:43.200
Python

00:40:43.259
00:40:45.800
Okay, let me install Python 2.

00:40:45.800
00:40:48.000
[Typing]

00:40:48.000
00:40:48.500
Yes.

00:40:48.500
00:40:53.300
[No audio]

00:40:53.300
00:40:57.200
Guys, with your remote nodes once if
you done with your username

00:40:57.200
00:41:00.000
and password with Root privileges,
then you don't have any

00:41:00.000
00:41:02.300
work with your remote nodes
everything you are doing from

00:41:02.300
00:41:04.400
your Ansible engine only.

00:41:04.400
00:41:06.700
That's why we are using Ansible to
work with your remote nodes without logging into there.

00:41:08.400
00:41:11.200
[No audio]

00:41:11.200
00:41:15.800
Still, we don't have which Python but
we have Python 2, right.

00:41:15.800
00:41:19.000
Anyway, it has been created and in
the terms of Python 2, right

00:41:19.000
00:41:23.000
Now, what I will do is again, I am
going to run, previously you got this location.

00:41:23.000
00:41:25.600
Now, let me run this.

00:41:25.600
00:41:29.200
[No audio]

00:41:29.200
00:41:34.500
So, your Ansible will try to give the
preference in this way
00:41:34.500
00:41:37.200
will try to look find out this Python of
us in if in case its

00:41:37.200
00:41:40.400
not there it will try with this location in
this way It will try

00:41:40.400
00:41:43.700
we will see that, see now, what it tried.

00:41:43.700
00:41:54.100
[No audio]

00:41:54.100
00:41:58.600
Okay higher version, right, python 3.6,
so still it is working with your python 3.6.

00:42:00.600
00:42:04.200
Okay, so whatever it may be you guys
finally if you have Python

00:42:04.200
00:42:08.100
on remote nodes right then your
Ansible will communicate with that.

00:42:08.100
00:42:10.400
If you don't have it will fail.

00:42:10.400
00:42:14.200
So, if it will fail then how we can work
with ROM modules, right?

00:42:14.200
00:42:16.800
We will see that while going forward

00:42:16.800
00:42:19.900
and guys, this is just a configuration.

00:42:19.900
00:42:24.000
Okay in the next video, we will work
with the details about inventory,

00:42:24.000
00:42:29.100
then your Ansible commands allow
commands

00:42:29.100
00:42:31.400
Right, fine.

00:42:31.400
00:42:32.700
You need to understand one more
thing very clearly.

00:42:32.700
00:42:33.500
That is.

00:42:33.582
00:42:35.500
[No audio]
00:42:35.500
00:42:39.600
See in these steps, right, we
connected with your remote nodes

00:42:39.600
00:42:44.000
only to create ansadmin user across
all your Managed nodes

00:42:44.000
00:42:47.000
and then just to provide password and
root privileges.

00:42:47.000
00:42:53.400
So, once it is done, then we are not
going to login with your remote nodes.

00:42:53.400
00:42:55.700
We are doing everything from your
Ansible engine.

00:42:55.700
00:42:57.700
[No audio]

00:42:57.700
00:43:00.500
Right, so that's it. Okay.

00:43:00.500
00:43:03.000
Okay guys. Thank you for watching
this video.
Transcript
00:00:00.000
00:00:02.200
Friends here.

00:00:02.200
00:00:05.300
We are going to discuss about ansible
directory structure.

00:00:06.100
00:00:09.400
So understanding about ansible
directory structure is very

00:00:09.400
00:00:10.400
very important.

00:00:11.000
00:00:13.400
But anyway here I am going to give a
very simple introduction

00:00:13.400
00:00:15.200
about your ansible directory structure.

00:00:16.900
00:00:19.900
So friends, we are assuming that
we're having three servers

00:00:20.000
00:00:23.400
in our infrastructure in our
environment and we are going
00:00:23.400
00:00:26.400
to manage them with tangible, right?

00:00:26.600
00:00:27.700
So that's why what we did.

00:00:27.800
00:00:31.100
We have taken one extra server and
here we install our ansible

00:00:31.100
00:00:34.400
and we are calling This Server as
ansible engine and these

00:00:34.400
00:00:38.000
three servers are called ansible nodes
or managed nodes or

00:00:38.000
00:00:43.300
clients. And to work from your hands
will Engine with your

00:00:43.300
00:00:45.900
remote nodes or your managed
nodes, right?

00:00:46.100
00:00:47.800
So we've done some configuration
here.

00:00:48.400
00:00:51.600
So ansible is using SSH connectivity
to work with your remote

00:00:51.600
00:00:56.100
servers. That's why we created
password less authentication

00:00:56.900
00:01:01.200
to work with your remote nodes
through the SSH and we done

00:01:01.200
00:01:04.000
that configuration as well right fine.

00:01:04.800
00:01:09.700
So guys here my ansible engine
server is from my VMware and

00:01:09.700
00:01:10.200
remaining three.

00:01:10.400
00:01:11.500
Or Worse right?

00:01:11.500
00:01:12.900
I created from my cloud.
00:01:13.800
00:01:18.500
So these are the three nodes from my
cloud and this is my

00:01:18.500
00:01:20.100
ansible engine server.

00:01:20.500
00:01:25.500
So I selected my VMware are there I
install my ansible.

00:01:25.900
00:01:27.700
First of all, let me check it and Sybil.

00:01:29.800
00:01:33.200
Yes, we have your ansible so friends
once if we install your

00:01:33.200
00:01:37.600
ansible then on your ansible engine
server right by default

00:01:37.600
00:01:38.800
you will get this location.

00:01:40.400
00:01:43.800
Rooty DC and Sybil and inside of this
you have some files

00:01:44.000
00:01:48.300
they are called ansible dot CFG host
and One Directory called

00:01:48.300
00:01:51.900
roles. So this is a simply your ansible
directory structure.

00:01:53.300
00:01:53.600
Right.

00:01:53.600
00:01:57.700
So here you have to understand that
this path is called default

00:01:57.700
00:02:00.700
ansible home in this location.

00:02:01.100
00:02:05.300
You have three things to or files and
one more is directory.

00:02:05.700
00:02:09.199
So first to file a runcible DOT c f g
second is host and

00:02:09.199
00:02:10.199
one more is roles.
00:02:10.699
00:02:12.699
So first try to remember these three
names.

00:02:13.600
00:02:16.900
So make sure that by default under
root TC.

00:02:16.900
00:02:20.100
You will have ansible on your ansible
engine server.

00:02:21.400
00:02:23.800
Alright, once you've installed your
ansible, you're getting

00:02:23.800
00:02:24.500
this location.

00:02:24.500
00:02:28.100
And in this location, you're having
these files, right and

00:02:28.100
00:02:32.300
for time being we are going to discuss
about only your ansible

00:02:32.300
00:02:35.700
dot C of G and then host information.

00:02:35.900
00:02:36.900
I mean host file.

00:02:37.300
00:02:39.500
So we are later will work with about
roles.

00:02:39.800
00:02:41.700
That is very very important actually.

00:02:41.900
00:02:44.400
But as of now, even though if you go
you will get confused.

00:02:44.400
00:02:49.000
So that's why just for time being
Forget about this directory.

00:02:50.100
00:02:51.200
Anyway, you have three things.

00:02:51.300
00:02:54.700
Just remember as of now ansible dot c
f g and hosts file

00:02:54.900
00:02:57.500
in your default ansible home.
00:02:59.200
00:03:04.700
fine then guys suppose if you want to
work with your remote

00:03:04.700
00:03:09.800
servers, then what we are doing the
remote servers or managed

00:03:09.800
00:03:11.200
nodes IPS.

00:03:11.200
00:03:13.900
We are providing in hosts files.

00:03:15.100
00:03:18.700
Suppose if you don't provide how
ansible Indian can understand

00:03:18.700
00:03:21.700
that with what servers it has to work.

00:03:23.600
00:03:27.800
first let me whooping my Terminal
anyway, we are here right?

00:03:27.800
00:03:29.500
Let me simply run and Sybil.

00:03:31.600
00:03:39.900
all iPhone m-pin you're getting empty
list is empty provided

00:03:39.900
00:03:45.300
host list is empty means your host file
does not have any

00:03:45.400
00:03:47.200
managed nodes information.

00:03:48.100
00:03:51.200
So if you have then only you can your
ansible Indian can

00:03:51.200
00:03:53.800
work with your managed nodes, right?

00:03:54.500
00:03:58.500
So let me open that we I wrote DC
guys.

00:03:58.500
00:04:01.800
This is the default location means
under root location.

00:04:01.800
00:04:03.600
That's why just to edit that file.

00:04:03.600
00:04:04.400
I am using sudo.
00:04:06.400
00:04:07.600
But anyway, we're going forward.

00:04:07.600
00:04:10.900
We will take our own host or our own
inventory file.

00:04:11.800
00:04:14.400
Let me open this first ansible host.

00:04:15.300
00:04:15.700
Right?

00:04:15.900
00:04:18.800
So all our commented any other is the
default information

00:04:18.800
00:04:20.500
you don't worry about that as of now.

00:04:20.800
00:04:23.899
Now if You observe here, we don't
have any IP addresses here.

00:04:24.200
00:04:27.399
So if you don't have then how your
ansible can understand

00:04:27.399
00:04:29.700
that with what servers it has to work.

00:04:30.100
00:04:33.900
So that's why before going to work
with your manager notes.

00:04:34.600
00:04:38.300
Through your ansible you need to
mention the remote servers

00:04:38.400
00:04:43.100
IP addresses or fully qualified domain
names in this file.

00:04:44.100
00:04:50.900
Right first, let me show you my See,
these are my notes,

00:04:50.900
00:04:52.100
right just click on this.

00:04:52.100
00:04:54.200
So, this is AWS Cloud Server, right?

00:04:54.600
00:04:57.300
So guys here you need to remember
one more point.
00:04:57.400
00:05:01.900
My ansible engine is from VMware
and my three nodes are from

00:05:01.900
00:05:06.600
AWS cloud in case if your ansible
engine is also from your

00:05:06.600
00:05:10.100
AWS Cloud, you can create one extra
server and they're under

00:05:10.100
00:05:11.800
server. You can install your ansible
engine.

00:05:12.700
00:05:16.400
So if if you are all servers or from
AWS Cloud then instead

00:05:16.400
00:05:17.400
of public IP.

00:05:17.400
00:05:18.400
You can use private eye.

00:05:18.600
00:05:23.800
As well, but my server my aunt's will
engine is from out

00:05:23.800
00:05:24.800
of your AWS Cloud.

00:05:24.800
00:05:25.400
That's why.

00:05:26.600
00:05:30.000
In my ansible engine to work with
remote nodes.

00:05:30.000
00:05:32.800
I need to provide remote nodes public
Eye Peas.

00:05:34.700
00:05:39.000
Right, but in real time suppose, you
may have your all servers

00:05:39.000
00:05:40.000
from uw's cloud.

00:05:41.600
00:05:44.300
Right, you need to understand all the
scenarios fine.

00:05:45.200
00:05:47.800
So guys now what I am doing is for
first server If You observe
00:05:47.800
00:05:50.700
this is the public IP, right?

00:05:50.700
00:05:53.100
So already I noted all the public eye
peas.

00:05:53.100
00:05:55.700
So these are my all three servers
public eye piece.

00:05:56.500
00:06:00.000
Let me copy this eyepiece into this file.

00:06:01.200
00:06:01.800
That's it.

00:06:01.900
00:06:05.200
No, let me save it she previously
whenever if you run this

00:06:05.200
00:06:08.600
command it was showing something
like your host is empty

00:06:09.100
00:06:09.900
now see that.

00:06:11.400
00:06:17.200
I am running right so it is going to pin it
is going to check

00:06:17.200
00:06:20.800
the connectivity with your remote
nodes using this ansible

00:06:20.800
00:06:22.200
all - mm ping command.

00:06:22.900
00:06:25.700
So don't worry about this entire syntax
will discuss in detail

00:06:25.700
00:06:28.400
about this Command right fine.

00:06:28.600
00:06:31.000
And don't worry about this warning is
just warning message

00:06:31.000
00:06:32.000
we can disable it.

00:06:32.900
00:06:36.900
Okay fine now guys now we can able
to see we are getting
00:06:37.000
00:06:40.800
a response for Ping command ping
module response as pong

00:06:40.800
00:06:44.500
that Now you're three servers or
reach.

00:06:44.800
00:06:48.500
I mean you are answerable can able
to reach your remote nodes.

00:06:48.900
00:06:49.500
That's fine.

00:06:51.000
00:06:56.800
now let me explain about your
inventory.

00:06:56.800
00:06:58.400
Anyway, the that's what we are
discussing.

00:06:58.400
00:06:58.800
Right.

00:06:59.500
00:07:03.500
So this host files simply it is called
inventory file.

00:07:04.900
00:07:09.400
So by default you are getting the
inventory file name as

00:07:09.400
00:07:15.400
hosts. But it's not mandatory to take
always your inventory

00:07:15.400
00:07:16.500
file name as this one.

00:07:16.500
00:07:18.000
You can also take some XYZ.

00:07:19.100
00:07:20.800
But also take some my host.

00:07:22.100
00:07:25.000
You can also take my inventory or
inventory any name you

00:07:25.000
00:07:29.600
can provide so in case if we change
the inventory file name

00:07:29.600
00:07:33.800
or location, then that file information
you need to mention
00:07:34.000
00:07:37.900
in your ansible dot CFG file.

00:07:39.300
00:07:42.800
So this is you have a right and double
dot CFG in this file

00:07:43.400
00:07:44.900
first. Let me open that.

00:07:46.800
00:07:51.800
So simply I am going to I am not going
to discuss entire

00:07:51.800
00:07:53.200
information about this file.

00:07:53.900
00:07:59.500
Just see that inventory file location
inventory by default.

00:07:59.500
00:08:02.100
This is the location that's why you
wanted to mention ansible

00:08:02.100
00:08:03.700
can understand that by default.

00:08:03.700
00:08:07.300
It will try to look for your inventory file
under root.

00:08:07.300
00:08:10.700
It is see ansible there will look for
hosts file.

00:08:11.500
00:08:15.700
Other than that if you change the file
name or if you change

00:08:15.700
00:08:19.000
the location of your Inventory, then in
this configuration

00:08:19.000
00:08:20.900
file. You need to change this.

00:08:21.000
00:08:22.300
You need to add enabled this.

00:08:22.300
00:08:24.700
I mean you have to deliver this hash
symbol and you need

00:08:24.700
00:08:26.200
to provide complete path.
00:08:27.300
00:08:29.700
Likewise you have different
parameters in this will discuss

00:08:29.700
00:08:30.400
step by step.

00:08:31.300
00:08:31.800
Right?

00:08:32.700
00:08:38.200
So now whatever the server's you are
going to manage with

00:08:38.200
00:08:41.600
your ansible all those server's IP
addresses.

00:08:41.600
00:08:44.100
We are mentioning in the file called
host.

00:08:44.600
00:08:47.600
So that is called inventory file, right?

00:08:47.600
00:08:51.400
So the default file is hosts file, but you
may take anything.

00:08:51.500
00:08:54.299
Let me show you a simple example so
that you can understand.

00:08:55.600
00:08:59.600
so what I am going to do is let me
move into.

00:09:01.800
00:09:05.100
So I am going to create my host.

00:09:07.400
00:09:07.900
Right.

00:09:07.900
00:09:10.300
Let me copy my host information files.

00:09:11.400
00:09:13.300
So we have here right our eyepiece.

00:09:17.100
00:09:18.100
That means save it.

00:09:19.300
00:09:21.200
Oh, this is under root, right?

00:09:21.200
00:09:23.100
I need to work with sudo.
00:09:24.200
00:09:28.600
so that's why we don't use this default
location to work

00:09:28.600
00:09:32.900
with your ansible will create our own
location will see that

00:09:35.500
00:09:39.600
fine Now what we have to do is I will
do one more thing.

00:09:40.800
00:09:42.900
In your default location, whatever the
server's you have.

00:09:42.900
00:09:43.700
Let me delete them.

00:09:45.300
00:09:46.300
So now we don't have anything.

00:09:46.300
00:09:51.400
Let me run simply ansible all - um pink
now see that you're

00:09:51.400
00:09:52.600
getting list is empty.

00:09:53.600
00:09:55.000
Now your inventory files.

00:09:55.000
00:09:58.200
I mean you are remote servers
information is there in this

00:09:58.200
00:09:59.500
file in this file?

00:09:59.500
00:10:02.700
You don't have but by default your
answer will try to look

00:10:02.700
00:10:06.800
into this file only but now we have our
IP is in this file.

00:10:06.900
00:10:10.500
That's why you need to mention this
file in your hands will

00:10:10.500
00:10:11.600
dot CFG file.

00:10:12.400
00:10:17.000
Let me open ansible Dot CFG file and
let me right here.
00:10:18.800
00:10:22.100
And anyway, you can enable below
line, but I don't want to

00:10:22.100
00:10:27.600
delete Disturb This existing default file
rooty TC and Sybil,

00:10:28.500
00:10:29.000
that's it.

00:10:29.600
00:10:34.500
Now while running your hands below
any ansible command write

00:10:34.500
00:10:38.800
your answer will try to look for
inventory file with this

00:10:38.800
00:10:43.000
information. Just now we ate right now
see that you're going

00:10:43.000
00:10:47.900
to I mean you are answerable in is
going to work based on

00:10:48.200
00:10:48.400
the information.

00:10:48.600
00:10:54.400
And refile my host because this my
host information you mentioned

00:10:54.400
00:10:56.100
in your answer will dot CFG file.

00:10:56.700
00:10:57.400
So that's it.

00:10:58.500
00:11:01.000
So now you can understand that right?

00:11:01.000
00:11:03.300
So whatever the files you have in this
location.

00:11:04.400
00:11:06.000
Let me remove my host.

00:11:06.200
00:11:08.600
I don't want to use in this location.

00:11:11.900
00:11:15.100
So by default, these are the directory
structure forever
00:11:15.100
00:11:17.900
ansible. So you need to remember that
in this file.

00:11:17.900
00:11:22.200
You are going to mention you are all I
piece right and in

00:11:22.200
00:11:24.700
this you're going to mention some
settings.

00:11:25.700
00:11:28.200
Suppose just now we modified host.

00:11:28.200
00:11:32.000
I mean inventory file name the now
you want to look your

00:11:32.000
00:11:33.800
ansible has to work on this inventory
file.

00:11:33.800
00:11:34.800
Then that information.

00:11:34.800
00:11:38.700
We are providing the in this ansible
fine, right?

00:11:39.200
00:11:40.200
So anyway, we did that.

00:11:40.200
00:11:42.700
Let me remove that.

00:11:47.200
00:11:47.700
That's it.

00:11:47.800
00:11:52.600
Now if I run we don't have any IP.

00:11:54.900
00:11:56.500
Addresses in inventory file.

00:11:56.500
00:11:58.400
That's why you're getting a list is
empty.

00:11:58.400
00:12:01.600
So your answer will can understand
for with which servers

00:12:01.600
00:12:02.400
it has to work.

00:12:04.300
00:12:04.800
That's it.
00:12:05.600
00:12:06.900
Right fine.

00:12:07.100
00:12:11.200
So guys in real time just assume that
just assume that there

00:12:11.200
00:12:14.000
are four five people's are working from
this server only

00:12:14.000
00:12:16.200
and they are all are using your
ansible.

00:12:16.700
00:12:19.300
So then just assume that instead of as
of now we are using

00:12:19.300
00:12:20.500
ants admin user right.

00:12:20.800
00:12:23.600
So I assume that Anne's admin one
and that mean to and submit

00:12:23.600
00:12:24.600
three something like that.

00:12:24.600
00:12:25.700
There are five users.

00:12:26.800
00:12:30.600
So first user is going to work with
some different servers

00:12:30.700
00:12:33.200
and second user is going to work with
some different servers

00:12:33.200
00:12:38.300
likewise. So in that case if users are
going to use same

00:12:38.300
00:12:41.700
file same inventory default location,
whatever you have default

00:12:41.700
00:12:46.700
inventory file host then while running
your ansible commands

00:12:46.700
00:12:48.600
you are going to look into that file only.

00:12:48.900
00:12:51.300
So in that along with your servers are
some other servers
00:12:51.300
00:12:52.000
are also there.

00:12:53.500
00:12:53.700
Right.

00:12:53.700
00:12:56.800
That's why just to avoid confusion right
whenever if you're

00:12:56.800
00:12:58.600
trying to work within your real time.

00:13:00.000
00:13:03.000
Right, so from which user you are
going to work from this

00:13:03.000
00:13:03.600
user, right?

00:13:04.900
00:13:08.900
So in this unit, just try to create your
own directory.

00:13:09.100
00:13:10.900
Let's say I am going to create.

00:13:12.300
00:13:16.500
My otherwise my ansible.

00:13:17.900
00:13:19.500
Working directory.

00:13:19.800
00:13:20.400
That's it.

00:13:20.700
00:13:24.500
Now, let me move into that try to copy
the default files,

00:13:24.500
00:13:29.400
whatever we how ansible so we have
something here, right?

00:13:29.600
00:13:31.700
So all our I'm going to copy to here.

00:13:32.600
00:13:33.100
That's it.

00:13:35.700
00:13:36.200
Right.

00:13:36.200
00:13:39.900
Now we have so now we do we are
not going to use the default

00:13:39.900
00:13:43.700
location inventory file and your hands
will not CFG file
00:13:44.100
00:13:46.600
now. We have our own inventory file.

00:13:47.900
00:13:51.500
And our own configuration file
suppose, if you don't want

00:13:51.500
00:13:53.200
to take hosts as host.

00:13:53.700
00:13:56.700
I mean inventory file name as if you
don't want to take as

00:13:56.700
00:13:59.000
host. You can do something.

00:13:59.000
00:14:04.400
Like let me create I am going to
remove this host files right

00:14:04.500
00:14:08.000
now. I am going to create inventory
something simply.

00:14:08.600
00:14:09.200
That's it.

00:14:13.200
00:14:15.600
Let me copy my IP addresses.

00:14:17.000
00:14:21.600
So guys my intention is I don't want to
use the default location

00:14:21.800
00:14:22.800
inventory file.

00:14:24.300
00:14:24.800
That's it.

00:14:26.300
00:14:26.700
Right.

00:14:27.200
00:14:31.000
So now let me run and Sybil all - um
pink it is not going

00:14:31.000
00:14:31.500
to work.

00:14:32.100
00:14:35.200
The reason is you change your
inventory file name.

00:14:36.500
00:14:39.500
Right and Anyway by default your
answer will try to look
00:14:39.500
00:14:44.400
for root etc' and simple host inventory
for this file.

00:14:44.400
00:14:45.400
It will try to look.

00:14:46.600
00:14:50.400
But now we are not using that we're
under working directory

00:14:50.700
00:14:53.700
there. We have ansible lot CFG file
now in this file if you

00:14:53.700
00:15:01.200
mention your inventory file location
Right see what I am

00:15:01.200
00:15:03.600
doing is my inventory.

00:15:04.300
00:15:06.000
Now, we are not under root TC.

00:15:06.100
00:15:09.400
Simply you can take dot dot means
current location right

00:15:09.400
00:15:12.800
dot but now our inventory file name is
not Host.

00:15:13.200
00:15:15.300
This is our inventory file location.

00:15:16.400
00:15:16.900
That's it.

00:15:17.800
00:15:18.800
So guys be clear.

00:15:18.800
00:15:22.800
I use dot why I use dot means
wherever you have your answer

00:15:22.800
00:15:25.900
will dot CFG file now in that location
only we have inventory

00:15:25.900
00:15:29.100
file with the name called inventory not
Inventory, you can

00:15:29.100
00:15:31.300
take anything right now.
00:15:31.300
00:15:35.000
I am running ansible all - IAM ping
now it is going to work.

00:15:39.000
00:15:39.200
Bye.

00:15:40.900
00:15:44.500
So guys but don't modify this name
ansible dot CFG in case

00:15:44.500
00:15:47.300
if you modify this file name and small
dots you have changed

00:15:47.300
00:15:51.300
of this some other file name then in
the current location.

00:15:51.300
00:15:54.000
Your ansible is not able to finance Bill
Dot CFG file.

00:15:54.000
00:15:58.200
That's why it is trying to consider the
default ansible dot

00:15:58.200
00:15:58.900
CFG file.

00:15:59.500
00:16:00.700
See, let me do one thing.

00:16:02.900
00:16:04.500
I'm going to take it as a backup.

00:16:04.600
00:16:05.000
Now.

00:16:05.200
00:16:11.400
We don't have any ansible dot CFG
file the default file and

00:16:11.400
00:16:13.800
double dot c f g if that is there then
only your hands will

00:16:13.800
00:16:16.900
can understand that now in the current
location.

00:16:17.100
00:16:19.400
We don't have ansible dot CFG.

00:16:20.500
00:16:24.900
Now if I try to run ansible all - m-pin
now see that.
00:16:28.000
00:16:29.400
It is not able to understand.

00:16:31.300
00:16:31.600
Right.

00:16:31.600
00:16:37.900
I mean it is not able to get your server
IP s from your inventory

00:16:37.900
00:16:42.300
file. So in case if you want to take this
as the inventory

00:16:42.300
00:16:46.700
file this file location, you need to
mention in this ansible

00:16:46.700
00:16:50.700
dot c f g but here now we are not
having like file name as

00:16:50.700
00:16:52.000
ants will dot CFG.

00:16:52.200
00:16:56.300
We're having like and simple dot CFG
underscore backup, right?

00:16:56.300
00:16:58.400
That's why I don't modify this name.

00:16:58.700
00:17:01.000
So for your entire ansible.

00:17:01.200
00:17:04.400
Working with your ansible
configuration file should be always

00:17:04.598
00:17:05.900
ansible dot CFG.

00:17:08.500
00:17:09.500
Right fine.

00:17:10.000
00:17:11.400
So now I am running.

00:17:12.700
00:17:14.800
Don't worry about this ansible all I
even jumping.

00:17:14.800
00:17:17.098
I will give in details about this
command.

00:17:18.500
00:17:21.800
Now I am running the tangible all - um
ping now it is going
00:17:21.800
00:17:25.900
to work with your remote nodes just
for connectivity to check

00:17:25.900
00:17:29.900
connectivity. It's working right and one
more thing.

00:17:30.700
00:17:33.500
Now as of now you don't worry about
this.

00:17:33.500
00:17:34.800
Just I'm commenting this.

00:17:38.599
00:17:47.300
ansible all - mmm ping Now here we
don't have any inventory

00:17:47.300
00:17:48.500
file location in this file.

00:17:50.099
00:17:51.400
Right, so that's why.

00:17:53.200
00:17:55.700
You are your ants will is unable to
understand about your

00:17:56.500
00:17:57.900
remote servers eyepiece.

00:17:58.700
00:18:01.900
That's why I'm not getting anything in
case if you don't

00:18:01.900
00:18:06.000
want to mention your inventory file in
ansible dot CFG.

00:18:06.800
00:18:10.500
Otherwise assume that for for you only
you have different

00:18:10.500
00:18:14.800
set of servers just assumed that so
sometimes I want to work

00:18:14.800
00:18:17.600
with some 50 servers and sometimes I
want to work in some

00:18:17.600
00:18:18.600
other 50 servers.

00:18:19.400
00:18:22.000
Anyway, you can mention that in one
single inventory file
00:18:22.000
00:18:24.700
and there you can Of them as of now,
I don't want to discuss

00:18:24.700
00:18:28.200
about groups but assume that I have
inventory one and inventory

00:18:28.200
00:18:31.900
to but I don't want to mention in our
ansible DOT CFG file

00:18:31.900
00:18:34.700
my inventory file location, even though
if you mention I

00:18:34.700
00:18:38.800
don't want to use that inventory file, I
want to use dynamically

00:18:38.800
00:18:41.200
my inventory file, then you can have
account you have an

00:18:41.200
00:18:44.700
option called - I then simply you can
mention your inventory

00:18:44.700
00:18:45.200
in this way.

00:18:45.200
00:18:45.700
You can run.

00:18:47.300
00:18:52.300
And symbol, right - with a hyphen I
option means use this

00:18:52.300
00:18:55.800
inventory even though if you have
some inventory file location

00:18:55.800
00:19:00.200
in this don't use that use my inventory,
whatever I mentioning

00:19:00.200
00:19:02.200
in command line, that's it.

00:19:04.300
00:19:07.600
So guys from this video you have to
understand that.

00:19:10.100
00:19:13.900
For your answer will configuration to
work with the ansible.
00:19:14.000
00:19:19.700
You have three things ansible dot CFG
hosts file and then

00:19:19.700
00:19:22.200
rolls. So anyway here we are going to
work.

00:19:22.300
00:19:24.600
We are not going to work with the
roles as of now.

00:19:24.800
00:19:25.800
Let me remove that.

00:19:25.800
00:19:26.900
That is a directory, right?

00:19:30.800
00:19:33.200
And the default inventory file is host.

00:19:33.200
00:19:37.000
But you can also modify that in case if
you modify that file

00:19:37.000
00:19:40.800
name, you need to mention your
ansible dot CFG, but don't

00:19:40.800
00:19:42.900
modify ansible dot CFG file name.

00:19:43.900
00:19:44.300
Okay.

00:19:44.700
00:19:49.100
So guys along with this you can write
your answer will dot

00:19:49.100
00:19:51.000
CFG file in different locations.

00:19:52.400
00:19:56.900
And there is some priority based on
that your ansible will

00:19:56.900
00:20:00.500
pick and pull dot CFG file and based
on that configuration

00:20:00.500
00:20:01.200
file details.

00:20:01.200
00:20:03.100
Your hands will work right?

00:20:03.100
00:20:04.700
We'll discuss that later.
00:20:06.000
00:20:06.400
Right.

00:20:06.900
00:20:07.300
That's it.

00:20:09.400
00:20:10.000
Okay.

00:20:10.000
00:20:11.300
Thank you for watching this video.
Transcript
00:00:00.000
00:00:02.000
Hi friends.

00:00:02.000
00:00:06.500
Here we are going to discuss about
how to disable host key checking

00:00:06.500
00:00:07.300
in Ansible.

00:00:07.800
00:00:10.700
So first of all, what is 'Host Key
Checking'?

00:00:11.600
00:00:14.400
So let's just assume that you are going
to connect with anyone

00:00:14.400
00:00:19.500
of the server at very first time using
your SSH. Right then

00:00:19.500
00:00:22.600
it will ask the confirmation like in this
way.

00:00:23.100
00:00:24.100
Let me show you that.
00:00:25.900
00:00:28.800
Are you sure you want to continue
connecting?

00:00:28.800
00:00:30.900
Yes or no? You have to provide yes.

00:00:30.900
00:00:33.600
Anyway whenever if you are working
with your Ansible, you

00:00:33.600
00:00:35.700
need to work with your remote servers
by default.

00:00:35.700
00:00:38.200
I don't want to provide this yes or no
option by default.

00:00:38.200
00:00:42.000
I want to make it as yes. I want to
disable asking about this.

00:00:42.000
00:00:46.600
So Host Key Checking is one of the
parameter for your Ansible.

00:00:46.600
00:00:49.700
You need to disable it. If you disable
then whenever

00:00:49.700
00:00:52.100
if you're trying to connect with your
remote server using

00:00:52.100
00:00:55.000
Ansible, it won't ask about this
confirmation.

00:00:57.400
00:00:58.800
So for that you need to disable.

00:00:59.100
00:01:04.500
So before that, let me start my
manager nodes so that I can

00:01:04.500
00:01:05.200
show you this.

00:01:08.400
00:01:10.600
So only three managed nodes, let me
start them.

00:01:12.100
00:01:13.900
So meanwhile guys I will do one thing.
00:01:22.600
00:01:26.600
You know, right we have default
Ansible home we have here

00:01:26.800
00:01:30.600
Ansible configuration file, host file and
then roles directory.

00:01:30.800
00:01:36.000
But for practice and even in real time,
most of the cases,

00:01:36.000
00:01:39.700
you won't use this location to work
with your Ansible. Because

00:01:39.700
00:01:42.400
I assume that there are 2-3 members
are working from

00:01:42.400
00:01:47.400
this server. I mean they are using
Ansible.

00:01:47.400
00:01:49.700
As of now we are in suppose
ansadminuser. Er, yes.

00:01:49.700
00:01:54.400
I assume that there is one more
ansadmin2 or ansadmin1.

00:01:54.400
00:01:57.400
They're also going to use same server
to work with they're

00:01:57.400
00:01:58.100
managed nodes.

00:01:58.100
00:01:59.500
I mean they're using this ansible,

00:02:00.000
00:02:03.200
so for their purpose, they have their
own configuration settings.

00:02:03.400
00:02:05.100
They have their own manage servers.

00:02:05.500
00:02:09.699
So if you use common location, then
there is a confusion.

00:02:10.000
00:02:13.199
That's why whenever if you're trying to
work with your servers
00:02:13.199
00:02:15.700
even in real time, first of all, you will
create your home

00:02:15.700
00:02:20.300
directory for your Ansible, right? And
now let me do one thing.

00:02:20.300
00:02:26.700
I assume that suppose you are going
to work with prod, nonprod, right?

00:02:26.700
00:02:29.100
So that's what I am doing is make
directory

00:02:30.400
00:02:39.000
'my_ansible_prod' and make that just
assumption guys.

00:02:40.800
00:02:47.700
'my_ansible_nprod' that's it. Right.

00:02:47.700
00:02:51.700
So just assume that you are going to
work with the prod or nprop, that is your wish, right?

00:02:51.700
00:02:58.300
So that's why suppose I am going to
move into nprod, right?

00:02:58.400
00:02:59.100
Now here as of now

00:02:59.100
00:03:03.500
we don't have anything but you need
to copy all the required

00:03:03.500
00:03:05.600
files to this location. Nothing

00:03:05.600
00:03:08.900
is there any way one is inventory file
and one more is configuration

00:03:08.900
00:03:11.300
file and other thing is roles. As of now
we are not going

00:03:11.300
00:03:13.500
to touch with roles, we'll see them in
future,

00:03:13.500
00:03:13.900
not now.
00:03:14.800
00:03:18.300
So now what I am doing is and if they
are from root, that's

00:03:18.300
00:03:20.900
why just I'm using Sudo. Anyway, our
answered main user having

00:03:20.900
00:03:21.800
Sudo privileges.

00:03:22.200
00:03:30.400
So 'cp - r'. Now, I want to copy
whatever the files you have there

00:03:30.400
00:03:33.600
I'm going to copy to here, right?

00:03:33.600
00:03:36.700
Now if you observe all are with root,
but we want to make

00:03:36.700
00:03:47.100
the user as suppose answered mean
so just I'm using 'chown - R ansadmin'

00:03:47.100
00:03:51.200
right? For - what happened?

00:03:52.800
00:03:56.200
Okay so that is root file so you need to
run with the pseudo,

00:03:56.300
00:04:01.200
that's fine. Now user is answered.
Right even if you want to

00:04:01.200
00:04:03.800
change group you can change it no
problem. Now let me remove

00:04:03.800
00:04:06.700
roles as of now. We are not going to
work with roles as of now.

00:04:06.700
00:04:10.400
Let me remove them, that's fine. Now
we have your host

00:04:10.400
00:04:15.200
file and then you have your ansible.cfg
file. So once

00:04:15.200
00:04:21.000
you do this immediately, immediately
just open your ansible.cfg file.
00:04:21.000
00:04:23.500
So guys now what is our inventory file
location?

00:04:25.399
00:04:27.899
So in the current location, you can
provide complete path

00:04:28.000
00:04:29.600
or in the current location,

00:04:29.700
00:04:33.900
We have - that means in the current
location where your ansible.cfg file

00:04:33.900
00:04:37.100
is there, there we have coast file. That
file.

00:04:37.100
00:04:43.300
I am using as a inventory file. Right.
That's it.

00:04:43.400
00:04:44.200
Anyway by default

00:04:44.200
00:04:46.600
you have something here, as of now I
want to nullify that

00:04:46.800
00:04:49.800
So I don't want to keep anything in
that - we'll discuss step by step.

00:04:49.800
00:04:53.800
Right now we don't have any content
into this. That's fine.

00:04:53.800
00:04:57.700
Now. Let me explain about your host
key checking.

00:04:57.700
00:05:01.600
Let me take first of all any one of the
server and I am going

00:05:01.600
00:05:03.500
to connect with the server.

00:05:05.300
00:05:10.300
And you let me take public IP. So this
is my public IP.

00:05:10.300
00:05:13.900
So guys remember that we are from - I
mean our manage servers
00:05:13.900
00:05:15.000
or from cloud.

00:05:15.400
00:05:18.400
That's why whenever if you stop and
start your servers, right

00:05:18.400
00:05:20.000
your public IP will change.

00:05:20.500
00:05:24.700
So while practicing don't forget to
modify your public IPs

00:05:24.700
00:05:27.200
whenever if you restart your server, I
mean whenever if

00:05:27.200
00:05:30.400
you start and stop your server. It just
cross-checks.

00:05:30.900
00:05:33.200
So just assume that we are doing very
first time just judging

00:05:33.200
00:05:38.100
finality. I done in our previous classes
that SSH keys exchange, right?

00:05:38.100
00:05:41.000
Anyway, I restarted that's why my
server IP has been changed.

00:05:41.100
00:05:45.900
That's why whenever if I try to connect
with your remote server,

00:05:45.900
00:05:53.600
see it is going to ask yes or no, right?
This I should

00:05:53.600
00:05:57.000
not - I mean here I don't want to
provide yes by default.

00:05:57.000
00:05:58.500
Anyway, we have to work with remote
servers.

00:05:58.500
00:05:59.900
Why should we provide always
manually?

00:05:59.900
00:06:04.700
Yes, so I want to avoid this. So
actually you are running
00:06:04.700
00:06:06.300
from message it is asking yes.

00:06:06.900
00:06:09.600
So let me do one thing in inventory
file.

00:06:09.800
00:06:14.000
I am providing my IP my public IP or
my managed node IP.

00:06:14.300
00:06:19.600
Now, we know only as of now one
single command 'ansible all - m ping'.

00:06:19.600
00:06:22.400
Firstlet me verify this and see that

00:06:23.800
00:06:27.000
it is going to ask yes or no
confirmation. Because it is going

00:06:27.000
00:06:29.400
to work with your remote server, but
very first time

00:06:29.400
00:06:31.800
that's what he's asking. But I don't
want to provide this

00:06:31.800
00:06:36.500
yes or no, right? So why it is asking is
basically your ansible

00:06:36.500
00:06:39.400
is he's going to use at back and your
SSH only .

00:06:39.400
00:06:43.300
That's why that is the property of your
SSH. Now we need to disable it.

00:06:43.300
00:06:47.000
But here we are working with ansible.
Now in ansible

00:06:47.000
00:06:50.100
we have different ways to disable your
host key checking.

00:06:51.100
00:06:53.100
But here we are going to discuss only
two ways, later.

00:06:53.100
00:06:54.600
we'll discuss about one more way.
00:06:55.400
00:06:58.600
So very first thing is on your command
line just for temporary

00:06:58.600
00:07:00.300
purpose, right?

00:07:00.300
00:07:03.500
You can 'export
ANSIBLE_HOST_KEY_CHECKING = False'.

00:07:05.300
00:07:09.800
That is one way. Second ways in your
ansible.cfg file

00:07:10.300
00:07:13.100
you can write 'host_key_checking =
False.

00:07:14.100
00:07:17.500
So first thing is guys make sure that
this is a environment

00:07:17.500
00:07:21.700
variable for your ansible. In case if you
set this value then

00:07:21.700
00:07:23.600
your ansible own check.

00:07:24.800
00:07:27.600
You're host key checking verification
by default,

00:07:27.600
00:07:30.300
it will try to connect with your remote
servers without asking

00:07:30.300
00:07:31.700
yes or no confirmation.

00:07:33.000
00:07:35.500
But this is just for temporary purpose.

00:07:35.500
00:07:38.100
Suppose once if you close your
terminal and open then this

00:07:38.100
00:07:39.200
variable gone.

00:07:40.400
00:07:43.200
That's why just for permanent
purpose, permanently,

00:07:43.200
00:07:47.200
if you want to disable your host key
checking, right? Just observe
00:07:47.200
00:07:49.600
'ansible.cfg' configuration file.

00:07:49.800
00:07:51.900
We know what is the purpose of
configuration file.

00:07:52.000
00:07:55.100
So whatever the configuration
information you need if you

00:07:55.100
00:07:58.800
want to set for your ansible everything
you can set in your

00:07:58.800
00:08:01.800
ansible.cfg. Sometimes some
information

00:08:01.800
00:08:05.200
you can also set in your inventory file
as well.

00:08:05.800
00:08:08.600
But as of now, I am not setting, I will
go with step-by-step.

00:08:09.100
00:08:09.100
Right now just let me search in this do
we have by

00:08:14.400
00:08:16.000
default somewhere this host key
checking.

00:08:19.300
00:08:22.500
See that? There is a host key
checking commented.

00:08:23.500
00:08:25.200
'host_key checking = False'.

00:08:25.900
00:08:28.700
So this line I am going to enable so
that you are going to

00:08:28.700
00:08:34.600
disable verifying host key checking.
That's it. Very simple.

00:08:34.600
00:08:38.400
Now, let me search about this.
Somewhere we have this here. Now

00:08:38.400
00:08:44.299
let me enable. Now I enabled host key
checking. You can verify it now.
00:08:44.299
00:08:51.400
Now it is enabled, right? Now if you
run your 'ansible all - m ping' command.

00:08:51.400
00:08:54.500
Now it won't ask yes or no
confirmation.

00:08:54.799
00:08:57.100
Without asking that yes or no
confirmation

00:08:57.100
00:08:59.300
it is going to connect with your remote
server.

00:08:59.400
00:09:02.000
Anyway, as of now we are doing
simple task that is checking

00:09:02.000
00:09:03.600
connectivity with your remote server.

00:09:03.900
00:09:04.700
Yes. It is working and we are getting
response as 'pong', right?

00:09:09.700
00:09:12.900
So guys you might observe here
whenever if I try

00:09:12.900
00:09:16.200
to run this command it is taking some
time to communicate

00:09:16.200
00:09:20.200
with your remote or managed nodes.
Because they see ansible

00:09:20.200
00:09:24.100
engine is on my VM Ware, your
servers are in Cloud AWS cloud

00:09:24.100
00:09:24.700
different network.

00:09:24.700
00:09:25.900
So it is taking some time, right?

00:09:29.400
00:09:31.900
But anyway in real time, you will have
your servers in your

00:09:31.900
00:09:36.300
own network, so it won't take much
time. So I can also create
00:09:36.300
00:09:40.000
my ansible engine on any one of you
AWS or your require -

00:09:40.300
00:09:42.400
I mean, whatever the cloud you are
using for your manage

00:09:42.400
00:09:44.900
servers. They only take one more
extra server and try

00:09:44.900
00:09:47.600
to install your ansible, right?

00:09:48.100
00:09:53.300
So but I need to maintain consistency
about this files and

00:09:53.300
00:09:53.900
all those things,

00:09:53.900
00:09:56.100
so I don't want to use cloud for my
ansible engine.

00:09:56.300
00:09:58.700
That's why I'm taking this. And while
going forward I will

00:09:58.700
00:10:02.600
show you one editor which is useful to
learn your playbooks

00:10:02.600
00:10:04.900
to write your playbooks, right?

00:10:04.900
00:10:07.700
So if I have a GUI access it is very
easy to use the data,

00:10:07.700
00:10:09.500
that's why I am selecting my VMware.

00:10:10.100
00:10:14.200
That's fine. So guys now I am running,
right?

00:10:14.200
00:10:15.700
Yeah. while we checked this right?

00:10:15.700
00:10:17.300
So without asking yes or no
confirmation,

00:10:17.500
00:10:19.500
it is going to work with your remote
nodes.
00:10:20.200
00:10:23.200
So we disabled it. What we disabled?
Host key checking.

00:10:23.200
00:10:24.700
It is very very important guys.

00:10:26.300
00:10:29.800
So people will forget about this point
and

00:10:29.800
00:10:32.600
they will try to connect with your
remote servers by running

00:10:32.600
00:10:37.300
your 'ansible all - m ping', whatever it
may be. Any playbook or

00:10:37.300
00:10:38.400
ping command or whatever.

00:10:38.400
00:10:40.400
It may be module or Playbook.

00:10:41.300
00:10:43.700
So sometimes they will get an error
and they can't understand

00:10:43.700
00:10:47.700
that. So that's why before going to
work with your remote

00:10:47.700
00:10:54.900
servers, first of all make this host key
checking as false, right?

00:10:54.900
00:10:58.000
Fine, and one more thing you are
getting some warning.

00:10:58.300
00:11:00.900
You can also disable this warning
message from your configuration

00:11:00.900
00:11:04.500
file, but initially, right you are at
practice level don't

00:11:04.500
00:11:05.600
disable this warning.

00:11:05.900
00:11:08.400
We have some different types of
warnings.
00:11:08.400
00:11:11.100
You can enable that so that your
message -

00:11:11.300
00:11:15.400
warning message won't display. But,
you are at starting stage

00:11:15.400
00:11:18.300
if you don't display this one, and you
can't understand sometimes

00:11:19.000
00:11:21.400
So, but anyway, you don't have any
problem by giving warning

00:11:21.400
00:11:23.200
message. That is just a warning
message.

00:11:23.300
00:11:25.300
Just observe that once, that's it.

00:11:25.700
00:11:33.100
Anyway, you don't have any problem
with that, right? Fine. And one more thing guys.

00:11:33.100
00:11:37.600
Because I am using suppose my
servers from AWS Cloud.

00:11:38.000
00:11:42.500
So whenever I start and stop my public
IP will change, right?

00:11:42.500
00:11:46.400
So that's why please please try to
verify your

00:11:47.700
00:11:51.300
inventory file before going to work with
your ansible, whether

00:11:51.300
00:11:54.200
this is your public IP or not for your
corresponding node

00:11:54.200
00:11:56.800
or not, right?

00:11:57.100
00:11:57.500
That's it. Okay guys. Thank you for
watching this.
Transcript
00:00:00.000
00:00:02.300
Hi friends, here.

00:00:02.300
00:00:05.400
We are going to discuss about
inventory file with groups

00:00:05.400
00:00:08.100
and group of groups friends already.

00:00:08.100
00:00:10.100
We know that simply what is inventory
file.

00:00:10.600
00:00:11.800
So what is the inventory file?

00:00:13.100
00:00:15.800
So the answer will inventory file is a
file which consists

00:00:15.800
00:00:19.400
of the list of hosts or managed nodes.

00:00:19.800
00:00:23.800
I mean simply we are mentioning in
this file the IP addresses
00:00:23.800
00:00:27.300
or fqdn names of your remote servers
or manage servers so

00:00:27.300
00:00:30.700
that your hands will work with that
servers, right?

00:00:31.000
00:00:34.200
So let me show you that suppose and
one more thing guys.

00:00:34.200
00:00:36.300
We are at very initial step.

00:00:36.300
00:00:37.800
That's why I want to repeat this.

00:00:38.700
00:00:42.200
Suppose we have root TTC and
Isabel.

00:00:44.100
00:00:46.500
This is the default home location for
your ansible.

00:00:47.200
00:00:47.600
Right?

00:00:47.900
00:00:51.300
But in real time most of the cases we
are not going to use

00:00:51.300
00:00:54.300
this default location because if two
three people are working

00:00:54.600
00:00:56.900
then they will get confused with their
hosts.

00:00:56.900
00:01:00.100
That's why they're going to create their
own in inventory

00:01:00.100
00:01:02.900
their own configuration file details, or
they're going to

00:01:02.900
00:01:05.400
create their own ansible home
directory.

00:01:05.700
00:01:08.500
You can create anywhere suppose
here we created.
00:01:09.700
00:01:13.900
Two directories to ansible home
directories one is for Pradhan

00:01:13.900
00:01:17.500
on prod so I am going to work with
suppose ansible prod nothing.

00:01:17.500
00:01:20.400
Is there just to move to that and what
we have what we did

00:01:20.500
00:01:23.800
already we did in in the last class
simply we copied from

00:01:23.800
00:01:24.800
your default route.

00:01:24.800
00:01:29.700
It is a ansible this ansible dot c f g and
host files right

00:01:29.800
00:01:34.000
now, you know in ansible dot CFG file
we have configuration

00:01:34.000
00:01:38.000
settings to work your ansible with your
nodes right?

00:01:38.000
00:01:42.000
Let me tell you one of the English
inventory location with

00:01:42.000
00:01:45.200
what inventory file your answer will
has to work that information.

00:01:45.200
00:01:48.400
We are mentioning in this file If You
observe here inventory

00:01:48.400
00:01:51.500
dot in the current location, whatever
the first name is there

00:01:51.700
00:01:54.700
that is the inventory file in this
configuration file that

00:01:54.700
00:01:55.500
means from here.

00:01:55.500
00:01:58.000
If you are only from this location guys
be clear.
00:01:58.700
00:02:01.700
So from this location whenever if you
run any ansible command

00:02:01.700
00:02:05.100
or Playbook that is going to consider
invent, I mean the

00:02:05.100
00:02:07.100
list of hosts from this file.

00:02:08.800
00:02:09.400
That's fine.

00:02:09.699
00:02:12.699
And anyway, as of now, I remove
entire servers in this file.

00:02:12.699
00:02:13.500
I don't have anything.

00:02:13.900
00:02:14.900
Let me update.

00:02:18.500
00:02:23.400
So to update first of all, let me show
you my notes.

00:02:23.400
00:02:24.700
These three are the nodes.

00:02:25.100
00:02:27.100
So, you know, you have public I be
here.

00:02:27.100
00:02:30.500
I am taking that public IP why I am
taking only public IP.

00:02:30.500
00:02:35.200
Why can't we go with private IP means
in case if my ansible

00:02:35.200
00:02:38.800
engine is also from AWS cloud and
they are in the same network

00:02:38.800
00:02:41.600
suppose. Then I can take my private
IP.

00:02:41.800
00:02:45.700
But as of now, my ansible engine is
from my VMware.

00:02:46.000
00:02:50.700
That's why we are at outside of your
Cloud so outside by
00:02:50.700
00:02:54.700
IP address public IP can accessible
that's why I'm taking

00:02:54.700
00:02:57.300
this public IP right likewise.

00:02:57.300
00:02:59.200
I copied all the public eye piece to
here.

00:03:00.400
00:03:04.400
Let me copy this and let me enter into
here and let me show

00:03:04.400
00:03:07.900
you a copy this all files right now.

00:03:07.900
00:03:11.700
What I am doing is for simply I am
running just ping command.

00:03:11.800
00:03:14.800
Don't worry about this entire syntax
will discuss in detail

00:03:14.800
00:03:18.900
about this ansible at our Command
format or Syntax for time

00:03:18.900
00:03:20.300
being. Just remember simply ansible.

00:03:20.300
00:03:20.800
All iPhone.

00:03:20.800
00:03:25.100
Yumping is going to Ping or check the
connectivity your manager

00:03:25.100
00:03:28.000
notes from your ansible engine.

00:03:29.300
00:03:32.600
So I'm running that so anyway,
anyway, it will take some

00:03:32.600
00:03:35.900
time because your server and civil
engineers from outside

00:03:35.900
00:03:37.400
of your AWS Network.

00:03:37.800
00:03:40.700
That's what is going to take some time
to connect with your
00:03:40.700
00:03:41.500
remote nodes.

00:03:41.900
00:03:46.700
Anyway, now your remote nodes are
able to reach for your

00:03:46.700
00:03:47.600
ansible engine.

00:03:47.600
00:03:50.300
So you're getting responses pong
means that is the reason

00:03:50.800
00:03:54.100
I mean you are able to reach your
managed nodes are able

00:03:54.100
00:03:56.800
to reach forever and civilian.

00:03:56.800
00:03:57.400
That's fine.

00:03:59.200
00:04:01.200
Now guys actually have three servers
here, right?

00:04:01.300
00:04:04.100
I want to work with only one server
then just to mention

00:04:04.100
00:04:07.800
that server see whatever it may be
ping or something else,

00:04:07.800
00:04:12.000
whatever it may be right, so I want to
work with only one

00:04:12.000
00:04:13.600
server among these three servers.

00:04:15.000
00:04:15.400
That's it.

00:04:16.899
00:04:19.399
In this way, you just you have to
mention only ever I be

00:04:19.399
00:04:23.000
here. I mean the server for which you
need to work with your

00:04:23.000
00:04:24.100
ansible that server IP.
00:04:24.100
00:04:27.200
You need to mention here instead of
you are remaining all

00:04:27.200
00:04:28.700
servers now.

00:04:28.700
00:04:30.800
I want to work with suppose some to
servers.

00:04:32.000
00:04:35.600
And before that guys if this IP is there
in this inventory

00:04:35.600
00:04:37.600
file then only or ansible will work.

00:04:38.100
00:04:39.100
Let me do one thing.

00:04:39.500
00:04:40.800
It's very very important.

00:04:42.300
00:04:42.700
Suppose.

00:04:42.700
00:04:45.600
What I am doing is I am going to
remove your first IP or

00:04:45.600
00:04:46.800
last type whatever it may be.

00:04:47.700
00:04:48.800
I remove that right now.

00:04:48.800
00:04:50.500
Let me save it now.

00:04:50.500
00:04:54.700
I am trying to communicate with your
remote IP using your

00:04:54.700
00:04:58.600
ansible. See what you're going to get.

00:05:00.900
00:05:04.200
No match supplied host pattern that I
pee first.

00:05:04.200
00:05:06.500
It should be there in your inventory file
then only your

00:05:06.500
00:05:10.500
answer will communicate or will work
with your that remote
00:05:10.500
00:05:11.700
or manage node.

00:05:12.200
00:05:18.200
Now, I see that now I copied I
replaced now if I run ping

00:05:18.200
00:05:20.800
command now your hands will work
with that server.

00:05:22.500
00:05:22.800
Right.

00:05:22.800
00:05:24.300
This is very very important point.

00:05:24.700
00:05:28.200
If we how in the inventory file then
only your answer will

00:05:28.200
00:05:32.600
work with that server that fine right
now.

00:05:32.600
00:05:33.900
You are getting your response.

00:05:35.100
00:05:38.100
So guys suppose I don't want to work
with all suppose if

00:05:38.100
00:05:40.800
I want to work with all then I am
mentioning simply are Hall.

00:05:41.300
00:05:47.000
Sorry all But I want to work with only
two servers then what

00:05:47.000
00:05:49.300
you have to do is you need to mention
your first server:

00:05:49.300
00:05:51.400
whatever the server you want to work
with.

00:05:52.400
00:05:54.200
That server IP:

00:05:54.500
00:05:56.500
in case you have some more servers
you need to mention.

00:05:56.500
00:05:59.500
So if you mention this way now, your
answer will is going
00:05:59.500
00:06:03.500
to check the connectivity for these two
servers make sure

00:06:03.500
00:06:05.500
that these two servers are already
there in your inventory.

00:06:05.500
00:06:08.400
That's why your uncle is going to work
with these two servers.

00:06:08.800
00:06:10.000
That's fine.

00:06:10.200
00:06:11.200
Now.

00:06:11.200
00:06:15.800
I assume that in your hand or you are
going to manage hundred

00:06:15.800
00:06:17.600
servers with the help of your ansible.

00:06:17.600
00:06:21.800
That means your inventory file
consists of hundreds are words.

00:06:23.100
00:06:25.700
if you want to work with at a time all
server simply you

00:06:25.700
00:06:28.900
have a simple command but simply
you can mention here all

00:06:30.300
00:06:33.600
but I want among a hundred servers I
want to work with only

00:06:33.600
00:06:37.300
50 servers first of all I need to mention
all my Hundred

00:06:37.300
00:06:40.800
servers in my inventory but I want to
work with only 50 servers

00:06:40.800
00:06:43.700
than what I have to do whatever the
50 servers you want to

00:06:43.700
00:06:48.400
work then that server one server to
server 3 likewise I need
00:06:48.400
00:06:52.100
to mention my 50 server's IP s that is
not a good practice

00:06:52.100
00:06:54.400
of course there is correct but initially
are going to waste

00:06:54.400
00:06:59.400
your time In that case we have an
alternate way.

00:06:59.900
00:07:02.800
What is that is simply open your
inventory file?

00:07:04.300
00:07:08.500
Right now see that suppose assume.

00:07:09.500
00:07:10.900
Anyway, we have only three servers
right?

00:07:10.900
00:07:13.800
That's why what I am doing is I am
going to take my local

00:07:13.800
00:07:16.800
server. Also, one of the manager
node, you can take it.

00:07:17.100
00:07:20.500
So before going to take what you have
to do is I already

00:07:20.500
00:07:21.300
exchanged my keys.

00:07:21.300
00:07:22.600
Let me remove this.

00:07:24.800
00:07:28.900
Non-host sorry authorized keys so that
you can understand.

00:07:32.000
00:07:34.800
So suppose what I am doing is
ansible.

00:07:37.400
00:07:39.900
Let me do one thing SSH.

00:07:41.600
00:07:44.500
Local Host I want to connect with my
Local Host.

00:07:44.900
00:07:46.100
So it is going to ask password.
00:07:46.100
00:07:48.200
That means you did not exchange
your keys.

00:07:48.700
00:07:52.400
So guys if you want to work using your
ansible engine with

00:07:52.400
00:07:53.800
your localhost as well.

00:07:53.900
00:07:57.900
I mean if you want to consider your
localhost also, one of

00:07:57.900
00:08:01.700
the manager node then unitech saying
you are public key with

00:08:01.700
00:08:06.200
your localhost as well the way how we
exchanged our key public

00:08:06.200
00:08:07.800
key with your managed node same
way.

00:08:07.800
00:08:10.000
You need to exchange with your
localhost as well.

00:08:10.900
00:08:11.600
Now let me do that.

00:08:11.700
00:08:15.900
SSH already generated keys right with
the Local Host.

00:08:17.800
00:08:19.300
Now it is going to ask password.

00:08:19.500
00:08:21.700
Let me provide password because
very first time you're going

00:08:21.700
00:08:22.500
to connect.

00:08:23.800
00:08:24.100
Right.

00:08:24.300
00:08:27.900
Now if I do SSH localhost now it is
going it is not going

00:08:27.900
00:08:30.000
to ask password that it is going to
connect with your Local
00:08:30.000
00:08:32.500
Host. That's it fine.

00:08:33.000
00:08:36.500
So guys now we exchanged our keys
with the localhost as well.

00:08:36.600
00:08:39.700
Now you can consider your localhost
also one of the manager

00:08:39.700
00:08:44.200
node. So now what I am doing is just
for our practice purpose

00:08:44.200
00:08:45.299
I exchange this.

00:08:47.000
00:08:52.000
non-pro ride so you can mention you
can mention your IP or

00:08:52.000
00:08:53.100
simply localhost.

00:08:54.700
00:08:55.200
Right.

00:08:55.400
00:08:58.400
So practice localhost practices the
best one just simply

00:08:58.400
00:09:04.200
I'm taking localhost now guys, our
concept is in case if

00:09:04.200
00:09:07.500
we have a hundred servers in your
inventory, but you want

00:09:07.500
00:09:11.500
to work with only 50 servers then one
way is you can mention

00:09:11.500
00:09:18.200
in this way like ansible instead of all
server 1:

00:09:18.200
00:09:19.200
server to:

00:09:19.200
00:09:20.100
server 3:

00:09:20.100
00:09:22.200
server for likewise, but that is not a
good practice.
00:09:22.200
00:09:26.500
That's why what we are doing is What
about the 50 servers

00:09:26.500
00:09:27.900
you want to work with ansible?

00:09:29.600
00:09:29.900
Nothing.

00:09:29.900
00:09:33.300
Is there a hundred zeros I want to
clang divided into two

00:09:33.300
00:09:35.200
groups. Yes, you can group it.

00:09:35.200
00:09:39.500
Let's say simply group one assume
that in group one first

00:09:39.500
00:09:42.500
two servers or for some 50 servers as
of now.

00:09:42.500
00:09:44.600
We have only two servers discharged
in that 50 servers are

00:09:44.600
00:09:47.800
there then let me take group to that's
it.

00:09:50.200
00:09:53.800
Now see that ansible all sorry not all
means you are going

00:09:53.800
00:09:55.000
to work with all servers.

00:09:55.500
00:09:56.300
I will explain that.

00:09:56.900
00:10:00.300
So now I want to work with last 50
servers assume that these

00:10:00.300
00:10:02.900
are the 50 servers are I want to work
with first 50 servers

00:10:03.800
00:10:06.000
whatever the 50 servers you want to
work in that case.

00:10:06.000
00:10:08.400
What you have to do is simply ansible.
00:10:09.600
00:10:13.300
Instead of all or instead of single
server name you can write

00:10:14.100
00:10:15.000
group one.

00:10:15.400
00:10:19.400
I want to work with Group 1 ansible
Group 1 servers.

00:10:19.700
00:10:23.000
Just I want to check the connectivity -
M Bing is going to

00:10:23.000
00:10:24.900
check the connectivity with your group
one.

00:10:27.200
00:10:30.500
Right now see that you are going to
get the connectivity

00:10:30.500
00:10:32.100
with your group 1 servers.

00:10:32.300
00:10:34.400
So we have two servers in group one
right now.

00:10:34.400
00:10:37.300
We are Ansel is going to check the
connectivity first two

00:10:37.300
00:10:39.400
servers. I mean Group 1 servers,
that's it.

00:10:40.400
00:10:43.400
But instead of to assume that there
are 50 servers now, let

00:10:43.400
00:10:45.000
me walk with the second group.

00:10:45.000
00:10:47.000
Yes, you can work with second group
as well.

00:10:53.300
00:10:53.800
Right.

00:10:54.400
00:10:57.400
Now you're going to get the response
from your remaining

00:10:57.400
00:10:57.800
to serve.
00:10:57.800
00:11:00.300
I mean from grouped with whatever
the server's you're there

00:11:00.500
00:11:02.900
for the server's now your hands will is
going to work.

00:11:03.400
00:11:04.700
Yes, you are getting response.

00:11:05.300
00:11:08.700
So guys now it is somewhat Simplicity
instead of mentioning

00:11:08.700
00:11:10.500
50 servers on your command line.

00:11:10.700
00:11:14.100
What we did is in our inventory we
group them.

00:11:15.200
00:11:18.800
50 servers one group 50 servers one
group not only like that.

00:11:19.200
00:11:20.700
Just assume that in your real time.

00:11:20.700
00:11:24.200
You have something like some web
servers some database servers

00:11:24.500
00:11:28.000
and some middleware server
something like that, right?

00:11:28.000
00:11:30.400
That's what I am doing is instead of
group one group two

00:11:30.400
00:11:34.900
likewise. What I am doing is let me do
one thing web servers.

00:11:36.500
00:11:37.600
Are you not in web servers?

00:11:37.600
00:11:40.800
You have some 30 servers as of now,
you're simply localhost

00:11:40.800
00:11:44.100
about assume that there are 30
servers in web servers.
00:11:44.700
00:11:51.600
Let me take DB or kill maybe in DB
how Oracle or some MySQL

00:11:52.100
00:11:53.900
so I'm going to take in this way DB.

00:11:54.500
00:11:58.300
Let's say my SQL assume that in each
group.

00:11:58.300
00:12:00.200
We have some 30 40 50 servers.

00:12:00.700
00:12:03.200
But as of now I am taking only one
server there is no difference.

00:12:04.200
00:12:08.400
Now, let's say some middleware in
that suppose weblogic or

00:12:08.400
00:12:13.100
Tomcat. likewise No guys.

00:12:14.300
00:12:16.800
I have some suppose hundreds are
worse.

00:12:17.500
00:12:20.000
So 25 or 20 servers are web servers.

00:12:20.100
00:12:22.800
So I meant I will mention all 20 service
under this group

00:12:22.800
00:12:26.600
name. So while mentioning your group
name you have to write

00:12:26.600
00:12:29.300
square brackets open and close
square brackets inside that

00:12:29.300
00:12:32.200
you need to mention your group name
without any spaces.

00:12:34.400
00:12:39.400
Now assume that there are some 10
or 20 web servers some

00:12:39.600
00:12:44.000
15 DB or kill servers some 20 DB
MySQL servers.
00:12:44.400
00:12:50.300
Some Tomcats are worth some 10
servers likewise now in my

00:12:50.300
00:12:54.400
inventory i divided my servers based
on the purpose now suppose

00:12:54.400
00:12:57.300
sometimes I want to work with only
web servers.

00:12:59.800
00:13:04.100
But I will do simply ansible web server
- em ping.

00:13:04.400
00:13:06.300
But as of now I am taking always pin
guys.

00:13:06.300
00:13:10.000
You have a lot of modules to work with
your managed nodes

00:13:10.300
00:13:12.100
we go with them step by step.

00:13:12.400
00:13:16.000
But let me take simply first ping
command only see now I

00:13:16.000
00:13:19.600
am able to work with my all web
servers so under web servers,

00:13:19.600
00:13:22.000
what are the server's you are having
assumed that some 50

00:13:22.000
00:13:25.300
servers are there are some 30 zeros
are there all the tea

00:13:25.300
00:13:28.600
servers you're going to get response
for all those 30 servers

00:13:29.000
00:13:35.600
now I work with suppose DB under
DB.

00:13:35.600
00:13:37.100
I want to work with mySQL.

00:13:38.300
00:13:41.100
Assume that you have some 10
MySQL servers, no need to mention
00:13:41.100
00:13:45.300
10 servers with colons now already we
group them and server-side

00:13:45.300
00:13:45.900
group to them.

00:13:48.300
00:13:48.700
Right.

00:13:48.800
00:13:52.200
Now we are going to get response for
your MySQL servers.

00:13:52.600
00:13:52.800
Now.

00:13:52.800
00:13:58.000
I want to walk with DB servers in the
DB servers MySQL as

00:13:58.000
00:14:03.400
well as or kill then DB my SQL DB or
kill that's it.

00:14:05.200
00:14:08.800
Now you're going to get your output
forever.

00:14:08.800
00:14:12.500
I mean the Ping response for your
SQL servers and then Oracle

00:14:12.500
00:14:13.900
Sorrows. That's it.

00:14:17.900
00:14:20.700
Right what we mentioned.

00:14:22.400
00:14:25.200
Yeah, fine this one right DB
anarchical.

00:14:25.200
00:14:28.700
We have two one one server one-on-
one under or kill and one

00:14:28.700
00:14:30.900
under SQL MySQL.

00:14:31.400
00:14:32.100
That's fine.

00:14:32.700
00:14:36.300
But see this is one way whatever the
way we provide here.

00:14:36.300
00:14:37.100
That is one way.
00:14:38.000
00:14:39.600
So what we are doing is here.

00:14:39.600
00:14:43.600
We are clubbing DB MySQL servers
and DB or kills our words.

00:14:43.900
00:14:48.600
This is one way and what about the
process we follow up to

00:14:48.600
00:14:51.900
now that is called simply inventory file
with some groups.

00:14:52.200
00:14:53.400
So all our individual groups.

00:14:55.700
00:15:01.400
Right and one more thing I suppose I
want to work with only

00:15:01.400
00:15:03.300
Local Host may be local.

00:15:03.600
00:15:03.900
See now.

00:15:03.900
00:15:05.000
I am not giving group.

00:15:05.000
00:15:07.700
I am giving individual server name If
You observe here.

00:15:09.000
00:15:09.300
Right.

00:15:09.300
00:15:10.600
Let me do one thing first.

00:15:10.600
00:15:11.700
I want to work with all.

00:15:12.800
00:15:16.900
Even though if you have your servers
under different groups,

00:15:17.400
00:15:22.300
there is a default group called all all
means commonly the

00:15:22.400
00:15:23.400
intersection part.

00:15:23.500
00:15:27.600
I mean servers all servers which are
there in your all groups
00:15:28.100
00:15:30.200
in case if server is repeating into three
groups.

00:15:30.200
00:15:34.400
It is going to consider as only one
server ansible all -

00:15:34.400
00:15:35.000
mmm ping.

00:15:37.000
00:15:40.100
Be clear all means all the servers
which are there in your

00:15:40.100
00:15:43.000
inventory. Now your hands will is
going to check with your

00:15:43.000
00:15:43.900
all servers.

00:15:44.300
00:15:48.300
I mean the Ping module response it is
going to get a response

00:15:48.300
00:15:49.000
for your ping mod.

00:15:49.000
00:15:52.000
Yes, you are getting right.

00:15:52.600
00:15:57.500
So Guys, these are the group names
which we provided by default.

00:15:57.500
00:16:00.300
There is a group called all all means
all the servers from

00:16:00.300
00:16:05.800
all groups, but now even though if you
have groups and Group

00:16:05.800
00:16:07.800
all I don't want to work with any group.

00:16:08.000
00:16:10.400
I want to work with single individual
server.

00:16:10.400
00:16:12.400
Let's say localhost now.

00:16:12.400
00:16:13.200
Let me run it.
00:16:14.800
00:16:16.600
See the response what you are getting
here.

00:16:18.400
00:16:20.100
Right now, let me do one more thing.

00:16:22.100
00:16:24.800
I want to work with one of the server
called this one.

00:16:32.100
00:16:32.400
Right.

00:16:32.500
00:16:36.500
Just check it whether you're able to
work with your remote

00:16:36.900
00:16:39.000
nodes are managed nodes, right?

00:16:39.000
00:16:40.100
Yes, you can work it.

00:16:40.900
00:16:43.600
So if your servers are there in any one
of the group, then

00:16:43.600
00:16:47.100
you can able to communicate with that
groups in sorry with

00:16:47.100
00:16:50.500
that serve a particular server by taking
that that's fine

00:16:51.500
00:16:53.800
now one more thing.

00:16:55.300
00:16:59.100
yeah, actually we work with this, right
so guys up to now

00:16:59.800
00:17:05.598
we know groups only groups in Udell
groups we have so sometimes

00:17:05.598
00:17:07.200
you want to work with two groups.

00:17:08.598
00:17:10.900
This group and this group, right?

00:17:11.000
00:17:14.900
So at the time what we can do and
symbol your DB or kill
00:17:14.900
00:17:22.200
group. And then DB MySQL group,
then you are task whatever

00:17:22.200
00:17:23.800
the task you are going to take that.

00:17:25.500
00:17:27.500
Now it is going to work with your two
groups.

00:17:27.598
00:17:28.700
Whatever the servers are there.

00:17:29.599
00:17:31.599
How many number of servers you are
having in your group?

00:17:31.599
00:17:32.300
No problem.

00:17:32.599
00:17:34.599
It is going to work with these two
groups.

00:17:35.500
00:17:36.300
That's fine.

00:17:36.700
00:17:40.599
But instead of mentioning your two
groups in this way.

00:17:41.000
00:17:44.800
I can Club these two groups and I can
create a new group

00:17:44.800
00:17:46.000
in my my inventory.

00:17:47.800
00:17:50.500
So guys what I am saying is suppose I
assume that in your

00:17:50.500
00:17:54.700
DVR kill some 30 servers are there
and in DB MySQL some 40

00:17:54.700
00:17:59.900
servers are there suppose if I want to
take simply DB irrespective

00:17:59.900
00:18:02.700
of your which type of DB I don't want
to consider that simply.

00:18:02.700
00:18:05.200
I want to consider as a DB servers
then what I have to do,
00:18:05.600
00:18:08.900
whatever the 30 servers are there
here that third those 30

00:18:08.900
00:18:12.100
servers. I need to mention here and
then the 40 servers from

00:18:12.100
00:18:14.000
your MySQL also need to mention
here.

00:18:14.700
00:18:17.100
Unnecessarily, I am going to waste my
time, right because

00:18:17.100
00:18:19.300
I need to copy 30 plus 40 70 servers.

00:18:19.600
00:18:20.500
Why should I copy?

00:18:20.700
00:18:25.200
I have a some alternate way whenever
if you want to Club

00:18:25.200
00:18:28.800
the servers which are there in different
groups you can club

00:18:28.800
00:18:32.300
and you can create a new group with
the syntax first mention

00:18:32.500
00:18:37.200
your new group and under that just
write your first group.

00:18:38.700
00:18:39.600
Second group.

00:18:39.600
00:18:42.800
Maybe if you have some other groups
opposed DB postgres or

00:18:42.800
00:18:47.300
SQL, right you can do in this way, but
this is not a normal

00:18:47.300
00:18:49.200
group group of groups.

00:18:49.700
00:18:53.300
That means this groups or children for
this group.
00:18:53.500
00:18:56.700
Now what we have to do is along with
that group name you

00:18:56.700
00:18:57.600
need to write.

00:19:00.400
00:19:02.500
Children, that's it.

00:19:03.700
00:19:09.400
Now guys concept is inventory with
groups this thing.

00:19:10.600
00:19:14.000
No inventory with groups and group of
groups.

00:19:14.100
00:19:17.600
So whenever if you want to Club
group of groups, yes, you

00:19:17.600
00:19:21.500
can club and you can create a new
group in this way your

00:19:21.500
00:19:25.100
group's new group name, and these
are the children's for

00:19:25.100
00:19:25.700
this group.

00:19:25.700
00:19:27.200
That's why you have to write here
children.

00:19:28.000
00:19:32.000
Now, let me do one thing last
execution command in this session.

00:19:32.700
00:19:36.200
That is simply DB - emping now.

00:19:36.200
00:19:38.900
I want to work with my DB or class.

00:19:38.900
00:19:39.700
Well as Debbie Meyer.

00:19:39.800
00:19:43.500
SQL but in my inventory, I created a
new group called DB

00:19:43.700
00:19:46.700
by considering these two groups as a
children for this grow.
00:19:46.900
00:19:47.400
That's it.

00:19:48.700
00:19:51.200
Now you're on school is going to work
with your all servers

00:19:51.200
00:19:53.700
which are there in this group and this
group.

00:19:54.400
00:19:59.000
So guys, this is the simply concept for
your ansible groups

00:19:59.100
00:20:00.700
and group of groups.

00:20:01.200
00:20:03.700
So guys, this concept is very very
important.

00:20:04.000
00:20:07.600
So while going forward for this
concept, I will add some

00:20:08.200
00:20:09.200
variables as well.

00:20:09.600
00:20:11.800
So if I go with that variables, you will
get confused.

00:20:11.800
00:20:13.000
I will go with step-by-step.

00:20:14.100
00:20:14.400
Okay?

00:20:14.600
00:20:15.100
Okay guys.

00:20:15.100
00:20:16.500
Thank you for watching this video.
Transcript
00:00:00.000
00:00:02.400
Friends here we are going to discuss

00:00:02.400
00:00:07.800
about different locations for ansible.cfg
file.

00:00:07.800
00:00:10.500
So already we know that what is
'ansible.cfg' file.

00:00:10.500
00:00:13.100
Simply it is a configuration file for your
ansible.

00:00:13.500
00:00:16.300
You can do some settings in your
'ansible.cfg' file.

00:00:16.500
00:00:19.800
Those settings are used by your
ansible while running your

00:00:19.800
00:00:21.700
ansible or commands or playbooks.

00:00:22.800
00:00:25.300
Fine. And we know one more thing.
00:00:25.600
00:00:28.400
What is the default location of your
'ansible.cfg' file?

00:00:30.800
00:00:36.500
Under root ETC, we have ansible and
in that we have 'ansible.cfg' file.

00:00:36.500
00:00:39.700
Let me open my ansible engine server
and let me show you that.

00:00:39.700
00:00:42.100
We know that already, but I want to
show you once again.

00:00:47.500
00:00:49.400
So in this we have 'ansible.cfg' file.

00:00:49.400
00:00:53.000
This is the default location of your
'ansible. cfg' file

00:00:53.800
00:00:57.000
and which has least priority while
running your playbooks

00:00:57.000
00:00:58.100
or commands.

00:00:58.500
00:00:59.700
So what is that least priority?

00:00:59.700
00:01:04.300
We will see in this, right? Fine, And we
know that in that

00:01:04.300
00:01:07.600
'ansible.cfg' file we can do different
settings. And already

00:01:07.600
00:01:11.700
we set up to now we have seen two
parameters right or two

00:01:11.900
00:01:16.100
values we set in your ansible.cfg file.
One is inventory file location

00:01:16.100
00:01:19.700
and one more is host key checking.
You can disable by enabling

00:01:19.700
00:01:22.500
this host key checking in your
'ansible.cfg' file.
00:01:23.100
00:01:29.000
So likewise we have different values
we can set in your ansible.cfg file.

00:01:29.000
00:01:30.200
But we'll discuss them

00:01:30.200
00:01:34.700
step-by-step, right? Fine. Now guys,
just observe here

00:01:35.900
00:01:39.200
I'm running simply 'ansible --version'
command.

00:01:39.500
00:01:43.000
You can also run your playbook. For
timing just in

00:01:43.000
00:01:46.500
case I am running 'ansible --version'
and see

00:01:46.500
00:01:51.500
that whenever if you run from this
location -your ansible

00:01:51.500
00:01:55.600
commands - your ansible is
considering config file as default

00:01:55.600
00:02:00.700
file. Now what I am doing is I am
entering into my practice directory

00:02:00.700
00:02:04.800
and there I am going to run my
'ansible --version' command.

00:02:04.800
00:02:08.000
Now, it is considering configuration file
as in the

00:02:08.000
00:02:10.199
current location, whatever you have it
is going to considering

00:02:10.199
00:02:16.000
that, right? Now, let me come back
and let me move into my

00:02:16.000
00:02:17.400
practice prod directory.

00:02:17.900
00:02:19.300
So anyway, I don't have anything here.
00:02:19.300
00:02:23.500
Now I am running 'ansible --version'.
So you don't have anything

00:02:23.500
00:02:24.300
in the current location.

00:02:24.300
00:02:27.000
If you don't have anything in the
current location now what

00:02:27.000
00:02:31.000
it is taking? The default ansible
configuration file.

00:02:32.600
00:02:38.700
That means you can mention your
config file 'ansible.cfg' file in different locations.

00:02:38.700
00:02:42.900
But while running your ansible it will
follow some priority

00:02:43.400
00:02:48.300
and based on that it will select
'ansible.cfg' file.

00:02:48.300
00:02:50.900
Now, what is that priority and what are
the different locations

00:02:50.900
00:02:53.500
for your 'ansible.cfg' file, right?

00:02:53.500
00:02:55.700
Let me show you them one by one.

00:02:56.900
00:03:00.300
And I'm going to display them based
on priority as well that

00:03:00.300
00:03:01.600
priorities from top to down.

00:03:02.200
00:03:07.000
So these are the different locations for
your 'ansible.cfg' file.

00:03:07.000
00:03:10.400
So just assume that this is one of the
environment variable

00:03:10.400
00:03:13.300
for your ansible on your Unix-like
systems.
00:03:13.300
00:03:17.400
You can export your configuration file
path using this environment

00:03:17.400
00:03:20.600
variable, right? Anyway in the current
location

00:03:20.600
00:03:23.000
also you can create or in the user
home.

00:03:23.000
00:03:27.700
Also, you can create with '.ansible.cfg'
file, right?

00:03:27.200
00:03:31.400
Then default location 'ansible.cfg' file.
In the user home.

00:03:31.400
00:03:35.700
you can also create 'ansible.cfg'
instead of dot but this

00:03:35.700
00:03:38.800
dot is just for priority. I will show you
that.

00:03:38.800
00:03:44.000
So now we have four places to look
for 'ansible.cfg' file

00:03:44.000
00:03:49.100
by your ansible while working with
your ansible, right?

00:03:49.100
00:03:54.500
So guys the priority is in case if you
don't have about three

00:03:54.900
00:03:58.300
locations in any one of these three
locations, if you don't

00:03:58.300
00:04:02.300
have 'ansible.cfg' file, then only your
ansible will try

00:04:02.300
00:04:05.000
to take settings from the sample.cfg
file.

00:04:06.500
00:04:08.900
Suppose you are running from some
location.
00:04:09.300
00:04:12.300
And in that location, if you have
ansible.cfg file,

00:04:12.300
00:04:13.500
then we'll take that only.

00:04:14.800
00:04:17.899
But before going to take this, it will try
to look for this

00:04:17.899
00:04:20.000
'ansible.cfg' enviroment variable.

00:04:20.399
00:04:23.100
If you set this, even though if you are
running from current

00:04:23.100
00:04:26.300
location, it will take configuration file
from this variable.

00:04:26.300
00:04:29.300
Because compared to this current
location always this is

00:04:29.300
00:04:33.200
the highest priority. That's it. Right?

00:04:33.200
00:04:37.700
Let me explain this with a simple
clarity.

00:04:37.700
00:04:42.500
Suppose in the current location. We
don't have anything.

00:04:42.500
00:04:44.200
That's why it is going to take default.

00:04:44.700
00:04:48.300
But before going to default or ansible,
we'll look first

00:04:48.300
00:04:51.800
of all, is there any enviroment variable
file exported

00:04:51.800
00:04:55.500
for the location of 'ansible.cfg' that is
ansible_config

00:04:55.500
00:04:57.800
If it is not there then we'll look in the
current
00:04:57.800
00:04:59.700
location. Anyway in the current
location

00:04:59.700
00:05:02.000
we don't have in the current location
suppose.

00:05:02.000
00:05:03.500
If you don't know how then we'll try to.

00:05:04.600
00:05:09.100
Go to here and we'll try to look for any
'.ansible.cfg' file

00:05:09.100
00:05:11.800
is there anyway we don't have? So we
don't have first three.

00:05:11.800
00:05:14.000
That's why it is taking default location.

00:05:14.600
00:05:18.600
Now what I am doing is I am going to
create in the home directory

00:05:18.600
00:05:23.800
of user with a '.ansible.cfg' file. Now,
let me move

00:05:23.800
00:05:27.400
into my prod. We don't know anything
here.

00:05:27.400
00:05:30.100
So previously whenever if you run
your command from here,

00:05:30.300
00:05:33.900
ansible commands, your ansible file is
taking configuration file as

00:05:33.900
00:05:37.700
default location. But before default
actually is going

00:05:37.700
00:05:43.200
to check for three other locations with
priority from ansible_config

00:05:43.200
00:05:47.800
file in the current location or under
user home. Right?

00:05:47.800
00:05:51.600
Just now we created some example
'ansible.cfg' file under
00:05:51.600
00:05:52.300
the user home.

00:05:53.000
00:05:53.200
Now I am running my 'ansible --
version 'command. Now it is

00:05:57.400
00:06:01.100
going to take this file previously if in
case if you don't

00:06:01.100
00:06:04.300
have anything it is going to take
default. Now before default,

00:06:04.300
00:06:05.700
this is the highest priority.

00:06:05.800
00:06:08.600
That's why your ansible is considering
that. Now let me do one

00:06:08.600
00:06:09.200
more thing.

00:06:09.400
00:06:11.900
I am going to create in the current
location 'ansible.cfg' file.

00:06:11.900
00:06:14.200
Now, I am running.

00:06:17.100
00:06:19.000
See now it is taking in the current
location, whatever the

00:06:19.000
00:06:22.000
configuration file you have. Right?

00:06:22.000
00:06:27.300
So before this it is having highest
priority on this file, right?

00:06:27.300
00:06:29.900
So before taking your default location,
it is going

00:06:29.900
00:06:33.800
to take this as the highest priority,
right?

00:06:33.800
00:06:36.000
And one more thing your
ansible_config file

00:06:36.000
00:06:39.700
you can export and you can I mean
that is the highest priority
00:06:39.700
00:06:42.500
or having compared to all these three,
right?

00:06:42.500
00:06:46.300
So guys based on this priority only
your ansible will take

00:06:46.300
00:06:49.400
'ansible.cfg' file while running your
ansible playbooks or commands.

00:06:52.600
00:06:59.000
Right? Fine. And one more thing.
Suppose just assumed that

00:06:59.000
00:07:01.500
in the current location you have your
'ansible.cfg' file

00:07:01.500
00:07:03.700
and in that you don't have any
settings.

00:07:05.800
00:07:11.000
Suppose you need inventory file
location, but you did not set in this.

00:07:11.000
00:07:13.500
Then your ansible want to consider
from other inventory

00:07:13.500
00:07:15.500
file other 'ansible.cfg' file.

00:07:16.000
00:07:19.800
First of all, it is considering in the
current location 'ansible.cfg' file.

00:07:19.800
00:07:22.800
This is the only now ansible.cfg file for
your ansible.

00:07:22.800
00:07:25.200
In case if you have settings it will take
otherwise

00:07:25.200
00:07:29.500
it will simply skip or it will give an error.
But it won't

00:07:29.500
00:07:33.300
take in case just assume that
inventory file is not mentioned
00:07:33.300
00:07:35.500
in the current location of 'ansible.cfg'
file.

00:07:35.700
00:07:38.400
If it is not there then you are ansible
won't concern

00:07:38.400
00:07:40.600
from other configuration files

00:07:41.000
00:07:42.600
,our inventory file, it won't do that.

00:07:42.600
00:07:43.400
It won't take it.

00:07:45.000
00:07:47.800
Whatever the configuration file is
picked by your ansible

00:07:47.800
00:07:50.400
in the doing it will try to look for
settings.

00:07:51.300
00:07:51.800
That's it. Okay. Okay guys. Thank you
for watching this video.
Transcript
00:00:00.000
00:00:04.400
Friends simply I want to revise our
Ansible Architecture here.

00:00:04.800
00:00:08.400
So already we know we already seen
this is the ansible architecture,

00:00:08.400
00:00:11.000
but why we have to draw this diagram
whenever if you say

00:00:11.000
00:00:13.200
ansible architecture right?

00:00:13.600
00:00:16.399
See let me explain that separately.

00:00:17.500
00:00:21.000
So suppose if you want to manage
some ten or hundred or thousands

00:00:21.000
00:00:23.800
of servers with ansible, right? In you
are assuming that in

00:00:23.800
00:00:25.200
your anware on any one moment.
00:00:25.200
00:00:26.900
You're having some number of
servers.

00:00:26.900
00:00:31.100
Let's say some three servers. nNt only
three you can take

00:00:31.100
00:00:32.200
any number of servers.

00:00:32.799
00:00:35.700
Now. I want to manage these these
three servers with the help

00:00:35.700
00:00:36.500
of ansible.

00:00:36.500
00:00:39.200
That's why we need to somewhere,

00:00:39.200
00:00:40.800
we need to install somewhere our
ansible.

00:00:40.800
00:00:42.700
That's why I'm going to take one extra
server.

00:00:42.900
00:00:45.900
So here I am going to install my
ansible, right?

00:00:45.900
00:00:50.600
So this is the first step in your ansible
architecture, right?

00:00:50.600
00:00:54.200
Then next what I have to do is - let me
do one thing.

00:00:54.200
00:00:56.300
This is your 'Ansible

00:00:58.300
00:01:05.500
Angine' or controller. Then this is let's
say server one or

00:01:05.500
00:01:07.600
manage node one. That's better.
Right?

00:01:07.600
00:01:08.000
We know now.

00:01:08.000
00:01:12.700
We are calling this as managed
nodes. Node 1, Node 2.
00:01:14.300
00:01:19.100
Likewise you can have any number of
nodes. Node 3. Right?

00:01:19.100
00:01:22.600
So now we have in our ansible
architecture one server for

00:01:22.600
00:01:26.900
ansible engine and remaining all of
our environment servers.

00:01:26.900
00:01:28.200
On those servers

00:01:28.200
00:01:34.700
we are going to work with your
ansible. Fine. Now to work from

00:01:34.700
00:01:38.300
your ansible with your manager nodes
what we need?

00:01:38.600
00:01:39.500
We need a connection.

00:01:39.500
00:01:42.300
We need to establish a connection,
right?

00:01:42.300
00:01:46.700
So ansible is going to get a connection
using SSH.

00:01:46.800
00:01:48.100
That's why you can say that.

00:01:48.100
00:01:53.000
So this here we are going to use SSH
connection.

00:01:53.000
00:01:54.700
Simply 'SSH connection'.

00:01:56.100
00:01:58.700
Right? Now these three are SSH
connections.

00:02:00.000
00:02:02.700
Fine. Now what we are doing.

00:02:04.100
00:02:07.000
I am going to connect with the remote
servers through using SSH.

00:02:07.000
00:02:09.600
So before going to connect, you need
to set up your SSH.
00:02:09.600
00:02:12.400
How we are going to set up? We can
set up in two ways.

00:02:12.400
00:02:15.500
One is passwordless authentication
and one more is with password

00:02:15.500
00:02:19.300
So till now we have seen
passwordless authentication

00:02:19.300
00:02:23.300
that is with the help of keys exchange
SSH keys.

00:02:23.400
00:02:27.000
So we will generate private and public
keys on your ansible

00:02:27.000
00:02:30.500
engine and we will share public keys
with all your manage

00:02:30.500
00:02:33.700
nodes, so that you can work at any
time

00:02:33.800
00:02:37.700
from with your all manage servers.
That's what we did.

00:02:37.700
00:02:41.800
So once if you do that, then now your
ansible is ready

00:02:41.800
00:02:44.700
to communicate with your remote
servers. But before going

00:02:44.700
00:02:47.300
to communicate, you need to mention
somewhere

00:02:48.700
00:02:55.200
in your ansible engine server the
managed nodes IPs, right?

00:02:55.200
00:02:59.300
You need to mention somewhere on
your ansible engine.

00:02:59.700
00:03:03.400
You need to mention in your file your
let's say
00:03:09.500
00:03:15.000
I want to take simply server 1 IP or
Node-1 IP. As of now,

00:03:15.000
00:03:24.100
I'm not writing but then Node-2 IP then
Node-3 IP , how to mention.

00:03:24.100
00:03:27.700
So once if you mention in this way
now this file we are calling

00:03:27.700
00:03:29.000
as 'Inventory'.

00:03:31.200
00:03:36.500
Inventory file and default inventory file
is under root ect ansible

00:03:36.500
00:03:37.500
and we have hosts. That's it.

00:03:39.900
00:03:44.400
Then after that we have seen
somewhere before going to connect

00:03:44.400
00:03:46.700
with your remote servers whenever if
you try to connect with

00:03:46.700
00:03:50.700
your remote servers using ansible.
Because at background

00:03:50.700
00:03:52.300
ansible is going to use SSH.

00:03:52.500
00:03:54.500
So whenever if you're trying to
connect with your remote

00:03:54.500
00:03:58.600
servers using SSH at very first time, it
is going to ask about

00:03:58.600
00:04:00.200
yes or no confirmation. Fingerprint
confirmation.

00:04:03.200
00:04:05.800
So we are going to provide yes, but
manually I don't want

00:04:05.800
00:04:08.600
to provide because by default I want to
work with managed
00:04:08.600
00:04:13.100
nodes. Why should I go and provide
manually always yes, yes,yes?

00:04:13.100
00:04:15.000
I don't want to provide for all servers
yes.

00:04:15.000
00:04:19.600
That's why you can do one set up on
your ansible engine server

00:04:19.600
00:04:22.399
that is simply host key checking as
false.

00:04:26.899
00:04:29.900
And see somewhere you are having
your inventory file in

00:04:29.900
00:04:33.400
different location and you can mention
your ansible file

00:04:34.200
00:04:37.600
location and sell inventory file location,
right?

00:04:38.600
00:04:44.000
So all these settings where we are
doing simply in your 'ansible.cfg' file.

00:04:44.000
00:04:44.500
That's it.

00:04:47.400
00:04:52.700
Right? Now we have, right, in your
ansible architecture, ansible

00:04:52.700
00:04:56.200
engine, remote nodes or manage
nodes or clients, inventory

00:04:56.200
00:04:59.900
file and 'ansible.cfg' file. That's fine.

00:04:59.900
00:05:03.200
Now suppose if you want to perform
any task on remote nodes,

00:05:03.600
00:05:05.300
right, you need to do something here.

00:05:06.200
00:05:10.100
So as of now, we have seen 'ansible -
m ping' means
00:05:10.100
00:05:12.400
you are going to check the
connectivity with your all remote

00:05:12.400
00:05:16.400
nodes. So here ping is the module. So
that's why whenever

00:05:16.600
00:05:21.800
you want to perform any task on your
remote nodes using ansible,

00:05:22.300
00:05:26.400
you know, you have a one concept
called modules as of now,

00:05:26.400
00:05:27.600
you know only modules.

00:05:28.700
00:05:39.600
Right. So now 'modules', that's it.
Right.

00:05:39.600
00:05:41.900
Now we can say simply in your ansible
architecture what we

00:05:41.900
00:05:44.600
have our environments are words.

00:05:46.200
00:05:48.700
Then these servers we are going to
manage with ansible.

00:05:48.800
00:05:50.500
That's why we need one extra server
there.

00:05:50.500
00:05:51.600
We are installing ansible.

00:05:52.300
00:05:55.100
Now we are mentioning this ansible
server information in one file

00:05:55.100
00:05:59.200
called 'Inventory'. And this ansible
needs some settings that

00:05:59.200
00:06:02.500
settings we are mentioning in
ansible.cgf file.

00:06:02.500
00:06:04.500
And using this ansible you are going
to work with the remote nodes,
00:06:04.500
00:06:07.200
so whenever if you want to work with
the remote nodes

00:06:07.200
00:06:12.100
using ansible in ansible, we have
predefined a scripts or

00:06:12.700
00:06:13.700
some programs.

00:06:13.700
00:06:15.300
Those are called simply modules.

00:06:15.700
00:06:19.300
So module is nothing but to perform
any action any task on

00:06:19.300
00:06:22.600
remote nodes. Remote nodes are
managed nodes in ansible.

00:06:22.600
00:06:24.900
We have predefined modules through
modules.

00:06:24.900
00:06:28.100
You can perform your tasks on remote
nodes.

00:06:28.100
00:06:30.300
So this is simply our ansible
architecture.

00:06:30.300
00:06:32.600
Of course, we have playbooks and
roles.

00:06:32.600
00:06:36.400
But as of now, this is simply your
simple ansible architecture.

00:06:36.400
00:06:37.500
That's it.

00:06:37.700
00:06:39.700
So just I want to revise this one.

00:06:39.700
00:06:42.500
That's why I did this because now we
know some concept from

00:06:42.500
00:06:44.800
ansible. That's why I mentioned that
okay.
00:06:44.800
00:06:45.400
Okay guys. Thank you for for watching
this video.
Transcript
00:00:00.000
00:00:02.700
[no audio] Friends, here

00:00:02.700
00:00:05.800
we are going to discuss about how to
install and configure

00:00:05.800
00:00:08.900
ansible on or hl8 see already.

00:00:08.900
00:00:13.200
We have seen how to install and
configure ansible on sent

00:00:13.200
00:00:14.800
weighs 7 same process.

00:00:14.800
00:00:16.800
You can follow for rhel 7.

00:00:18.300
00:00:21.400
But whenever if you come to our hl8
there is a small difference.

00:00:22.000
00:00:26.400
Anyway, first will try to go with the
steps which we followed
00:00:26.500
00:00:28.100
for our scent o S7.

00:00:29.600
00:00:34.100
So if you want to install ansible on
sent to S7, whatever

00:00:34.100
00:00:37.200
the steps we followed the same steps.

00:00:37.200
00:00:38.400
I am going to follow here.

00:00:39.000
00:00:42.000
But before going to that, let me launch
my our hl8 from my

00:00:42.000
00:00:46.000
cloud AWS Cloud you can take from
anywhere I am taking from

00:00:46.000
00:00:49.600
here. These are the Channel 8.

00:00:50.800
00:00:51.900
So add storage.

00:00:51.900
00:00:55.000
I want to go with default values and I
want to select a security

00:00:55.000
00:00:59.100
group. So in my security group, I open
all traffic just to

00:00:59.100
00:01:02.300
avoid confusion with the pro your Port
open ports and all

00:01:02.300
00:01:02.900
those things.

00:01:03.300
00:01:06.099
But anyway in real time based on
security groups, you will

00:01:06.099
00:01:09.700
select Now, let me launch it.

00:01:15.500
00:01:18.600
Once it is launched, right then we will
connect and we will

00:01:18.600
00:01:19.400
try with that.

00:01:21.300
00:01:27.400
so meanwhile, let me modify this as
ansible engine or a chill
00:01:27.700
00:01:34.900
8 I'm taking that's it.

00:01:36.400
00:01:37.400
Now it is up and running.

00:01:37.400
00:01:38.700
Let me connect with that.

00:01:42.800
00:01:46.500
So I'm going to connect using my git
bash terminal.

00:01:46.600
00:01:49.500
So if you don't how git bash, please try
to install git and

00:01:49.500
00:01:50.800
so that you will get git Bash.

00:01:57.100
00:01:58.300
It's taking some time.

00:01:58.400
00:01:59.300
Just wait.

00:02:05.900
00:02:08.300
So this is not fully up and running.

00:02:08.400
00:02:09.500
Maybe it is running now.

00:02:09.500
00:02:10.400
Let me try.

00:02:20.800
00:02:22.100
Oops, what happened man?

00:02:30.000
00:02:31.600
Knees up and running only right?

00:02:33.100
00:02:34.700
Maybe still initializing.

00:02:36.000
00:02:36.700
No problem.

00:02:45.400
00:02:46.200
Yeah, fine.

00:02:48.700
00:02:52.600
Now see here first, let me enter into
root and guys because

00:02:52.600
00:02:54.100
you are going to install ansible here.

00:02:54.100
00:02:55.400
You can update your m.
00:02:57.500
00:03:01.100
But now I'm not going to update my M
because it will take

00:03:01.100
00:03:01.700
some time.

00:03:02.400
00:03:03.500
I don't want to waste your time.

00:03:03.500
00:03:07.400
You can update in this way by using
this right once you see

00:03:07.400
00:03:10.500
update just try to install using urm.

00:03:11.700
00:03:15.300
I mean install your ansible using m c
that what you are getting.

00:03:16.800
00:03:19.500
In your orange jelly ate whatever the
default repository

00:03:19.500
00:03:22.800
you have in that you could not I mean
you are M could not

00:03:22.800
00:03:26.300
able to find ansible ansible package is
not there in your

00:03:26.300
00:03:27.100
default repo.

00:03:28.600
00:03:32.100
So guys if you remember in your
second way is by default,

00:03:32.100
00:03:38.200
right? We tried to install we tried to
install your ansible

00:03:38.200
00:03:43.700
without adding a repository and other
time we tried and we

00:03:43.700
00:03:49.500
got ansible as some 2.4 version but to
get latest ansible

00:03:49.500
00:03:54.200
what we did we went to let me open.

00:03:57.200
00:04:00.200
Guys, no need to follow any other
document simply open docks
00:04:00.200
00:04:01.400
that ansible.com.

00:04:01.800
00:04:04.200
So maybe it will take time but you will
get to good information

00:04:04.200
00:04:05.100
from here itself.

00:04:06.100
00:04:09.500
Now what we did in your aura shells or
sent to a seven we

00:04:09.500
00:04:14.600
enter into this repository and they're
based on your voice.

00:04:14.900
00:04:17.500
We added this repository to your
operating system.

00:04:17.500
00:04:25.300
Now, the hour C is 8, let me add this
repository to my Our

00:04:25.300
00:04:29.800
hl8 now I'm adding so after adding.

00:04:32.000
00:04:34.200
Now, let me try now install ansible.

00:04:34.300
00:04:34.900
These are the steps.

00:04:34.900
00:04:36.900
We followed in your scent weighs 7,
right?

00:04:37.400
00:04:40.800
Same steps We are following here
also, but even though if

00:04:40.800
00:04:46.200
you add your new repository to your
host in the tall, so

00:04:46.200
00:04:49.100
you could not able to find your
answers will package.

00:04:49.600
00:04:53.800
That means as of now, whatever the
EPL package is there that

00:04:53.800
00:04:57.300
is not updated with your ansible
package.
00:04:57.400
00:05:01.400
That's why you could not able to install
using m Then how

00:05:01.400
00:05:05.700
we can install so guys if you
remember we can install ansible

00:05:05.700
00:05:09.500
in three ways One is using M
command second one is people

00:05:09.800
00:05:11.300
third one is using source file.

00:05:11.900
00:05:12.000
Now.

00:05:12.000
00:05:15.300
Let me try with the hip is nothing but
using python.

00:05:15.700
00:05:19.400
Whip is the python package
management tool, you know ansible

00:05:19.400
00:05:22.000
is also one of the Python package.

00:05:23.000
00:05:24.200
Right fine.

00:05:24.600
00:05:26.900
Anyway before going to install your
ansible.

00:05:26.900
00:05:29.300
First of all, you should have some
python on your host.

00:05:29.800
00:05:30.600
Let me check it.

00:05:30.600
00:05:32.000
Is there any python or not?

00:05:38.000
00:05:39.200
I don't have any python.

00:05:40.300
00:05:44.800
Right buddy, how some distribution
python for your operating

00:05:44.800
00:05:49.500
system purpose somewhere in your
host not exert your in detail
00:05:49.500
00:05:52.000
your python, but don't worry about
that.

00:05:52.100
00:05:52.500
As of now.

00:05:52.500
00:05:53.600
You don't have any python here.

00:05:53.600
00:05:56.400
That's why what I am doing is first I
am trying to install

00:05:56.400
00:06:00.300
python. So guys because we are
using latest versions of operating

00:06:00.300
00:06:02.800
system. So in this latest version of the
operating system,

00:06:02.800
00:06:06.100
we are going to get both python 2 & 3
that's why you have

00:06:06.600
00:06:11.100
two major versions of your python
python 2 & 3 Now whether

00:06:11.100
00:06:13.600
you want to install two or three, you
need to mention suppose.

00:06:13.600
00:06:15.800
I want to go with the two we can go
with the three also,

00:06:15.800
00:06:16.500
no problem.

00:06:16.500
00:06:20.500
I'm installing only python to so once
you've installed your

00:06:20.500
00:06:23.500
python to just observe that what is the
python version you

00:06:23.500
00:06:29.200
are going to get Python 2 is there on
my operating system

00:06:29.400
00:06:31.200
and I'm getting 2 dot 7.15.

00:06:31.800
00:06:32.200
Yes.
00:06:32.700
00:06:37.100
Minimum 2.7 is fine for 2.8 versions of
ansible right fine.

00:06:38.600
00:06:41.600
Now, let me check it whether is a there
is a pipe is installed

00:06:41.600
00:06:42.700
or Not by default.

00:06:42.800
00:06:43.100
Yes.

00:06:43.100
00:06:45.800
It is installed and pointed to your
python 2.

00:06:46.900
00:06:48.700
Now let me install.

00:06:50.800
00:06:54.000
Your ansible, don't worry about
warning.

00:06:56.000
00:06:58.100
Just visit warning not an error, right?

00:06:58.700
00:07:01.700
So once it is installed then we'll check
it about your ansible.

00:07:11.500
00:07:12.400
It is almost done.

00:07:12.800
00:07:16.500
So once it is done then actually I need
to show some differences

00:07:16.500
00:07:21.000
between your old versions of I mean
with the m command if

00:07:21.000
00:07:26.200
install pi r ansible and if you install
your ansible with

00:07:26.200
00:07:27.300
peep, what is the difference?

00:07:27.900
00:07:29.900
Anyway, we installed your ansible.

00:07:29.900
00:07:30.700
Let me check it.

00:07:30.700
00:07:32.000
What is the ansible here?
00:07:32.800
00:07:37.700
Yes, you are getting 2 dot 8.4 so today
but some minor version

00:07:38.300
00:07:41.300
so previously we Lower ansible here,
right?

00:07:41.300
00:07:44.000
I mean on my son to his from VMware.

00:07:44.500
00:07:48.500
Let me check it my ansible version
here to dot 8.2.

00:07:48.700
00:07:51.200
So at that time I have this version
maybe now we have to

00:07:51.200
00:07:54.400
dot a DOT for no problem, right?

00:07:54.400
00:07:57.100
You can also install specific version
while installing your

00:07:57.100
00:07:59.700
ansible by giving here ansible version.

00:08:00.300
00:08:03.600
Okay, but no problem and see the
difference guys in the output

00:08:03.600
00:08:06.400
of your ansible - iPhone version here
you are getting ansible

00:08:06.400
00:08:11.200
version config file is none, but
whereas in Sento S7 you're

00:08:11.200
00:08:12.400
getting some config file.

00:08:12.400
00:08:13.700
That is the default location.

00:08:14.100
00:08:18.500
But why you are not getting here the
reason is whenever if

00:08:18.500
00:08:21.100
you install your ansible with um
command you are going to

00:08:21.100
00:08:26.600
get default ansible home as root ATC
ansible, but now here
00:08:26.600
00:08:32.200
you don't have ansible default home
on RH L E8 because we

00:08:32.200
00:08:36.100
followed python pipe installation
procedure.

00:08:37.000
00:08:39.200
So that's why I told that a very first
time please don't

00:08:39.200
00:08:39.900
go with the pit.

00:08:40.100
00:08:44.000
As of now because this is the
difference if you go with them,

00:08:44.000
00:08:46.200
you will get default structure and so
that you can understand

00:08:46.200
00:08:47.799
about your ansible directory structure.

00:08:49.299
00:08:52.400
Now if you miss yeah, you know that
what is the default structure

00:08:52.400
00:08:55.700
for your ansible now you can able to
create your environment.

00:08:55.700
00:08:57.400
I mean you are default directory
structure.

00:08:58.900
00:08:59.300
Right.

00:08:59.500
00:09:03.700
So now what I am doing is I am
moving into root EDC and symbol.

00:09:03.900
00:09:05.500
Sorry, we don't have ansible right?

00:09:05.500
00:09:08.900
Let me move in to retrieve it is C and
let me create directory

00:09:08.900
00:09:10.400
called ansible now.

00:09:10.400
00:09:12.000
Let me enter into this ansible.
00:09:12.700
00:09:14.700
So guys, what are the files you have
under ansible?

00:09:15.100
00:09:19.400
If you remember you have three things
one is roles and two

00:09:19.400
00:09:22.900
files and build walls CFG and
inventory file that is hosts.

00:09:24.300
00:09:26.400
Now these three things we can create
now here.

00:09:26.900
00:09:27.900
Let me create them.

00:09:29.900
00:09:36.600
Make directory roles and touch and
simple dot C of G host.

00:09:36.800
00:09:39.300
We don't have any content into that,
but we need this data

00:09:39.300
00:09:43.300
structure. So once if you done this
now, let me run ansible.

00:09:43.600
00:09:44.700
You can run from anywhere.

00:09:46.300
00:09:47.700
Yes, you are getting right.

00:09:49.500
00:09:54.700
the same thing now you're also getting
on your sent weighs

00:09:54.700
00:09:57.800
7 which where we followed em
installation now we created

00:09:57.800
00:09:58.800
this environment.

00:10:01.900
00:10:10.500
right fine Is there anything yeah Noble
everything is fine.

00:10:11.600
00:10:15.400
So now we have default directory
structure for your ansible.
00:10:15.700
00:10:18.900
Now, let me come out from here
instead of that.

00:10:18.900
00:10:23.000
Let me create user add and set Min
because we are following

00:10:23.000
00:10:25.800
this procedure right once you install
your ansible, then

00:10:25.800
00:10:29.600
we are going to create same user
across all servers and let

00:10:29.600
00:10:32.200
me provide password for this ants
admin.

00:10:32.800
00:10:33.400
So password.

00:10:33.400
00:10:36.900
I am going to provide ants admin or
the red 123 same password.

00:10:36.900
00:10:44.400
I am going to give Right, and I want to
make it as a I mean,

00:10:44.400
00:10:46.400
I want to give you root privileges for
this user.

00:10:46.400
00:10:48.400
So where you can give it the ice to do.

00:10:51.200
00:10:52.200
So I answered Min.

00:10:53.100
00:10:55.400
Let me copy this and I want to paste it.

00:10:59.800
00:11:00.300
That's it.

00:11:00.900
00:11:01.700
And one more thing.

00:11:02.500
00:11:06.000
It is see SSH ssh D config file.

00:11:06.200
00:11:11.600
You can mention your password
authentication as yes.
00:11:19.000
00:11:23.800
Right now for your user we have root
privileges.

00:11:28.800
00:11:31.200
Okay, let me come out from here.

00:11:33.200
00:11:38.600
Sorry, we need to enter into pseudo
OSU and admin.

00:11:42.100
00:11:46.300
Fine now, we are in our on our ants
admin user now.

00:11:46.300
00:11:49.500
Let me run from here and simple -
iPhone version.

00:11:49.600
00:11:52.800
So what you have to get you need to
get some output such

00:11:52.800
00:11:55.800
that if know where if you are able to
find the answers will

00:11:55.800
00:11:59.300
dot CFG file then it has to pick the
default ansible dot

00:11:59.300
00:12:00.200
CFG file.

00:12:00.600
00:12:02.800
So in previous videos, we have
discussed about different

00:12:02.800
00:12:06.900
locations for ansible or configuration
file and the least

00:12:06.900
00:12:09.700
priority is always for your default
location of ansible dot

00:12:09.700
00:12:10.400
CFG file.

00:12:10.400
00:12:10.700
Yes.

00:12:10.700
00:12:11.700
Now we are able to get it.

00:12:12.900
00:12:16.100
Guys, the only thing is you need to
create default ansible
00:12:16.100
00:12:21.200
home in your or hl8 because we
followed python people to

00:12:21.200
00:12:22.500
install your ansible.

00:12:22.600
00:12:23.100
That's it.

00:12:24.300
00:12:24.500
Now.

00:12:24.500
00:12:27.300
What I am doing is I am going to
create some directory called

00:12:27.300
00:12:30.900
my ansible nan.

00:12:32.700
00:12:38.600
Fraud simply n prod you can grade
any directory now.

00:12:38.600
00:12:40.500
I am going to create my own ansible
home.

00:12:40.500
00:12:43.000
This is just I am assuming that this is
my ansible home.

00:12:44.000
00:12:44.700
No from here.

00:12:44.700
00:12:46.700
I'm running ansible iPhone iPhone
version.

00:12:48.400
00:12:51.700
So still we don't have any animal dot
CFG file other than

00:12:51.700
00:12:52.700
your default location.

00:12:52.700
00:12:55.200
That's why your hands will is picking
that and double dot

00:12:55.200
00:12:58.300
CFG file now, let me create in the
current location and double

00:12:58.300
00:13:02.100
dot CFG file and let me run ansible
iPhone iPhone version
00:13:02.200
00:13:04.000
now it is going to pick in the current
location and small

00:13:04.000
00:13:04.900
dot CFG file.

00:13:05.400
00:13:05.900
That's it.

00:13:06.000
00:13:07.000
Now, everything is fine.

00:13:08.700
00:13:12.000
Right now and one more thing.

00:13:13.800
00:13:16.300
We need host file as well.

00:13:17.000
00:13:17.200
Right?

00:13:17.200
00:13:18.400
Let me create a host here.

00:13:21.300
00:13:25.500
Fine and suppose this previously.

00:13:25.600
00:13:29.900
I have taken my ansible engine server
from my VMware suppose

00:13:29.900
00:13:31.800
if I want to continue from this server.

00:13:31.800
00:13:34.500
I mean, I want to take this as my
ansible engines are were

00:13:34.800
00:13:35.200
then here.

00:13:35.200
00:13:38.300
Also, I need to update my inventory
file before going to

00:13:38.300
00:13:41.300
update your inventory file that is host
file with your remote

00:13:41.300
00:13:42.600
eyepiece or manage diabetes.

00:13:42.600
00:13:45.800
You need to establish a connection
between your managed nodes

00:13:45.900
00:13:48.300
and with your ansible engine server.
00:13:49.100
00:13:49.300
Right.

00:13:49.300
00:13:52.600
Anyway, we are creating same user
across all servers.

00:13:52.900
00:13:54.700
So already we know previous
sessions.

00:13:54.900
00:13:58.100
We consider this Node 1 node 2 and
node 3 as our managed

00:13:58.100
00:14:01.900
nodes and already we created and
submitted across all these

00:14:01.900
00:14:05.600
three users and already be enabled
password less authentication

00:14:05.600
00:14:11.700
as yes and already we exchanged our
keys from my VMware sent

00:14:11.700
00:14:13.300
weighs 7 server from here.

00:14:13.400
00:14:16.200
I exchanged my keys, but now I don't
want to work from here

00:14:16.800
00:14:19.800
just assume that suppose iPhone to
work from Yura Rachel

00:14:19.800
00:14:23.700
8 then here you need to generate your
keys and again from

00:14:23.700
00:14:27.200
here you have to exchange your keys
with your manager nodes.

00:14:28.600
00:14:29.100
Right.

00:14:29.500
00:14:31.500
So, you know, what are the steps to
generate your keys?

00:14:31.500
00:14:34.100
Simply SSH - key Jen.

00:14:36.000
00:14:36.500
That's it.
00:14:36.600
00:14:39.300
It is going to create your keys on the
door at SSH.

00:14:40.200
00:14:41.500
I mean under user home.

00:14:42.000
00:14:42.900
Let me go too.

00:14:45.000
00:14:46.400
So you have dot SSH.

00:14:46.400
00:14:50.000
So here you created this is private key
and this is public

00:14:50.000
00:14:52.900
key. So if you want to make a pass for
Less authentication

00:14:52.900
00:14:55.500
between servers, so from here, if you
want to connect with

00:14:55.500
00:14:59.200
anyone server suppose using
password less, then you need

00:14:59.200
00:15:01.900
to share this key with your manager
node.

00:15:02.100
00:15:03.200
So, how can I share?

00:15:03.200
00:15:10.200
Simply SSH - copy - ID then you are
remote server IP man,

00:15:10.200
00:15:14.300
who is first in our first let me take first
manager node.

00:15:14.600
00:15:15.400
Is my manager?

00:15:15.400
00:15:17.100
No, right.

00:15:17.100
00:15:21.800
So guys now you can go with either
private APR public IP

00:15:22.500
00:15:26.700
because my ansible engine and my
notes all are from same
00:15:26.700
00:15:28.800
network from your AWS Cloud.

00:15:29.500
00:15:32.700
Then I can take either private IP or
public type if that

00:15:32.700
00:15:35.500
is your wish if you go with private IP.

00:15:35.700
00:15:38.900
Yes, let me take this private IP and let
me provide that

00:15:40.200
00:15:43.300
yes, just provide user password for
that.

00:15:43.600
00:15:47.000
Anyway, we already Created
password as answered Min or the

00:15:47.000
00:15:50.100
right one, two three right now.

00:15:50.100
00:15:53.300
Let me connect with this sh and press
enter.

00:15:53.800
00:15:56.800
So without asking password you able
to connect with your

00:15:57.000
00:15:58.800
remote server manage node.

00:16:02.100
00:16:02.500
That's it.

00:16:04.400
00:16:10.500
right now Same way let me copy ID.

00:16:10.600
00:16:14.500
I mean this public IP to Second
manage node as well.

00:16:15.100
00:16:17.900
So again here also, you can take
either private IP a public

00:16:17.900
00:16:20.600
IP. But now I am taking private eye
public IP.

00:16:20.600
00:16:21.000
No problem.

00:16:21.000
00:16:22.100
We can go with any IP.
00:16:24.300
00:16:26.500
And sad Min or the right one, two
three.

00:16:28.700
00:16:31.300
Now, let me copy for third managed
node as well.

00:16:32.000
00:16:35.300
So guys here I am not creating and
submitting user across

00:16:35.300
00:16:39.100
your remaining managed nodes
because we already created while

00:16:39.100
00:16:41.200
working with from sin to are seven.

00:16:41.800
00:16:42.800
That's why yes.

00:16:42.800
00:16:46.100
I am using same answered been user
from here also.

00:16:47.300
00:16:48.700
Okay, don't get confused.

00:16:50.400
00:16:52.100
Now, let me take third note.

00:16:53.600
00:16:56.400
So on this user you can take either
private or public.

00:17:05.098
00:17:05.598
That's it.

00:17:05.700
00:17:05.900
Now.

00:17:05.900
00:17:10.000
We exchanged our keys from your or
a chelate ansible engine

00:17:10.000
00:17:11.200
to your manager nodes.

00:17:12.098
00:17:14.598
Now, let me know down my all
eyepiece.

00:17:15.400
00:17:18.200
So I am going to take public IP or you
can also take private

00:17:18.200
00:17:19.300
IP first.
00:17:19.300
00:17:22.900
I will take public eye bees because I
want to show you.

00:17:24.500
00:17:29.300
Connection established with your rhel
8 and from our VMware

00:17:29.300
00:17:31.400
which is or sent West 7.

00:17:33.000
00:17:37.400
Why actually we up to now till this
moment we have seen some

00:17:37.400
00:17:41.200
delay whenever if you are going to
connect with your managed

00:17:41.200
00:17:45.099
nodes from your sin to a 7 right.

00:17:45.900
00:17:47.400
So now I am going to update this.

00:17:50.900
00:17:54.700
VI host to file I am going to update
your servers.

00:17:54.800
00:17:57.700
So now I am going to run and Sybil.

00:17:59.500
00:18:05.000
All - um thing is but we missed one
thing try to find that

00:18:05.300
00:18:08.600
if I run this, you're not getting any
output.

00:18:09.000
00:18:11.200
Your Ansel is not able to Ping to any
servers.

00:18:11.800
00:18:16.000
The reason is If You observe Your
answer will not CFG file

00:18:16.000
00:18:19.800
is empty and in the current location we
have ancelot CFG

00:18:19.800
00:18:22.500
file your answer will try to get some
configurations from

00:18:22.500
00:18:23.100
that file.
00:18:24.000
00:18:26.400
So in that file, I need to mention about
my inventory file,

00:18:26.400
00:18:28.000
right, but I didn't mention that.

00:18:29.100
00:18:33.000
So if you don't want to mention you
can run simply by giving

00:18:33.000
00:18:35.400
- I your inventory file.

00:18:35.500
00:18:38.000
This is fine if you don't want to
mention your inventory

00:18:38.000
00:18:40.800
information in your servers.

00:18:43.400
00:18:46.500
Right, so guys and one more thing see
here.

00:18:49.700
00:18:50.100
Sr.

00:18:50.100
00:18:56.900
No asking right, so that's why if you
remember there is a

00:18:56.900
00:19:03.200
Syntax for your ansible dot CFG file
Let me move into what

00:19:03.200
00:19:06.700
is that our nonprofit right and double
dot CFG.

00:19:06.900
00:19:10.500
Let me try with the grip inventory.

00:19:11.500
00:19:14.800
So if it directly start with peep
insulation for your ansible,

00:19:14.800
00:19:17.000
you can't understand all those things
now.

00:19:17.000
00:19:18.300
Let me copy this value.

00:19:20.900
00:19:26.100
Now come to hear open you are
ansible DOT CFG file and just
00:19:26.100
00:19:30.300
write with square brackets defaults
and the mention your

00:19:30.300
00:19:34.700
inventory file location and along with
that if you remember

00:19:35.000
00:19:39.000
you need to mention host key
checking as false.

00:19:42.200
00:19:47.400
simply oh Sticky Chicken equals to
false Now I want to mention

00:19:47.400
00:19:49.100
this as well in this file.

00:19:54.000
00:19:54.400
Right.

00:19:54.600
00:19:57.300
Anyway, you can use default and build
or CFG file entire

00:19:57.300
00:20:00.200
settings and you can copy and in that
you can enable or disable.

00:20:00.600
00:20:04.000
But as of now I want only this value is
just I set them now

00:20:04.000
00:20:06.300
see that I am going to run without
hyphen.

00:20:06.300
00:20:06.900
I option.

00:20:07.000
00:20:10.400
I already mentioned my post
information or inventory file

00:20:10.400
00:20:12.400
location in my ants build or CFG file.

00:20:12.400
00:20:15.000
Now your answer will communicate in
the current location

00:20:15.200
00:20:18.500
and School Board CFG file, then it will
work.

00:20:22.100
00:20:23.300
We're getting response now.
00:20:25.100
00:20:32.600
but same ansible all iPhone em if I run
from here My VMware

00:20:32.700
00:20:34.400
I'm using now my VMware.

00:20:37.800
00:20:39.600
Okay, let me take this back up.

00:20:48.500
00:20:51.700
So I am mentioning my remote
managed node eyepiece.

00:20:51.700
00:20:55.800
Now, I am trying to run ansible ping
command.

00:20:57.600
00:21:01.400
Fing module or simply one ansible
command now it is going

00:21:01.400
00:21:02.500
to sleep take some time.

00:21:02.500
00:21:06.100
No see it is taking some time to
communicate with your managed

00:21:06.100
00:21:14.400
nodes because because I already told
this we are using ansible

00:21:14.400
00:21:18.000
engine on my VM Ware, but you are
managed nodes are on your

00:21:18.000
00:21:19.800
cloud different network.

00:21:19.800
00:21:21.100
That's what is taking some time.

00:21:22.000
00:21:28.900
But now This our hl8 This Server is
also from my cloud and

00:21:28.900
00:21:32.900
managed nodes also from my AWS
Cloud then if I run this it

00:21:32.900
00:21:36.400
is going to give you a response
compared.

00:21:36.400
00:21:40.800
I mean in less time compared to your
scent o S7 from VMware.
00:21:40.800
00:21:44.500
It is taking very less time to get
response from your servers.

00:21:47.000
00:21:47.300
Bye.

00:21:48.800
00:21:54.300
fine Okay guys, so this is the way how
we can install and

00:21:54.300
00:21:57.300
configure using your or hl8 thing.

00:21:57.300
00:21:59.700
Is there just to be installed with the
peep and we created

00:21:59.700
00:22:04.000
some root EDC ansible home
directory and under that.

00:22:04.000
00:22:07.500
We created three things one is two
files on on Morris directory

00:22:07.600
00:22:11.500
and soldered CLG host and roles
directory after that remaining

00:22:11.500
00:22:12.300
procedure is same.

00:22:14.300
00:22:18.500
So if you want to use this or hl8 as
your answer will engine.

00:22:18.500
00:22:21.300
Yes, you can go on use or if you want
to go with your sent

00:22:21.300
00:22:25.600
away seven or or hl7 or any other like
Ubuntu or your Amazon

00:22:25.600
00:22:29.000
Linux. Yes, you can use for your
ansible engine anyone of

00:22:29.000
00:22:30.600
Enochs like based system.

00:22:31.400
00:22:33.800
That's it and one more thing.

00:22:35.600
00:22:37.900
Yeah, see that actually Norwich L8.
00:22:37.900
00:22:40.700
Also we have the default python
location in this.

00:22:42.200
00:22:46.400
Right see that anywhere now our
engine is also or hl8.

00:22:48.700
00:22:51.500
Three dot 6.8 we have that.

00:22:53.700
00:22:54.100
Right.

00:22:54.300
00:22:57.200
So if you want to use purely or
required python, then you

00:22:57.200
00:23:01.100
can install right fine.

00:23:01.600
00:23:04.400
So nothing is there don't confuse here.

00:23:07.300
00:23:10.900
So guys suppose if you want to install
your ansible with

00:23:10.900
00:23:14.600
the em on your are hl8 you need to do
one more thing.

00:23:14.800
00:23:15.300
Actually.

00:23:16.700
00:23:20.800
If you want to you need to subscription
manager or repo you

00:23:20.800
00:23:26.600
have to use So what is subscription
manager repo if you simply

00:23:26.600
00:23:28.700
search subscription manager app you
are going to get the

00:23:28.700
00:23:29.600
information here.

00:23:30.100
00:23:34.400
So only for the subscribers who
subscription manager did

00:23:34.400
00:23:35.600
on one their host.
00:23:35.800
00:23:38.800
They can only enable a repository PL
repository such that

00:23:38.800
00:23:41.900
they can install ansible with the m as
of now on our hl8.

00:23:42.300
00:23:45.400
So while going forward everyone will
get this package and

00:23:45.400
00:23:47.200
everyone can install using Young.

00:23:48.400
00:23:51.100
But anyway, and rh8, as of now, it is
not possible with the

00:23:51.100
00:23:55.000
m. Not possible means if you don't do
subscription.

00:23:56.300
00:23:56.500
Right.

00:23:56.500
00:23:57.900
That's why I simply be followed.

00:23:59.100
00:24:03.100
peep installation procedure Right.

00:24:03.600
00:24:07.700
So the only thing once if you follow
peep installation procedure,

00:24:07.700
00:24:11.000
you need to create your ansible
default user home.

00:24:12.200
00:24:12.700
That's it.

00:24:14.100
00:24:14.500
Okay.

00:24:15.200
00:24:15.800
Okay guys.

00:24:15.800
00:24:17.100
Thank you for watching this video.
Transcript
00:00:00.000
00:00:02.400
Friends here

00:00:02.400
00:00:06.200
we are going to discuss about ansible
ad-hoc commands. Simply

00:00:06.200
00:00:07.609
introduction part.

00:00:07.600
00:00:10.010
Let me start that.

00:00:10.000
00:00:13.900
Friends, we can work with your
manage nodes using your ansible

00:00:13.900
00:00:16.110
in two ways.

00:00:16.100
00:00:21.100
One is using ad-hoc commands,
second one is playbooks. Ansible

00:00:21.100
00:00:23.510
ad-hoc commands and ansible
playbooks.
00:00:23.500
00:00:26.310
Anyway before going to work with this
concept,

00:00:26.300
00:00:29.110
we are already familiar with our UNIX-
like systems, right?

00:00:29.100
00:00:32.110
Let me open my UNIX-like system.

00:00:32.100
00:00:33.409
So suppose.

00:00:33.400
00:00:35.510
I want to know the uptime of my
server.

00:00:35.500
00:00:36.010
Yes.

00:00:36.000
00:00:38.600
I'm using one of the command called
uptime and I am going

00:00:38.600
00:00:40.610
to get this result.

00:00:40.600
00:00:44.200
So now if you observe uptime that is a
command the purpose

00:00:44.200
00:00:48.309
of our time is just to get your uptime of
a server. Simply

00:00:48.300
00:00:52.100
your uptime is giving the output for
one task the task is

00:00:52.100
00:00:58.910
Uptime. Now I want to get RAM usage
then I can use this command

00:00:58.900
00:01:02.900
so now free -m is the one of the
command and the purpose

00:01:02.900
00:01:08.200
of this command is just to get RAM
usage nothing but one

00:01:08.200
00:01:12.800
simple task output. So you're using
free -m to get
00:01:12.800
00:01:18.700
some output for a task. Task is RAM
usage. Right? Now

00:01:18.700
00:01:23.110
here if I want to execute these two
commands at a time then

00:01:23.100
00:01:28.400
what can I do? Nothing is there. You
can write a simple shell

00:01:28.400
00:01:32.210
script in that you can include these
two commands.

00:01:32.200
00:01:36.900
Right? So I am writing vi. Let me write
a let me take any

00:01:36.900
00:01:45.810
shell script named as multi_task.sh.

00:01:45.800
00:01:51.900
So uptime free -m. Now. I am going to
run this.

00:01:51.900
00:01:54.210
[no audio]

00:01:54.200
00:01:59.310
Yes, you are getting your uptime as
well as your RAM usage.

00:01:59.300
00:02:03.000
So guys if you have a commands,
individually you can run

00:02:03.000
00:02:07.410
your commands and you know, each
command purpose is different

00:02:07.400
00:02:09.609
Uptime command is purpose different,
free-m

00:02:09.600
00:02:13.400
command purpose is different. And
whenever if you want

00:02:13.400
00:02:16.500
to run these two commands and if you
want to get a output

00:02:16.500
00:02:20.810
for these two, then you can also write
these two commands
00:02:20.800
00:02:24.000
in a file called shell skip and you can
run that so that

00:02:24.000
00:02:27.910
we are going to get output for these
two commands.

00:02:27.900
00:02:32.600
Right? Now. If you're clear with this
ansible ad-hoc commands

00:02:32.600
00:02:36.800
are nothing but your Linux command I
mean, it's like your Linux

00:02:36.800
00:02:40.500
commands and ansible playbooks are
nothing but like your

00:02:40.500
00:02:45.310
shell script. Guys only purpose, not
the syntax.

00:02:45.300
00:02:50.100
So a lot of comments are useful to
execute a single task

00:02:50.100
00:02:53.109
on your manage nodes. See uptime.

00:02:53.100
00:02:57.600
You are going to get uptime for a
server. free -m.

00:02:57.600
00:03:02.100
you're going to get RAM usage for
your server. Only one

00:03:02.100
00:03:05.300
task you're executing with uptime or
with free -m.

00:03:05.300
00:03:09.010
But with the shell script, we are
executing two tasks,

00:03:09.000
00:03:11.700
uptime as well as free -m. Because we
included

00:03:11.700
00:03:16.600
those commands inside of our shell
script. The same way ansible
00:03:16.600
00:03:21.200
ad-hoc commands are useful to
execute one task on your remote

00:03:21.200
00:03:23.209
node or nodes.

00:03:23.200
00:03:27.510
You can exclude on one single node
or on multiple nodes or

00:03:27.500
00:03:30.109
we know group concept as well in your
inventory.

00:03:30.100
00:03:34.810
So you can execute your ad-hoc
commands on a group or a server

00:03:34.800
00:03:38.000
or a multiple groups or on a multiple
servers or combination

00:03:38.000
00:03:40.709
of servers and groups.

00:03:40.700
00:03:43.200
Now. Playbooks are nothing but
whatever.

00:03:43.200
00:03:46.800
the individual tasks you're going to
execute you're going

00:03:46.800
00:03:48.200
to get with ad-hoc commands.

00:03:48.200
00:03:49.300
Those ad-hoc commands

00:03:49.300
00:03:54.109
we are going to write in a Playbook
and you are going to

00:03:54.100
00:03:57.109
get output for multiple tasks using
playbooks.

00:03:57.100
00:03:57.500
That's it.

00:03:57.500
00:04:00.209
[no audio]

00:04:00.200
00:04:03.910
Fine. Now. What is ad-hoc command?
00:04:03.900
00:04:08.109
So guys the ad-hoc command is the
one liner and simple command

00:04:08.100
00:04:14.010
that performs one task on the target
host or groups.

00:04:14.000
00:04:17.209
Let me show you simply one simple
ad-hoc command.

00:04:17.200
00:04:19.100
So let me open my ansible controller.

00:04:19.100
00:04:22.510
This is actually my ansible controller.

00:04:22.500
00:04:25.510
See that I have ansible here.

00:04:25.500
00:04:26.310
Right?

00:04:26.300
00:04:28.909
So guys, this is my RHEL 8.

00:04:28.900
00:04:32.900
So by default you are not going to get
your ansible default

00:04:32.900
00:04:37.000
home called root EDC ansible in your
are rhel8 whenever if

00:04:37.000
00:04:41.500
you install with git. Right? We created
if you remember in

00:04:41.500
00:04:43.909
our previous classes, okay.

00:04:43.900
00:04:47.409
Now I am entering into my practice
directory.

00:04:47.400
00:04:51.200
Let me show you my all the servers
which are there my inventory

00:04:51.200
00:04:52.300
file called hosts.

00:04:52.300
00:04:54.510
[no audio]

00:04:54.500
00:05:00.710
Right. So these are the three servers,
but I created in terms of two groups.
00:05:00.700
00:05:03.200
So in your real time, you may have
any number of groups on

00:05:03.200
00:05:04.200
any number of servers.

00:05:04.200
00:05:06.710
No problem. Fine.

00:05:06.700
00:05:12.100
Now, I am going to run one simple
ansible ad-hoc command. So whenever

00:05:12.100
00:05:16.400
if I say ad-hoc command, you need to
think ad-hoc commands

00:05:16.400
00:05:21.110
are going to use to get to execute one
task.

00:05:21.100
00:05:25.409
So as of now suppose my task is just
to check the connectivity

00:05:25.400
00:05:28.810
from your ansible controller to your
ansible nodes.

00:05:28.800
00:05:33.100
So for that this is the syntax for your
ansible ad-hoc command.

00:05:33.100
00:05:34.700
Ansible. Here.

00:05:34.700
00:05:38.300
You have to provide either server
name or group name or server

00:05:38.300
00:05:41.010
name and group name.

00:05:41.000
00:05:41.900
For time being suppose,

00:05:41.900
00:05:43.300
I am going to take DB group.

00:05:43.300
00:05:46.500
I want to check the connectivity with
you with my DB groups

00:05:46.500
00:05:47.710
are worse.
00:05:47.700
00:05:51.000
So as of now, I am having only 1
server under my DB group.

00:05:51.000
00:05:53.600
But in real time you may have any
number of servers but no

00:05:53.600
00:05:59.800
problem same syntax. db -yum, then
you have to provide here

00:05:59.800
00:06:03.110
one module, ping.

00:06:03.100
00:06:05.909
Right. So guys, this is module

00:06:05.900
00:06:09.610
Now this module is going to execute
your task.

00:06:09.600
00:06:12.500
First of all, this is complete ansible ad-
hoc command, but

00:06:12.500
00:06:16.510
your ad-hoc command is going to
execute a task using a module,

00:06:16.500
00:06:18.300
So based on your required tasks.

00:06:18.300
00:06:22.100
You need to select your required
module. For time being,

00:06:22.100
00:06:23.200
let me execute this.

00:06:23.200
00:06:25.610
[no audio]

00:06:25.600
00:06:28.510
Yes, you're going to get response as
pong.

00:06:28.500
00:06:32.000
But now I want to get up time for my
all DB servers then

00:06:32.000
00:06:36.100
ansible your group name in case if you
have group otherwise,

00:06:36.100
00:06:38.610
you can also execute on single server
also, no problem.
00:06:38.600
00:06:41.510
Let me execute on single server.

00:06:41.500
00:06:45.110
So suppose this is my single server
and I want to execute

00:06:45.100
00:06:47.810
I want to check the uptime for this.

00:06:47.800
00:06:50.810
So to get uptime, you have one
module.

00:06:50.800
00:06:53.100
But don't worry about that, which
model you are going to

00:06:53.100
00:06:57.900
use as of now. Just after the syntax -
m shell. Shell is nothing

00:06:57.900
00:07:01.600
but is simply a module which is useful
to execute your commands

00:07:01.600
00:07:03.210
on your remote nodes.

00:07:03.200
00:07:06.110
So that commands you have to
provide as an argument.

00:07:06.100
00:07:10.710
So argument you have to provide that
argument inside of quotation.

00:07:10.700
00:07:11.100
That's it.

00:07:11.200
00:07:14.010
No, you're going to get up time for this
server.

00:07:14.000
00:07:17.110
59 minutes. Right.

00:07:17.100
00:07:20.700
Now what I want to do is I want to
execute my uptime commander

00:07:20.700
00:07:25.210
all servers then instead of one server
just to mention all.

00:07:25.200
00:07:25.600
That's it.
00:07:25.600
00:07:27.810
[no audio]

00:07:27.800
00:07:31.000
Suppose if you have multiple groups
and you want to execute

00:07:31.000
00:07:34.610
only supposed server in your inventory
have some 10 groups,

00:07:34.600
00:07:38.300
but you want to execute on only on
two groups, right?

00:07:38.300
00:07:40.800
So as of now anyway, I have only two
good but assume that

00:07:40.800
00:07:44.600
you have some multiple groups in your
inventory, but you

00:07:44.600
00:07:49.200
want to execute your task only on two
groups then your first

00:07:49.200
00:07:52.900
two group then let me take your
second group, but with colons

00:07:52.900
00:08:00.100
you have to mention then - m shell �
uptime. Now.

00:08:00.100
00:08:02.100
We are going to get a ping for all your
servers.

00:08:02.100
00:08:04.500
I mean whatever the servers are there
in DB group and web

00:08:04.500
00:08:09.800
servers group now I want to execute
even I want to know RAM

00:08:09.800
00:08:15.010
usage as well then same command
just argument is different.

00:08:15.000
00:08:15.500
That's it.

00:08:15.500
00:08:17.810
[no audio]
00:08:17.800
00:08:21.210
Fine. Now. See here?

00:08:21.200
00:08:25.500
If you remember in ansible.cfg, we
mentioned the inventory

00:08:25.500
00:08:26.810
file location.

00:08:26.800
00:08:29.400
So whatever the servers are there in
this inventory those

00:08:29.400
00:08:32.299
servers will be identified by your
ansible while running

00:08:32.299
00:08:38.100
your ansible ad-hoc commands or
playbooks, but sometimes you

00:08:38.100
00:08:42.299
may have two tree inventory files. One
inventory file for suppose

00:08:42.299
00:08:45.710
prod and one inventory file is for non-
prod.

00:08:45.700
00:08:48.010
Right? Let me create my vi prod.

00:08:48.000
00:08:51.510
Let's just assume prod inventory.

00:08:51.500
00:08:52.400
You can provide any name.

00:08:52.400
00:08:53.809
No problem.

00:08:53.799
00:08:54.309
Right?

00:08:54.299
00:08:56.700
So in this what I am doing is simply I'm
taking localhost

00:08:56.700
00:08:58.810
as my proxy server.

00:08:58.800
00:09:02.200
So guys if you want to work with your
localhost, don't forget

00:09:02.200
00:09:05.500
to exchange your keys with your
localhost as well.
00:09:05.500
00:09:08.010
Otherwise, it won't work.

00:09:08.000
00:09:11.000
The way how we exchange
exchanged our keys with your remote

00:09:11.000
00:09:12.000
nodes the same way.

00:09:12.000
00:09:16.610
You have to exchange your keys with
your localhost as well.

00:09:16.600
00:09:21.010
Now observe that in your ansible.cfg
file you have host.

00:09:21.000
00:09:23.600
This is the inventory file, but I don't
want to use this

00:09:23.600
00:09:26.100
inventory. Now. I want to use this
inventory while running

00:09:26.100
00:09:28.510
my ansible ad-hoc comments or
playbooks.

00:09:28.500
00:09:32.110
Then what I have to do one thing is I
can update here.

00:09:32.100
00:09:36.600
Otherwise while running your
commands there itself we can

00:09:36.600
00:09:39.910
provide your required inventory file.

00:09:39.900
00:09:41.910
Now. I don't want to work with this
inventory.

00:09:41.900
00:09:44.410
Now. What about the inventory you
are providing on your command.

00:09:44.400
00:09:47.900
On your command line that inventory
will be used by your

00:09:47.900
00:09:51.800
ansible now compared to this value
the command line inventory
00:09:51.800
00:09:54.710
has the highest priority.

00:09:54.700
00:09:57.500
Right? Now. I want to check I want to
check.

00:09:57.500
00:10:05.210
What is the uptime for my localhost.

00:10:05.200
00:10:07.000
[corrective speech]

00:10:07.000
00:10:09.910
[no audio]

00:10:09.900
00:10:12.910
So guys we need to provide. After
providing inventory,

00:10:12.900
00:10:16.300
we need to provide here group or
server or groups or multiple

00:10:16.300
00:10:18.010
groups or multiple servers.

00:10:18.000
00:10:21.000
So as of now in our group, we have
only one server, sorry

00:10:21.000
00:10:22.110
in our inventory.

00:10:22.100
00:10:26.000
We have only one server I can provide
either all or I can

00:10:26.000
00:10:28.200
also write simply your server name.

00:10:28.200
00:10:31.510
[no audio]

00:10:31.500
00:10:36.500
Right. Localhost fine now it is going to
work.

00:10:36.500
00:10:39.210
[no audio]

00:10:39.200
00:10:44.300
Right. So guys now if we observe. Let
me write.

00:10:44.300
00:10:45.100
Let me see.

00:10:45.100
00:10:48.110
What are the commands we executed.
00:10:48.100
00:10:51.010
Oh history.

00:10:51.000
00:10:55.010
See, this is the one of the command
we executed.

00:10:55.000
00:10:56.400
I think we explore from here.

00:10:56.400
00:10:59.500
Yeah, this is the one of the command
we executed.

00:10:59.500
00:11:04.210
[no audio]

00:11:04.200
00:11:06.210
So let me write it them first.

00:11:06.200
00:11:14.200
So we did one time ansible all -m ping.
Then ansible db web_

00:11:14.200
00:11:28.510
servers - m ping or ansible db
web_servers - m shell module

00:11:28.500
00:11:38.100
-a uptime. Right. Same way you can
provide you can find RAM

00:11:38.100
00:11:39.900
usage using this command, right?

00:11:39.900
00:11:42.310
[no audio]

00:11:42.300
00:11:48.100
Now. Just after the different things
here and ansible -m.

00:11:48.100
00:11:51.110
I we provided some prod inventory file.

00:11:51.100
00:11:54.600
Then we have taken a required
module and we executed the

00:11:54.600
00:11:58.400
command like of time of course you
can also execute.

00:11:58.400
00:12:00.410
[no audio]

00:12:00.400
00:12:02.800
Any module connects good as of now
just I am taking very
00:12:02.800
00:12:04.710
simple things.

00:12:04.700
00:12:06.700
So that you can understand first of all
your answers will

00:12:06.700
00:12:09.010
or her command syntax.

00:12:09.000
00:12:14.700
Now. If you observe. First we execute
like a ping second.

00:12:14.700
00:12:16.400
We executed like a shell module.

00:12:16.400
00:12:18.410
[no audio]

00:12:18.400
00:12:22.600
Right. Then third we executed our
shell model with different

00:12:22.600
00:12:27.500
inventory. Now. By observing all these
three I can create

00:12:27.500
00:12:38.700
a simple ansible ad-hoc command
syntax. So what is that after

00:12:38.700
00:12:42.210
That? First of all, you need to provide
by default ansible

00:12:42.200
00:12:47.200
then in case if we don't want to work
with default inventory,

00:12:47.200
00:12:49.500
then you can provide your required
inventory while running

00:12:49.500
00:12:51.100
you ad-hoc commands are playbooks.

00:12:51.100
00:12:54.010
That's why this is an optional.

00:12:54.000
00:12:56.000
I'm burning inside of it square
brackets.

00:12:56.000
00:12:58.900
There is an optional then here.

00:12:58.900
00:13:03.410
You need to write server name.
00:13:03.400
00:13:07.710
Or you can provide some groups.

00:13:07.700
00:13:13.900
Suppose let us say group 1 group 2.
Something like that, but

00:13:13.900
00:13:17.300
no need to provide all you can provide
only one server or

00:13:17.300
00:13:21.200
one group or multiple groups or
servers and groups combination.

00:13:21.200
00:13:25.500
But all things you have to provide we
have to separate with:

00:13:25.500
00:13:28.300
see that I separated server name with
the colon then group

00:13:28.300
00:13:32.800
1: with group to make sure that here
you have to provide

00:13:32.800
00:13:36.600
any server name, which is there in this
inventory file.

00:13:36.600
00:13:40.310
If you are not providing this in the
default inventory file.

00:13:40.300
00:13:44.400
Server name you can provide only one
server, or you can provide

00:13:44.400
00:13:47.600
multiple servers make sure that they
are going to support

00:13:47.600
00:13:51.700
with you can provide multiple groups
and again groups you

00:13:51.700
00:13:54.500
have to supply it with colon or
combination of servers and

00:13:54.500
00:13:57.500
groups, but all things you have to
supply it with:

00:13:57.500
00:14:01.010
that's it. Then -m module.
00:14:01.000
00:14:02.700
What is your required module?

00:14:02.700
00:14:04.300
So how you can understand?

00:14:04.300
00:14:07.900
What is the model you how to take
based on task?

00:14:07.900
00:14:10.310
Which task you have to execute on
your manage

00:14:10.300
00:14:14.210
nodes same based on that you have
to select your module.

00:14:14.200
00:14:17.610
And if you observe ping module is not
having any arguments,

00:14:17.600
00:14:20.110
but she'll module is consist of some
argument.

00:14:20.100
00:14:23.400
So sometimes you may have
arguments.

00:14:25.900
00:14:30.310
Right. And sometimes you may not
have argument.

00:14:30.300
00:14:31.500
That's why this is an optional.

00:14:32.900
00:14:41.110
Right. So guys, this is the simply your
ansible or ad-hoc command syntax andible.

00:14:41.100
00:14:43.700
If you don't want to use default
inventory, then just mention

00:14:43.700
00:14:46.200
your inventory if you want to use
default inventory, don't

00:14:46.200
00:14:47.610
use this.

00:14:47.600
00:14:52.200
And the server or group or multiple
groups multiple servers

00:14:52.200
00:14:55.210
with: - yum your require module name.
00:14:55.200
00:14:58.200
So some models may have argument
some models may not have

00:14:58.200
00:15:02.100
arguments but how you can
understand which more good which

00:15:02.100
00:15:04.710
module consists of which argument
right?

00:15:04.700
00:15:09.210
Nothing is there let me open my
ansible controller.

00:15:09.200
00:15:14.100
First of all, I'm running simply and
super doc - l so which

00:15:14.100
00:15:17.300
is going to list your all modules which
are there with your

00:15:17.300
00:15:20.500
ansible just to press enter so that you
can see different

00:15:20.500
00:15:26.000
modules. The each module purpose is
different suppose if

00:15:26.000
00:15:30.410
you want to work with AWS, there are
some AWS modules, right?

00:15:30.400
00:15:36.700
So let me enter q, so actually there
are around 2800

00:15:36.700
00:15:39.800
plus modules are there with your
ansible as of now in future

00:15:39.800
00:15:46.010
they're going to increase See 2834
modules are there but don't worry.

00:15:46.000
00:15:49.000
You don't need to learn all the
modules based on the area

00:15:49.000
00:15:51.500
where you're going to apply your
ansible based on that.
00:15:51.500
00:15:54.910
You have to learn your modules.

00:15:54.900
00:15:57.800
But once if you know how to use some
to three models and

00:15:57.800
00:16:00.500
is very easy to work with any one of
the model because they're

00:16:00.500
00:16:03.900
here. But here I will go with step-by-
step.

00:16:03.900
00:16:05.500
I will start with simple models.

00:16:05.500
00:16:07.500
Then I will go and work with multiple.

00:16:07.500
00:16:11.600
I mean complex modules right
suppose just assumed that.

00:16:11.600
00:16:14.510
[no audio]

00:16:14.500
00:16:16.600
I know one of the module called.

00:16:19.200
00:16:23.910
[corrective speech]

00:16:23.900
00:16:25.700
Let me grab shell.

00:16:25.700
00:16:28.710
[no audio]

00:16:28.700
00:16:31.010
Yes, we have with the shell different
things.

00:16:31.000
00:16:33.510
If you want to work with Windows, you
have to use this module

00:16:33.500
00:16:36.200
if you want to work execute any
modules on your targets,

00:16:36.200
00:16:37.400
you have to use shell module.

00:16:37.400
00:16:40.910
[no audio]
00:16:40.900
00:16:43.910
Right, if you want to work with
VMware, something like that

00:16:43.900
00:16:49.210
suppose. I want to know how to use
shell module then simply

00:16:49.200
00:16:51.500
ansible doc - l shell module.

00:16:51.500
00:17:02.510
[corrective speech]

00:17:02.500
00:17:11.108
Sorry shell, see that. In detail
information, is there here?

00:17:11.098
00:17:16.800
How to use your ansible shell module.
Right, so don't worry

00:17:16.800
00:17:18.310
just observe that as of now.

00:17:18.300
00:17:20.300
So I will go with step-by-step so that
you can understand

00:17:20.300
00:17:23.400
very clearly how to use different
modules in different scenarios

00:17:23.400
00:17:25.300
with different arguments.

00:17:25.300
00:17:27.310
[no audio]

00:17:27.300
00:17:30.210
No, I want to show you one more
thing.

00:17:30.200
00:17:39.210
So we ran commands like ansible all -
m, let's say shell uptime.

00:17:39.200
00:17:41.300
And you're getting your up time for all
your servers which

00:17:41.300
00:17:43.099
are there with your inventory file.

00:17:43.500
00:17:47.510
Now. I want to get RAM usage of all
the servers which are there
00:17:47.500
00:17:49.910
my default inventory. Yes.

00:17:49.900
00:17:54.900
I am getting now to tasks you are
executing with two different

00:17:54.900
00:17:58.300
at all commands, but I want to execute
these two tasks with

00:17:58.300
00:18:00.910
one command.

00:18:00.900
00:18:02.810
Then you have to write a playbook.

00:18:02.800
00:18:06.010
So let me show you a simple playbook
called this one.

00:18:06.000
00:18:08.000
So if you have there, don't worry about
syntax how you are

00:18:08.000
00:18:12.000
going to write just I use one module
here and I'm using a

00:18:12.000
00:18:16.600
time and one more module, but here
I'm using free -m. Now

00:18:16.600
00:18:22.800
if I run this. Right.

00:18:22.800
00:18:23.800
I'm excluding that Playbook.

00:18:23.800
00:18:26.710
Now you are going to get now.

00:18:26.700
00:18:28.300
Uptime for all three servers.

00:18:28.300
00:18:32.000
So this is RAM usage and uptime for
all your three servers

00:18:32.000
00:18:33.510
with server wise.

00:18:33.500
00:18:36.610
So that is the advantage with
playbooks. Right.

00:18:36.600
00:18:40.300
So guys first if you know how to work
with other commands,
00:18:40.300
00:18:43.900
then you can write playbooks and it is
very important to

00:18:43.900
00:18:48.210
know that how to work with ad-hoc
commands.

00:18:48.200
00:18:51.400
No, final thing is guys whenever if you
are writing your

00:18:51.400
00:18:54.000
ad-hoc command, we are saying that
module.

00:18:54.000
00:18:55.710
What is that module?

00:18:55.700
00:18:59.000
So here shell is the one module thing
is one module copy

00:18:59.000
00:19:02.410
is one module m is one module.

00:19:02.400
00:19:05.310
We have different modules.

00:19:05.300
00:19:07.610
What is this module?

00:19:07.600
00:19:12.710
So guys model nothing but predefined
program that program.

00:19:12.700
00:19:17.710
Is able to execute our task on your
manage nodes.

00:19:17.700
00:19:19.200
Actually that is a simple program.

00:19:19.200
00:19:21.300
But you do need to write that program
already program has

00:19:21.300
00:19:24.000
written by someone else it is there
with your answer will

00:19:24.000
00:19:26.410
just use that.

00:19:26.400
00:19:29.600
So whenever if someone asked what
is a module you have to
00:19:29.600
00:19:32.700
say that model is nothing but is simply
a program that is

00:19:32.700
00:19:34.600
useful to execute a task.

00:19:34.600
00:19:37.700
So based on our required tasks, we
have to select required

00:19:37.700
00:19:45.400
module. So all modules you can see
here ansible doc - l

00:19:45.400
00:19:49.010
here you can see all modules.

00:19:49.000
00:19:51.200
Just press enter and you can go and
see.

00:19:51.200
00:19:53.310
[no audio]

00:19:53.300
00:19:57.010
Right. So we will see a lot of modules
while going forward.

00:19:57.000
00:20:01.200
Okay, so before going to work with
your ad-hoc commands you

00:20:01.200
00:20:02.800
need to remember this syntax.

00:20:02.800
00:20:06.010
[no audio]

00:20:06.000
00:20:09.700
We clear so I will post this syntax in
the description part

00:20:09.700
00:20:10.400
of this video.

00:20:10.400
00:20:12.300
Please try to use this syntax guys.

00:20:12.300
00:20:14.810
And this is very simple syntax.

00:20:14.800
00:20:19.810
We have some more options need to
include for this command.

00:20:19.800
00:20:23.900
But while going forward based on
requirement, I will add
00:20:23.900
00:20:26.700
one by one so that you will get perfect
idea about your answer

00:20:26.700
00:20:28.410
below dot command.

00:20:28.400
00:20:31.800
Right. And one important point is your
ad-hoc commands

00:20:31.800
00:20:36.700
or always consists of main important
thing one is targets

00:20:36.700
00:20:38.510
and one is module.

00:20:38.500
00:20:41.410
So on which target you're going to
work with your ansible.

00:20:41.400
00:20:42.900
And what is the task based on that?

00:20:42.900
00:20:45.900
You are module these two are the
important things with your

00:20:45.900
00:20:48.810
ansible ad-hoc commands. Right.

00:20:48.800
00:20:52.900
So guys sometimes ad-hoc
commands are also helpful instead

00:20:52.900
00:20:56.910
of playbooks suppose if I want to stop
all my servers.

00:20:56.900
00:20:59.900
I don't want to write a playbook simply
I can use on simpler

00:20:59.900
00:21:02.800
command and I can stop or I can
restart my servers.

00:21:02.800
00:21:04.810
[no audio]

00:21:04.800
00:21:09.710
See suppose if I want to list a files in
the current location.

00:21:09.700
00:21:12.200
I can run simply ls no need to write a
shell script and no
00:21:12.200
00:21:14.900
need to exclude it suppose if I want list
get what I

00:21:14.900
00:21:17.010
have to do VI.

00:21:17.000
00:21:26.700
So before that I need to find out my.
Okay, I need to write

00:21:26.700
00:21:30.700
simply some test dot sh already we
have here.

00:21:30.700
00:21:32.210
Let me delete them. Then.

00:21:32.200
00:21:35.100
I have to write a list and I have to save
it and I need to

00:21:35.100
00:21:39.800
run test.sh. No use, know if you want
to run only one command.

00:21:39.800
00:21:42.810
Why should we write a shell script that
I can run?

00:21:42.800
00:21:46.200
So even with your ansible also
whenever if you want to exclude

00:21:46.200
00:21:49.810
s single task simple task, no need to
write a play book.

00:21:49.800
00:21:54.010
That's why ants will play ansible or
commands are also important.

00:21:54.000
00:21:57.910
to work with your managed nodes.
Right.

00:21:57.900
00:22:00.400
Okay guys, thank you for watching this
video and make sure

00:22:00.400
00:22:03.700
that this is simply ansible or command
syntax and you need

00:22:03.700
00:22:13.546
to remember this. Okay. Bye
Transcript
00:00:00.000
00:00:02.400
Friends here.

00:00:02.400
00:00:05.400
We are going to discuss about how
ansible works.

00:00:05.600
00:00:09.800
I mean whenever if you run ansible or
commands or playbooks

00:00:09.800
00:00:13.200
how they are going to execute on your
managed node through

00:00:13.200
00:00:14.100
your ansible.

00:00:15.400
00:00:19.400
So before going to work with that, let
me show you your ansible

00:00:19.400
00:00:21.000
simple architecture already.

00:00:21.000
00:00:24.900
We know this right now assume that
we are going to execute
00:00:24.900
00:00:29.300
one simple or Holcomb and then
whenever if you type this

00:00:29.300
00:00:34.200
on your command line, and if you
enter how your ansible is

00:00:34.200
00:00:38.600
going to execute this on your manager
nodes their subs are

00:00:38.600
00:00:43.000
here. So whenever if you run your ad
hoc command or Playbook

00:00:43.000
00:00:46.500
first, your ansible will look into ansible
dot CFG file.

00:00:46.700
00:00:49.400
And from this it will get some
configuration details.

00:00:49.400
00:00:52.500
Let's say one of the information is your
inventory file location.

00:00:54.000
00:00:57.600
Now after getting inventory file
location based on the servers,

00:00:57.600
00:01:00.800
which you are mentioning in your ad
hoc command or while

00:01:00.800
00:01:03.800
going forward in Playbook based on
that.

00:01:04.099
00:01:08.900
It will get respect to servers IPS from
your inventory file.

00:01:10.000
00:01:13.300
Then after getting inventory IPS from
your inventory file,

00:01:13.500
00:01:17.600
maybe eyepiece or host names or
fqdn names then immediately

00:01:17.600
00:01:22.800
your ansible will establish SSH
connection with your all
00:01:23.000
00:01:25.000
managing nodes parallelly.

00:01:27.100
00:01:30.300
So after that, whatever the command
you are passing here,

00:01:30.300
00:01:32.200
whatever the module you are passing
here.

00:01:32.800
00:01:38.300
Then that module will be copied to
Oliver managed nodes.

00:01:38.300
00:01:38.700
Again.

00:01:38.700
00:01:43.700
This is also parallel or this module will
push into your

00:01:44.000
00:01:45.200
remote nodes.

00:01:46.300
00:01:49.900
So after questioning your particular
tasks module into your

00:01:49.900
00:01:54.600
remote nodes your answer will
exclude them over SSH on your

00:01:54.600
00:01:59.900
managed nodes only be clear your
tasks or executing on your

00:01:59.900
00:02:06.200
manager nodes only then once the
task is completed then whatever

00:02:06.200
00:02:08.000
the module you push.

00:02:08.000
00:02:11.199
I mean your ansible engine push it into
your managed nodes

00:02:11.500
00:02:13.000
that will be removed.

00:02:13.699
00:02:16.500
So this is the way how your answers
will is going to work?

00:02:17.600
00:02:20.300
So, you know model is nothing but
simply a python script
00:02:21.200
00:02:24.200
that python script will push it into your
all managed nodes.

00:02:24.500
00:02:27.200
Then that script will exclude on your
managed node itself

00:02:27.300
00:02:31.700
over SSH then once it is done then
whatever The Pusher program

00:02:31.700
00:02:35.500
will be I mean module will be there on
your manager nodes

00:02:35.500
00:02:36.500
that will be removed.

00:02:37.700
00:02:41.700
Now you may get down whatever the
module we have that model

00:02:41.700
00:02:44.200
your ansible is going to push into all
your managed nodes

00:02:44.200
00:02:46.300
right then where it will store.

00:02:49.300
00:02:51.500
Now see that before going to that.

00:02:51.500
00:02:54.600
Let me open my ansible engine now.

00:02:54.600
00:02:58.000
I have different servers with a different
groups.

00:02:58.100
00:03:01.000
You can execute On All or maybe
anyone of that.

00:03:01.300
00:03:05.900
Let me execute on all and I am going
to suppose a shell module

00:03:06.300
00:03:08.000
to work suppose simply up time.

00:03:08.800
00:03:14.400
So before going to run these let me
open my One of the manager

00:03:14.400
00:03:18.500
node. Let me connect with that
because I want to show you
00:03:18.500
00:03:22.900
where the ansible modules are going
to copy to your remote

00:03:22.900
00:03:24.800
nodes. It's very very important.

00:03:28.800
00:03:33.800
now let me login into one of them.

00:03:33.800
00:03:34.700
I managed server.

00:03:34.700
00:03:37.200
You can also login into all manage
servers and we can see

00:03:37.200
00:03:42.800
that so we are running our playbooks
or a dog commands through

00:03:43.400
00:03:46.400
and submenus the right now, let me
enter into that.

00:03:47.800
00:03:51.900
Now see that as of now, these are the
directories under my

00:03:52.700
00:03:58.700
answered mean home be clear home
answered mean home or with

00:03:58.700
00:04:02.000
what user you're running your rock
commands that user home

00:04:02.700
00:04:05.900
now. I am coming to our ansible
engine and here I am going

00:04:05.900
00:04:06.300
to run.

00:04:07.500
00:04:12.400
so once if you run it is going to
execute your tasks on your

00:04:12.400
00:04:13.600
respect to notes.

00:04:14.000
00:04:19.100
Just come back here and let let's say
LS - A seedot ansible

00:04:19.100
00:04:20.300
has been created.
00:04:21.000
00:04:21.200
Now.

00:04:21.200
00:04:23.800
Let me see the that is structure of your
ansible.

00:04:24.500
00:04:28.100
We have temp in that see by default.

00:04:28.100
00:04:29.700
Your ansible has been created.

00:04:31.100
00:04:33.800
And in that Temple has been created.

00:04:33.800
00:04:37.200
Anyway, as of now, you don't have any
content into this actually

00:04:37.200
00:04:41.000
whenever if you run your auto
commands or Playbook those

00:04:41.700
00:04:44.700
Playbook or Rock'em and they are
depending on modules.

00:04:44.700
00:04:49.400
So that model will be pushed into this
location by default.

00:04:49.400
00:04:51.100
It will be pushed into this location.

00:04:51.300
00:04:52.800
Of course, you can also change this.

00:04:52.800
00:04:56.000
But as of now we are going to work
with this default location.

00:04:57.100
00:05:00.800
So under user home, there will be Dot
ansible.

00:05:00.900
00:05:05.800
Be created into that template directory
will be created in

00:05:05.800
00:05:10.100
that your models will be copied and
those models are python.

00:05:11.100
00:05:13.900
That's why we need actually python on
remote nodes in case
00:05:13.900
00:05:17.200
if you don't have python how to work
we will see for timing

00:05:17.200
00:05:19.100
assuming that all servers are having
python.

00:05:19.700
00:05:21.600
I mean all manage servers fine.

00:05:22.400
00:05:26.700
So once if modules are copied into
this location, then you

00:05:26.700
00:05:30.300
are ants will exclude them and once
task is done then they

00:05:30.300
00:05:34.400
are removing but in case if you want to
see there is a one

00:05:34.400
00:05:39.600
flag you can set that flag so that your
modules won't delete

00:05:39.600
00:05:40.800
on your manager.

00:05:41.000
00:05:45.700
notes Now let me run this ansible
keep remote files equals

00:05:45.700
00:05:48.500
to 1 I am enabling this option and I am
running.

00:05:50.600
00:05:54.400
Now go to your manager node now
see that.

00:05:55.600
00:06:00.300
Based on your task directory will be
created then move into

00:06:00.300
00:06:05.700
that. So you guys where we are
answerable them based on suppose.

00:06:05.700
00:06:07.900
If you run two three tasks through two
three directories

00:06:07.900
00:06:13.300
will be created now in this there is a
module python script.
00:06:13.700
00:06:15.100
So whatever the module you are
pushing.

00:06:15.100
00:06:18.100
No, I mean your hands will Union is
pushing to manager nodes

00:06:18.200
00:06:21.900
that is this module and this module will
exclude here and

00:06:21.900
00:06:24.700
that result will send back to your
control node.

00:06:25.600
00:06:27.900
So guys, this is very very important.

00:06:30.400
00:06:33.700
So if you want to delete them by
default, don't use this

00:06:33.700
00:06:39.400
option. And simple keep remote files
equals to 1 but just

00:06:39.400
00:06:44.100
for our Clarity in which location your
modules or push how

00:06:44.100
00:06:49.000
they are going to keep that files that is
structure for that.

00:06:49.000
00:06:51.300
I mentioned this so that you can able
to see them.

00:06:53.600
00:07:00.200
Right now so our clear idea is ansible
engine is pushing

00:07:00.200
00:07:05.300
pushing modules to your remote
nodes based on your task that

00:07:05.300
00:07:07.900
model nothing but simply a Python
program that program will

00:07:07.900
00:07:09.600
execute on your remote nodes.

00:07:10.000
00:07:14.300
But from which location it is executing
under user home dot
00:07:14.300
00:07:19.100
ansible under the temp based on that
one directory into that.

00:07:19.200
00:07:21.000
It will push your module.

00:07:23.600
00:07:28.300
Fine and one more thing whenever
you are answerable is pushing

00:07:28.500
00:07:31.500
your modules or whenever it is
executing your push through

00:07:31.500
00:07:33.200
modules on your managed nodes.

00:07:33.700
00:07:35.400
Everything is a parallel process.

00:07:36.800
00:07:38.400
Is it really parallel or serial?

00:07:39.500
00:07:42.900
How we can understand that let me
show you with an example

00:07:42.900
00:07:45.700
so that you will get clearer idea
suppose.

00:07:45.700
00:07:50.600
I am running simply ansible all - em
some shell argument.

00:07:51.000
00:07:53.800
I am writing simply sleep five seconds.

00:07:54.600
00:07:58.500
Then Echo High just for our
understanding purpose.

00:07:58.500
00:07:59.800
I am taking just run it.

00:08:02.100
00:08:06.300
See you are going to get your output
at a time for all servers.

00:08:06.400
00:08:08.000
Just observe your thermal output,
right?

00:08:10.100
00:08:12.600
You're going to get your entire output
3 servers or briquette.
00:08:12.600
00:08:14.900
I'm that's why this is parallel.

00:08:15.900
00:08:19.200
Maybe you're not believing this but if
you want to see that

00:08:20.100
00:08:23.200
in your ants Bill Dot CFG file, right?

00:08:23.800
00:08:25.200
There is a Forks Valium.

00:08:26.100
00:08:28.400
So by default you don't have this I
added this.

00:08:30.100
00:08:32.700
In your suppose, if you go with your
answer will installation

00:08:32.700
00:08:33.799
with the m command.

00:08:33.799
00:08:36.100
You can see in our ansible DOT CFG
file.

00:08:36.100
00:08:36.900
Let me show you.

00:08:39.299
00:08:45.400
ansible CFG sample so that you can
understand.

00:08:51.000
00:08:52.200
sample ansible.

00:08:52.200
00:08:56.400
CFG file Okay, whoops.

00:09:08.300
00:09:09.200
Yeah, see here.

00:09:10.200
00:09:13.900
So in our in our sin to A7, we have
seen that there are some

00:09:13.900
00:09:16.700
default values which they commented
right now.

00:09:16.700
00:09:19.500
One of the value is for Subs over here.

00:09:20.800
00:09:25.900
Folks it goes to Phi that means by
default ansible will execute
00:09:25.900
00:09:28.500
a task on Phi servers at a time.

00:09:29.500
00:09:30.900
That means parallely.

00:09:30.900
00:09:35.100
It will execute on Phi servers suppose
if you have some tools

00:09:35.100
00:09:38.300
are worse then how your answer is
going to execute.

00:09:38.800
00:09:43.200
So it will execute in one go on fi
servers in second go on

00:09:43.200
00:09:46.000
file servers and you have two more
servers.

00:09:46.000
00:09:49.400
So in three goes it is going to
complete your task on your

00:09:49.400
00:09:50.200
to all servers.

00:09:50.700
00:09:54.500
But if you want to execute on all to all
servers at a time,

00:09:54.500
00:09:58.700
what you have to do is you need to
make this value as to

00:09:58.700
00:10:01.600
all. So when you have to make it as a
two ball if you have

00:10:01.600
00:10:04.000
to all servers and if you want to
execute your tasks and

00:10:04.000
00:10:05.500
all tools are worse at a time.

00:10:05.600
00:10:09.100
They need to make this as a tool
suppose if I make it as

00:10:09.100
00:10:12.900
a 1 means even though if your
hundred servers are one server
00:10:12.900
00:10:16.300
or two servers it is going to execute
serially one by one

00:10:16.800
00:10:19.300
now. Let us assume that if you have
some threes are words

00:10:19.500
00:10:22.600
it is going to execute in first go on one
server in second

00:10:22.600
00:10:25.600
go on second server in third go on one
more server.

00:10:25.700
00:10:29.100
So it is going to execute a complete
your task on three goes.

00:10:31.500
00:10:33.400
Now, let me show you this now.

00:10:33.400
00:10:35.900
If you want to execute your task
parallely.

00:10:35.900
00:10:38.800
Now, you need to make it as a value
for x value equals to

00:10:38.800
00:10:44.100
1. If you delete this entire line by
default ansible will

00:10:44.100
00:10:48.200
execute in case if you don't see this
value in your configuration

00:10:48.200
00:10:51.900
file by your ansible ansible will
execute on file servers

00:10:51.900
00:10:52.400
at a time.

00:10:53.300
00:10:54.400
Now same command.

00:10:54.400
00:10:58.400
I am running now see the result you
are going to get your

00:10:58.400
00:11:00.900
output first on one server after 5
Seconds.
00:11:02.700
00:11:06.000
Then you're going to get your output
on next server after

00:11:06.000
00:11:10.200
5 seconds, but previously with Force
equals to Phi or even

00:11:10.200
00:11:13.500
if you delete that by default you are
getting output on all

00:11:13.500
00:11:14.000
server socket.

00:11:14.000
00:11:16.800
I'm but now you are not getting see
that now one by one you

00:11:16.800
00:11:19.300
are getting that means your answer
will is executing now

00:11:19.300
00:11:21.400
your task on your managed node C.

00:11:21.400
00:11:21.900
Really?

00:11:24.900
00:11:30.900
Right and one more thing see we are
saying that ansible is

00:11:30.900
00:11:34.700
pushing modules into your managed
nodes.

00:11:36.000
00:11:38.900
Right and you are managed nodes or
not trying to connect

00:11:38.900
00:11:39.700
with your engine.

00:11:39.700
00:11:42.200
Your engine only is going to connect
with your manager nodes.

00:11:44.600
00:11:45.000
Right.

00:11:45.300
00:11:50.400
So your engine is pushing that way
ansible follows push mechanism.

00:11:50.400
00:11:53.700
If you go with the chef that is following
pull mechanism
00:11:53.900
00:11:55.200
managed nodes itself.

00:11:55.200
00:11:58.400
They are trying to pull your modules in
chef.

00:11:59.300
00:12:02.900
But in ansible ansible is engine is
going to push them.

00:12:03.100
00:12:05.100
That's why this is called push
mechanism.

00:12:06.400
00:12:09.900
And one more thing if it is a pull
mechanism, you shouldn't

00:12:09.900
00:12:12.800
you should have some agent here or
some software here to

00:12:13.300
00:12:15.900
pull this modules into their manager
nodes.

00:12:17.000
00:12:18.500
Right, but we don't have that.

00:12:18.700
00:12:20.600
Our answer will engine will take care
everything.

00:12:20.800
00:12:24.300
That's why we are not installing any
software or agent on

00:12:24.300
00:12:25.600
your remote nodes.

00:12:25.800
00:12:29.500
That's why this is called Agent less
architecture.

00:12:32.300
00:12:35.700
Right, so guys you need to understand
here.

00:12:37.200
00:12:51.200
simply ansible follows push
mechanism then ansible is a key

00:12:51.200
00:12:53.900
agent less architecture.
00:12:58.200
00:13:02.300
Right and one more thing if you want
to make it as a serial

00:13:02.300
00:13:06.100
execution basically ansible executes.

00:13:08.100
00:13:26.200
ask on managed nodes parallelly but
you can make it as serial

00:13:26.500
00:13:37.700
by be clear by keeping folks value
equals to 1 in ansible

00:13:37.700
00:13:43.100
dot CFG file And while going forward
in case if you're going

00:13:43.100
00:13:46.200
to work with playbooks in playbooks
itself, we can mention

00:13:47.300
00:13:49.700
for its value instead of parallel.

00:13:49.700
00:13:51.000
You can exclude in cereal.

00:13:52.600
00:13:53.000
Right.

00:13:54.200
00:13:57.700
Okay guys, this is the way how your
ansible is going to work

00:13:57.700
00:13:59.500
with your managed nodes.

00:13:59.500
00:14:01.200
It's very very important thing.

00:14:02.800
00:14:03.100
Right.

00:14:03.100
00:14:06.100
So finally from this concept you have
to understand that

00:14:06.100
00:14:10.900
ansible follows push mechanism and it
is agentless and by

00:14:10.900
00:14:15.900
default ansible will execute a task on
five servers parallely,
00:14:16.500
00:14:19.900
but if you want to execute your tasks
on number of servers

00:14:19.900
00:14:22.500
require number of servers parallel at a
time, you need to

00:14:22.500
00:14:26.300
make it even more Force value new
ansible DOT CSV file.

00:14:28.100
00:14:28.600
That's it.

00:14:29.300
00:14:29.600
Okay.

00:14:30.000
00:14:30.500
Okay guys.

00:14:30.500
00:14:31.800
Thank you for watching this video.
Transcript
00:00:00.000
00:00:06.557
[no audio] Friends here, we are going
to discuss how to transfer a file using Ansible Ad-hoc commands.

00:00:06.557
00:00:11.000
So, simply assume that you're having
Ansible engine here and

00:00:11.000
00:00:14.400
you are going to manage some
number of nodes using the Ansible engine.

00:00:14.400
00:00:23.010
Now, our task is, you have some file
on your Ansible engine and you need to transfer that file or you
need

00:00:23.000
00:00:30.710
to copy that file from your Ansible
engine to your required nodes, maybe all nodes or maybe some
of the nodes.

00:00:30.700
00:00:34.997
But be clear we are not copying a file
from one node to another node.
00:00:34.997
00:00:39.539
So, this part we'll discuss while
working with playbooks.

00:00:39.539
00:00:50.249
For time being we are going to
transfer a file from your Ansible engine to you are required nodes
and that we are going to achieve using your Ad-hoc commands.

00:00:50.239
00:00:53.943
So, guys finally what is our task?
Transfer a file.

00:00:53.943
00:00:58.500
So, we know that, in Ansible for each
and every task there is a separate

00:00:58.500
00:01:02.400
module now for your requirement for
your task,

00:01:02.400
00:01:09.210
there is a copy module, now you can
transfer your files using copy module.

00:01:09.200
00:01:12.900
Now, before going to see about your
copy module, let me show

00:01:12.900
00:01:17.520
you once again our simple, basic Ad-
hoc command syntax.

00:01:17.510
00:01:22.100
Already we have seen this in our
previous videos, right in case if

00:01:22.100
00:01:25.700
you want to work with any other
inventory, then you have

00:01:25.700
00:01:29.200
to mention hyphen "i" with your
inventory file, but if you want

00:01:29.200
00:01:31.700
to work with the default inventory,
which is there in your

00:01:31.700
00:01:37.310
Ansible.CFG file at the time you
wanted to mention your inventory file location.

00:01:37.300
00:01:42.443
Right, so simply Ansible some servers
or groups or combination of servers and groups.
00:01:42.443
00:01:48.710
Then hyphen "m" you're required
module then hypen "a" for this module, whatever the arguments
you're having,

00:01:48.700
00:01:50.444
you have to mention those arguments.

00:01:50.444
00:01:59.713
Fine now, let me show you the simple
Syntax for your copy module.

00:01:59.713
00:02:08.810
So simply: ansible, your required
group from your inventory file hyphen "m" copy hypen "a"
arguments.

00:02:08.800
00:02:12.699
So, here I have taken source and
destination arguments why

00:02:12.699
00:02:15.000
we need the source and destination
means you are going to

00:02:15.000
00:02:21.510
transfer or copy a file from your
Ansible engine to respective nodes or required nodes.

00:02:21.500
00:02:26.410
So, whenever if you want to copy or
transfer a file you should have some source and destination.

00:02:26.400
00:02:32.568
That's why you have as of now simply
source on destinations or the arguments for your copy module.

00:02:32.558
00:02:47.010
And anyway before going to use this
just to go to Google and simply type Copy module then you are
going to get a

00:02:47.000
00:02:51.288
URL just after the very first URL that is
from official documentation.

00:02:51.288
00:03:00.209
Just click on that, and go through that
this entire page ones.

00:03:00.200
00:03:04.547
Okay, and at the last, you are going to
have some playbooks as well.
00:03:04.547
00:03:10.231
So, as of now we are not going to
work with playbooks, we are going to see only your ad-hoc
commands.

00:03:10.221
00:03:13.100
See we have different parameters
here.

00:03:13.100
00:03:17.900
If you observe here just go to top
parameters: attributes,

00:03:17.900
00:03:23.410
backup, checksum, content, decrypt,
destination, directory mode.

00:03:23.400
00:03:28.551
These are all arguments actually for
your copy module.

00:03:28.551
00:03:32.341
For timing, I am going to use some of
them so that you will get some idea.

00:03:32.341
00:03:35.607
First of all, let me open my and
Ansible engine.

00:03:35.607
00:03:38.155
Let me enter into our practice
directory.

00:03:38.155
00:03:41.448
Just let me open my inventory file.

00:03:41.448
00:03:44.311
So, in my inventory, I have three
servers with two groups.

00:03:44.311
00:03:50.555
First of all, let me check it whether
they are reachable over the network through your ansible or not.

00:03:50.555
00:03:54.466
So, simply ansible all means all is the
default group.

00:03:54.466
00:03:58.200
If you mention simply all your ansible
engine is going to

00:03:58.200
00:04:00.508
work with all the servers which are
there in your inventory.
00:04:00.508
00:04:04.900
Guys now, I'm not using hypen "i" for
inventory file location

00:04:04.900
00:04:11.609
because I want to work with the
default inventory file, which is there in your anisible.CFG.

00:04:11.600
00:04:14.100
What is there in ansible.CFG in the
current location?

00:04:14.100
00:04:19.743
Whatever the host is there from that
my ansible is going to pick my servers or groups.

00:04:19.743
00:04:26.209
Now, anyway, let me run this: ansible
all -m, ping.

00:04:26.200
00:04:30.066
So, all servers are able to reach
through the network.

00:04:30.066
00:04:39.960
Now let me run your simple ansible
copy module.

00:04:39.960
00:04:45.054
So, I want to transfer a file right, see
how I am going to do that?

00:04:45.054
00:04:48.915
Ansible, so let me take cat db

00:04:48.915
00:04:52.408
So you have two groups.

00:04:52.408
00:04:53.780
First of all, let me take only one group.

00:04:53.780
00:05:03.622
So, what I am doing is Ansible, I want
to copy some file to my DB servers.

00:05:03.622
00:05:09.927
So, let's say DB -m copy module then
- a arguments.

00:05:09.927
00:05:13.149
So, you have to mention your
arguments inside of quotations.

00:05:13.149
00:05:15.608
So, better practice is always double
quotations.
00:05:15.608
00:05:21.404
Now, let me mention source: source is
in the current location,

00:05:21.404
00:05:25.954
simply whatever the hosts file you are
having you can transfer any file.

00:05:25.954
00:05:31.478
So, I am taking in the current location,
whatever the hosts file is there that file I want to transfer

00:05:31.478
00:05:35.422
to my nodes which are there in this
group.

00:05:35.422
00:05:38.715
But, what is the destination on my
node?

00:05:38.715
00:05:41.032
I am taking simply tmp.

00:05:41.032
00:05:45.166
So, if you mention a file your content
is going to copy into that file.

00:05:45.166
00:05:49.592
If you don't mention with this name, it
will copy a file into this location.

00:05:49.592
00:05:55.891
So, let me run this first and see the
output: I'm running.

00:05:55.891
00:06:02.274
Yes, observe the output, change your
true destination see that,

00:06:02.274
00:06:07.911
with these hosts file it is going to copy
the content.

00:06:07.911
00:06:13.210
But, ours is there in the host file simply
your host file copied to temple location.

00:06:13.200
00:06:17.700
Right suppose if I want to create on
your remote node or

00:06:17.700
00:06:25.710
on your nodes with some other name,
then I can mention suppose different file name now see that.
00:06:25.700
00:06:29.004
If you mention your file name, then it is
going to copy.

00:06:29.004
00:06:34.610
Your required file source file to
destination with the your required name.

00:06:34.600
00:06:38.100
If you don't mention then into that
directory, whatever the

00:06:38.100
00:06:43.210
name you are having on your sourse
same name will be created on your remote server on your remote
server.

00:06:43.200
00:06:50.210
That's it. Now. Let me enter into your
manage node.

00:06:50.200
00:06:52.234
So, simply we have partial as
authentication.

00:06:52.224
00:06:57.127
I am entering SSH then your remote
server IP or node IP.

00:06:57.127
00:06:58.324
Then we are entering into that.

00:06:58.324
00:07:02.800
Let me move into temple location and
see that we have host

00:07:02.800
00:07:08.774
and inventory just come out from here
and here I want to show you one more thing.

00:07:08.774
00:07:13.385
I want to rerun this, now see the
output.

00:07:13.385
00:07:17.196
Change the false.

00:07:17.196
00:07:22.277
Destination is anyway you are
providing your destination

00:07:22.277
00:07:25.958
but changed false means this is not
changing any content
00:07:25.958
00:07:29.068
in the destination location in the
destination file.

00:07:29.068
00:07:31.132
What is the reason?

00:07:31.132
00:07:36.110
See, just now we copied our file into
your manager node.

00:07:36.110
00:07:40.088
Again, we are trying to copy but before
going to copy, is there

00:07:40.088
00:07:43.697
any modification in the source file?
No, if there is no modification,

00:07:43.697
00:07:45.598
why should we copy again?

00:07:45.598
00:07:50.707
So, even though if you try to copy the
same file, once again,

00:07:50.707
00:07:56.058
your Ansible won't allow that because
they were Ansible will able to find that.

00:07:56.058
00:07:59.862
already same content is there in the
remote location file.

00:07:59.862
00:08:01.403
That's why it is going to skip that.

00:08:01.403
00:08:07.591
So, this is one of the property of your
Ansible that is called idempotent.

00:08:07.591
00:08:13.310
So, idempotent means if there is no
change then your answer won't do that task.

00:08:13.300
00:08:18.909
If there is something if some changes
are there then only it will perform your task.

00:08:18.900
00:08:24.210
Now, what I am doing is let's say in
our inventory file.

00:08:24.200
00:08:26.609
I am going to add localhost as well.

00:08:26.609
00:08:29.271
Now there is a change right now.
00:08:29.271
00:08:33.850
If you try to copy your or if you try to
transfer your file

00:08:33.850
00:08:42.610
now, it will copy or it will transfer your
file to your remote server. See that change true.

00:08:42.600
00:08:47.010
Right, so whenever if there is a
change then only your content will

00:08:47.000
00:08:52.331
be copied or your file will be moved to
your remote server or manage node.

00:08:52.331
00:08:56.210
Right, if it is very first time definitely it
will copy but whenever

00:08:56.200
00:09:00.200
if you re running your ansible will find

00:09:00.200
00:09:03.400
the information about your previous
state and the current

00:09:03.400
00:09:08.391
state if both informations are same
then it won't do any execution.

00:09:08.391
00:09:18.556
That's it. Fine now, this is one way to
use your copy module.

00:09:18.556
00:09:22.201
So, source we have in your hand and
we are copying that but

00:09:22.201
00:09:26.769
I assume that let me remove all my
arguments.

00:09:26.769
00:09:30.210
I don't have a file but I want to copy,

00:09:30.200
00:09:33.374
I want to create a file on remote server
with some content.

00:09:33.374
00:09:37.708
Then you have one more argument
called content.

00:09:37.708
00:09:48.020
Now, let's say your content is "hello,
this is from copy module", that's it.
00:09:48.020
00:09:52.800
So, content just to mention single
quotations because all

00:09:52.800
00:09:55.200
we use double quotation know just
use different quotations here.

00:09:55.200
00:09:58.451
Then what is the destination?

00:09:58.451
00:10:03.229
So, in the destination is nothing, but if
you don't create

00:10:03.229
00:10:07.300
now if you don't use any file now, it will
give an error

00:10:07.300
00:10:09.000
because this is not a filename.

00:10:09.000
00:10:10.291
This is a content right?

00:10:10.291
00:10:13.822
So, previously we ran our commands

00:10:13.822
00:10:18.300
without giving your destination file
name and after giving

00:10:18.300
00:10:22.000
some destination file name, but in that
case source is a

00:10:22.000
00:10:25.300
file, but now we are not using source
we are using in place

00:10:25.300
00:10:28.956
of source some content directly create
with this information

00:10:28.956
00:10:32.810
in your remote node some file, but I
am giving I'm not giving any file name.

00:10:32.800
00:10:36.310
No, I have given simply temple
location. Not only temple location,

00:10:36.300
00:10:39.300
You can give any location, but make
sure the make sure that

00:10:39.300
00:10:42.189
that is exact path now, let me run it.
00:10:42.189
00:10:49.318
You're going to get an error cannot
use the content with the directory as a destination.

00:10:49.318
00:10:52.500
That's why if it is a content, you know
to mention your file.

00:10:52.500
00:10:55.950
Suppose I want to create a hello. txt
now run that.

00:10:55.950
00:11:02.310
Now, in destination it is going to create
Hello. txt file with this content.

00:11:02.300
00:11:06.990
Just verify that just log into your
remote server.

00:11:06.990
00:11:11.080
I mean managed node then enter into
root temp.

00:11:11.080
00:11:15.783
Now see the content in this that's it.

00:11:15.783
00:11:28.410
So, now let me come out from here.

00:11:28.400
00:11:32.711
So, now just now we came out from
your manager node.

00:11:32.711
00:11:38.210
Now, if you observe in your
documentation, right, we are having different options.

00:11:38.200
00:11:40.008
Let me go with one more option.

00:11:40.008
00:11:47.210
Suppose I'm trying to copy the same
file to your manager node, which

00:11:47.200
00:11:51.010
is there already in the manager node,
but this time content is different.

00:11:51.000
00:12:00.010
But before going to copy, I want a
backup of my previous file, which is there in your manager, you
know.

00:12:00.000
00:12:02.800
Right now you can take a backup.
00:12:02.800
00:12:06.210
So, let me take suppose.

00:12:06.200
00:12:10.010
So, already we have some Hello.txt on
your managed node, right.

00:12:10.000
00:12:14.110
That's why what I am doing is just I am
modifying the content.

00:12:14.100
00:12:20.290
Simply this is from, see that, I'm
modifying the content.

00:12:20.290
00:12:24.650
But, if you run your previous file,
whatever you have Hello.txt

00:12:24.650
00:12:26.800
in that whatever the content you're
having that content

00:12:26.800
00:12:30.936
is going to remove a new content is
going to add into that file.

00:12:30.936
00:12:35.200
But I need a backup for my previous
file if there is

00:12:35.200
00:12:44.210
a some file with hello.txt then simply
right back up equals to yes.

00:12:44.200
00:12:45.545
This is one more argument.

00:12:45.545
00:12:48.548
Let's say, let me enter.

00:12:48.548
00:12:58.210
Now, it is going to show you that
change through and what is the backup file in the temple location,

00:12:58.200
00:13:03.174
Hello.txt with you are time-stamped
has been taken a backup.

00:13:03.174
00:13:14.210
So, if you want to verify that just enter
into your manager node.

00:13:14.200
00:13:19.910
Go to temple location. Now, see that.
00:13:19.900
00:13:25.910
It has been created backup before
copying new content to your Hello.txt file.

00:13:25.900
00:13:29.001
So, if you want to see that just see
that content.

00:13:29.001
00:13:31.819
So, this is previous file content.

00:13:31.819
00:13:35.896
Now, we have been created this new
file, that's it.

00:13:35.896
00:13:44.610
Okay, so guys this is the simple way to
use your copy module to transfer a file from your current location,

00:13:44.600
00:13:49.810
I mean from your Ansible engine to
with your remote nodes, required remote nodes.

00:13:49.800
00:13:56.010
If you want to copy the same file with
all with your all servers, then you can use simply all.

00:13:56.000
00:14:01.944
Right and one more thing see for time
being I have taken root to temp.

00:14:01.944
00:14:06.310
But, I want to copy suppose I want to
create a new file with some content on my user

00:14:06.300
00:14:08.800
home on the remote node or on my
managed node.

00:14:08.800
00:14:13.010
Then what you can do is simply
Ansible, let's say DB.

00:14:13.000
00:14:15.700
DB group I'm taking but you can
provide number of servers

00:14:15.700
00:14:18.100
or number of groups or combination of
service and groups

00:14:18.100
00:14:21.710
with colon, if you remember you can
provide in this way, right?
00:14:21.700
00:14:25.048
So, as of now, I'm going to take only
simply DB group.

00:14:25.048
00:14:26.550
I want to work with DB group servers.

00:14:26.550
00:14:40.542
Now, let me copy - A content, this is
for DB servers.

00:14:40.542
00:14:50.310
Then destination so our destination I
want to take, let me take the remote server destination.

00:14:50.300
00:14:53.500
I can assume home and ans-admin
because we are going to work

00:14:53.500
00:15:03.010
with answered me in right so in the
remote server also under this location.

00:15:03.000
00:15:08.200
So I want to create any file name.

00:15:08.200
00:15:16.010
Let's say demo.txt or DB.conf file,
that's it.

00:15:16.000
00:15:18.010
Now, let me enter.

00:15:18.000
00:15:20.200
So, as of now, I am going to walk with
only one server, but

00:15:20.200
00:15:23.000
you can work with the number of
servers based on your requirement.

00:15:23.000
00:15:25.900
You can copy the content or you can
copy a file or transfer

00:15:25.900
00:15:32.910
a file with your manager notes from
your Ansible engine simply by using copy module.

00:15:32.900
00:15:36.900
Now it has been created under your
remote server in this

00:15:36.900
00:15:40.700
location with the DB.conf just enter
into your manager
00:15:40.700
00:15:45.100
node and just verify that so you are
under your user home

00:15:45.100
00:15:47.937
in the remote server manager node
just LS.

00:15:47.937
00:15:55.010
Yes, there is a DB.conf file, this is for
DB servers.

00:15:55.000
00:16:01.500
Right, fine, now, see if you observe
your information always

00:16:01.500
00:16:05.900
you are getting your terminal also in
the same line after

00:16:05.900
00:16:11.478
displaying your content, but I want to
enter this in the next line, right?

00:16:11.468
00:16:18.710
So, that's why what you have to do is,
so, where are have on the remote node manage?

00:16:18.700
00:16:21.710
No, let come out from here.

00:16:21.700
00:16:29.405
Just in the content at the end just right
/n, now see that.

00:16:29.405
00:16:35.500
Yes change true means it has been
changed.

00:16:35.500
00:16:38.294
Let me enter into remote node.

00:16:38.294
00:16:45.610
Now, see the direct deliver content
information now, your terminal is coming to next line.

00:16:45.600
00:16:49.200
So be clear whenever if you are
copying your content, so

00:16:49.200
00:16:55.410
in your content at the end just add / n,
remember /n means new line. That's it.

00:16:55.400
00:16:58.801
Okay, so guys like wise you have
different parameters here.
00:16:58.801
00:17:02.552
So, what is the group you want to give
for your copied file?

00:17:02.552
00:17:04.710
Right, what is the mode you want to
provide?

00:17:04.700
00:17:06.410
What is the owner you want to
provide?

00:17:06.400
00:17:09.510
So, you have so many things here.

00:17:09.500
00:17:12.310
So, there are some sample Playbooks
which are using by copy

00:17:12.300
00:17:15.108
module and we will discuss these
playbooks later.

00:17:15.098
00:17:22.210
But, if you want to see some of the
parameters they are you they're using some parameters.

00:17:22.200
00:17:26.288
So, all those things we will discuss
effectively while writing playbooks.

00:17:26.288
00:17:28.599
So, for time being just to get some
idea we are going to use this simple way of your copy module.

00:17:33.599
00:17:40.402
Right, okay guys. Thank you for
watching this video.
Transcript
00:00:00.000
00:00:01.800
Friends here

00:00:01.800
00:00:05.300
we are going to discuss about how to
download a file from

00:00:05.300
00:00:09.400
nodes using ansible or Hawk
command see in our previous video.

00:00:09.400
00:00:13.200
We have seen how to transfer a file
from your ansible engine

00:00:13.200
00:00:14.600
to your manager nodes.

00:00:14.900
00:00:17.900
And there we use copy module now
reverse process.

00:00:17.900
00:00:21.200
If you want to download some files
from your managed nodes
00:00:21.200
00:00:25.300
to your ansible engine how we can do
it now for this task.

00:00:25.300
00:00:26.700
We have a fetch module.

00:00:28.000
00:00:31.200
Now using fetch module you can
download your required file

00:00:31.200
00:00:36.400
from your ansible manager node to
your ansible engine node

00:00:36.400
00:00:40.400
or nodes anyway already we know the
simple Syntax for your

00:00:40.400
00:00:44.600
ansible at our Command now here
using fetch module what is

00:00:44.600
00:00:49.000
the simple and small or a command
this is the right so ansible

00:00:49.400
00:00:52.400
your group or servers or combination
of different servers

00:00:52.400
00:00:57.600
here then - em required module - A
Arguments for that.

00:00:58.100
00:01:00.700
Now here we are going to download
download means you should

00:01:00.700
00:01:02.800
have some source and destination.

00:01:02.900
00:01:07.300
So source is our managed server on
my on our manager server

00:01:07.500
00:01:12.800
some file location destination by
default in the ansible

00:01:12.800
00:01:16.500
engine some location right now.

00:01:16.500
00:01:19.300
Let me go to my controller.
00:01:21.800
00:01:24.000
So let me enter into my practice
directory.

00:01:24.000
00:01:27.700
So a how inventory and in this
inventory how some files I

00:01:27.700
00:01:29.700
am going to work with suppose DB
group.

00:01:30.300
00:01:33.100
Let's just let me check the connectivity
through your ping

00:01:33.100
00:01:36.500
module. Yes, they're able to reach
now.

00:01:36.700
00:01:40.500
So before going to download Israel
some file on your remote

00:01:40.500
00:01:41.200
servers, right?

00:01:41.300
00:01:43.700
Let me login into my first server there.

00:01:43.700
00:01:46.200
I already created a file called demo
Dot txt.

00:01:47.600
00:01:52.200
This is a Node 1 just exit from there
and let me login into

00:01:52.200
00:01:53.100
second server.

00:01:53.700
00:01:57.600
So guys if You observe here I am
providing simply SSH your

00:01:57.600
00:01:58.200
server name.

00:01:58.300
00:02:00.800
So it is without asking a password is
going to connect because

00:02:00.800
00:02:04.400
we provided password less up
indication through your keys.
00:02:06.000
00:02:09.400
Now here also I have a file but this is
this is an Ode to

00:02:10.400
00:02:14.400
and if You observe here on our
managed nodes under this home

00:02:14.400
00:02:16.300
and said mean we have a file.

00:02:16.800
00:02:19.600
So if you want to download you should
know the complete path

00:02:20.600
00:02:22.000
now just come out from there.

00:02:22.200
00:02:22.400
Now.

00:02:22.400
00:02:23.900
We are on our ansible engine.

00:02:24.200
00:02:27.800
Let me download that file and Isabel
from DB servers.

00:02:29.400
00:02:33.100
Using fetch module now, I need to
provide source and destination

00:02:33.300
00:02:35.700
so source is in this location.

00:02:36.800
00:02:38.800
We have a demo dot txt file.

00:02:39.300
00:02:43.000
So that is the source then what about
destination destination

00:02:43.000
00:02:45.800
is nothing but by default in your
ansible engine server,

00:02:46.100
00:02:48.200
so I want to download the server.

00:02:48.300
00:02:53.200
I mean managed nodes from all my
manners nodes this file

00:02:54.000
00:02:58.100
into in the current location under demo
directory.
00:03:00.700
00:03:03.500
So dot means in the current location
demo directory.

00:03:03.500
00:03:06.300
So before running this command just
observe the data structure.

00:03:06.300
00:03:09.400
I don't have any demo directory here
now, I am going to run

00:03:09.400
00:03:17.900
this. observe the output see that
change through means your

00:03:17.900
00:03:19.300
task has been executed.

00:03:20.400
00:03:24.200
And what is the Destination for your
file.

00:03:24.600
00:03:28.300
So in the current location, this is
current location If You

00:03:28.300
00:03:32.100
observe here there is a demo directory
has been created under

00:03:32.100
00:03:36.000
that with some direct is structure
based on server wise and

00:03:36.000
00:03:39.700
on the remote server, whatever the file
you have that file

00:03:39.700
00:03:42.800
has been created under home under
answered mean actual.

00:03:42.800
00:03:45.400
This is the path complete path on your
remote server.

00:03:45.400
00:03:48.900
Same data structure has been created
on your local server

00:03:48.900
00:03:49.400
as well.

00:03:50.100
00:03:52.400
I mean when you're ansible engine as
well just up.
00:03:52.500
00:03:55.800
That now previously.

00:03:55.800
00:03:57.000
We don't have any demo directory.

00:03:57.000
00:03:57.200
Now.

00:03:57.200
00:04:00.800
We have been created with your fetch
module inside of that

00:04:01.200
00:04:02.700
just observe the data structure.

00:04:04.400
00:04:08.700
Based on server wise home directory
in that and segment directory

00:04:08.700
00:04:09.900
in the demo dot exe file.

00:04:09.900
00:04:13.400
Is there so the same path actually it is
there in your remote

00:04:13.400
00:04:14.100
server as well.

00:04:14.400
00:04:15.700
So it has been created that.

00:04:17.300
00:04:17.700
Right.

00:04:17.700
00:04:20.300
Now if you want to see the content of
any server, let's say

00:04:20.300
00:04:21.100
this is the server.

00:04:22.000
00:04:24.500
Sorry under demo on this server.

00:04:25.700
00:04:28.900
Home and submit demo dot txt file has
been created.

00:04:29.200
00:04:33.800
Yes the same way your second server
information is also there.

00:04:34.400
00:04:35.400
I mean other node.

00:04:39.500
00:04:43.600
Yes, we have but guys I don't want to
create this direct
00:04:43.600
00:04:45.000
instruction. Simply.

00:04:45.200
00:04:47.700
I have provided in my command demo
directory in this demo

00:04:47.700
00:04:48.500
directory directly.

00:04:48.500
00:04:50.900
I want to create my server files.

00:04:51.600
00:04:56.200
I don't want to create these things then
see that how we

00:04:56.200
00:04:56.700
can run.

00:04:57.100
00:04:58.200
So before going to that.

00:04:58.400
00:05:00.600
Let me remove our demo directory
ones.

00:05:04.000
00:05:06.300
otherwise I will take new directory I will
keep that as it

00:05:06.300
00:05:13.800
is so now whatever the command you
have sorry command is

00:05:14.200
00:05:17.800
and so a lot of command yeah so now
I am taking new demo

00:05:18.700
00:05:22.200
and I am providing one more
argument called Flat equals to

00:05:22.200
00:05:28.500
yes but be clear you're going to get an
error the reason

00:05:28.600
00:05:35.500
I will explain you see that It has been
downloaded from this

00:05:35.500
00:05:39.600
file. I mean from this server, but here
changed false.

00:05:40.100
00:05:43.600
The reason is content is different, but
we are trying to
00:05:43.600
00:05:46.900
download into new demo directory
with the same file name

00:05:46.900
00:05:49.100
know for Server one same file name.

00:05:49.100
00:05:51.600
We are using server to we are using
same file name.

00:05:52.800
00:05:55.400
So for both manage servers, we are
trying to download with

00:05:55.400
00:05:56.300
the same file.

00:05:56.400
00:06:00.200
If the file content is same then it will be
downloaded but

00:06:00.200
00:06:04.600
the content is different now, so that's
why if the content

00:06:04.600
00:06:07.600
is same you just try with by keeping on
both.

00:06:07.600
00:06:11.000
The server's demo dot exe file content
has same but that

00:06:11.000
00:06:12.000
is not possible.

00:06:12.000
00:06:15.100
Sometimes right you may or may not
have same content on all

00:06:15.100
00:06:17.500
the manage servers in a particular
location in particular

00:06:17.500
00:06:24.500
file. If it is same no problem, if it is
different then in

00:06:24.500
00:06:28.700
this location in this location, I want to
create a demo dot

00:06:28.700
00:06:34.500
txt file by mentioning server name in
that then there is
00:06:34.500
00:06:36.700
a default variable called.

00:06:38.500
00:06:43.600
Inventory hostname don't worry about
this variable will discuss

00:06:43.600
00:06:45.900
that in detail in the next sessions.

00:06:47.300
00:06:52.600
So now what I am doing is under this
location with server

00:06:52.600
00:06:57.400
name. I want to create demo dot txt
file.

00:06:58.900
00:07:02.800
Now see the result so before going to
that just for our Clarity

00:07:02.800
00:07:05.300
purpose because already we
downloaded right?

00:07:05.300
00:07:06.700
Let me remove this file.

00:07:08.100
00:07:10.500
Anyway, even though if it is there we
are going to create

00:07:10.600
00:07:11.800
with server wise name right?

00:07:11.800
00:07:12.400
No problem.

00:07:19.400
00:07:20.700
Flat equals to S.

00:07:20.900
00:07:23.900
So, you know now the advantage with
the flat equals t as

00:07:24.100
00:07:27.000
if you don't mention flat Eco CS by
default that is know

00:07:27.300
00:07:29.700
if that is node is going to create some
directory structure.

00:07:29.800
00:07:31.800
I don't want to create that data
structure directly.
00:07:31.800
00:07:36.100
I want to download a file into this
location based on server

00:07:36.100
00:07:39.900
wise. So before going to create a
demo dot txt file.

00:07:40.100
00:07:42.900
I am creating the demo dot txt file with
server name.

00:07:43.900
00:07:47.100
See now in place of this variable with
curly braces.

00:07:47.100
00:07:49.100
I have mentioned something inventory
hostname.

00:07:49.400
00:07:54.900
So they're the respect to managed
server name will be replaced

00:07:55.100
00:07:58.400
and - demo dot txt file will be created
now just observe

00:07:58.400
00:08:00.100
that I'm running that.

00:08:01.200
00:08:04.800
See, this is the server underscore
demo dot txt.

00:08:04.900
00:08:07.000
This is one more server demo dot txt.

00:08:07.000
00:08:09.900
So where it has been created under
new demo dot directly

00:08:09.900
00:08:11.200
under new demo directory.

00:08:11.600
00:08:14.700
So we have provided in the current
location in this demo

00:08:14.700
00:08:16.900
directory. Just create based on server.

00:08:16.900
00:08:19.200
Why's your demo dot txt file content?

00:08:20.300
00:08:22.500
Right now enter into that and see the
result.
00:08:23.100
00:08:26.200
So this is the one server now.

00:08:26.200
00:08:28.100
We have one more managed node.

00:08:29.800
00:08:32.200
See the content now without any
errors.

00:08:32.200
00:08:33.500
We have been downloaded.

00:08:34.500
00:08:34.900
Right?

00:08:35.100
00:08:39.700
So guys now we are using fetch
module to download the content

00:08:39.700
00:08:42.000
to download the file from your
managed nodes.

00:08:43.700
00:08:47.900
If the file which is there on your
managed nodes if that

00:08:47.900
00:08:50.299
is same then no problem directly we
can download.

00:08:50.600
00:08:53.500
But anyway, that is not the best
practice because we have

00:08:53.500
00:08:56.000
to know the file from which server it is.

00:08:56.900
00:09:00.500
That's why while downloading you
have to mention your destination.

00:09:00.800
00:09:04.000
So if you mention only destination it is
going to download

00:09:04.000
00:09:07.000
your content to this file, but I want to
create based on

00:09:07.000
00:09:07.600
server wise.

00:09:07.600
00:09:12.200
That's why I included some syntax
here to curly braces start
00:09:12.200
00:09:13.300
and open inside.

00:09:13.400
00:09:17.000
That I have I have written inventory
host name means from

00:09:17.000
00:09:20.300
which server you are going to
download by default that server

00:09:20.300
00:09:21.800
name will be replaced.

00:09:22.500
00:09:22.700
Actually.

00:09:22.700
00:09:28.300
This is the fact or variable of your
ansible or to work with

00:09:28.300
00:09:29.300
your managed nodes.

00:09:29.600
00:09:32.100
So we'll discuss in detail about this
facts and variables

00:09:32.400
00:09:33.500
in later sessions.

00:09:34.100
00:09:37.300
Okay, so guys finally this is the way
how we can download

00:09:37.400
00:09:39.500
a file from your managed nodes.

00:09:40.100
00:09:40.600
Okay guys.

00:09:40.600
00:09:41.800
Thank you for watching this video.
Transcript
00:00:00.000
00:00:06.710
[no audio] Friends, here we are going
to discuss about how to create or delete a file

00:00:06.700
00:00:10.800
or directory using Ansible Ad-hoc
command and I mean if you want

00:00:10.800
00:00:16.727
to create some file or directory on your
managed nodes how we can create using Ansible Ad-hic
commands.

00:00:16.716
00:00:22.410
See to perform this task we have file
module with your Ansible.

00:00:22.400
00:00:26.810
Not only file, we have some other
modules as well through which also you can do same thing.

00:00:26.800
00:00:30.800
But here we are going to discuss with
file module, now see that
00:00:30.800
00:00:36.210
we already know the simple Syntax for
your Ansible Ad-hoc command.

00:00:36.200
00:00:41.527
Now, I want to use this simple syntax
forever file module

00:00:41.527
00:00:46.085
ansible required server or group or
combination of groups and servers

00:00:46.085
00:00:50.222
- m module file then for this module
some arguments.

00:00:50.222
00:00:52.490
So, here I am taking PATH and state.

00:00:52.490
00:00:56.610
Path means in which location you
want to create your file or directory.

00:00:56.600
00:01:00.410
State is going to represent whether
that is a file or directory.

00:01:00.400
00:01:04.810
Let me excecute this on my ansible
engine.

00:01:04.800
00:01:11.610
So, here I have some inventory in
which we have DB group and some other group under DB group.

00:01:11.600
00:01:18.610
We have two servers and on these two
servers, I want to create a file or directory maybe anything you
can

00:01:18.600
00:01:24.510
create anything right, see that I am
going to take ansible on my DB servers.

00:01:24.500
00:01:32.610
I want to create an empty file, then
arguments path suppose, I want to create under temple location.

00:01:32.600
00:01:36.010
You can provide any location under
temple location.

00:01:36.000
00:01:42.410
I want to create suppose Hello.txt file
then State = touch.
00:01:42.400
00:01:53.110
That's it. Yes, it has been created and
if You observe here with some default values, it has been created
your file.

00:01:53.100
00:01:58.527
Some GID group mode, but I want to
create a file,

00:01:58.527
00:02:01.900
with my required mode: let's say I
want to create one more file,

00:02:01.900
00:02:12.410
Newfile.txt then you can also mention
one more argument called mode and more suppose.

00:02:12.400
00:02:19.010
I have to mention suppose, I am
mentioning triple seven permission just observe that.

00:02:19.000
00:02:21.310
It has been created with your required
mode.

00:02:21.300
00:02:25.209
But, previously if you don't mention
any mode is going to take default mode.

00:02:25.200
00:02:29.109
Now, we mention the mode that's why
it is going to create you to your required mode.

00:02:29.100
00:02:32.510
Not only mode you can change your
provide your group GID,

00:02:32.500
00:02:36.300
uid, right warner everything you can
provide as an argument.

00:02:37.300
00:02:45.010
Now the same file I want to remove if
you want to remove you can provide State as absent.

00:02:45.000
00:02:48.709
That's it, it has been deleted now.

00:02:48.700
00:02:52.310
I want to create a directory.

00:02:52.300
00:03:02.609
Let's say Hello directory, so, directory I
want to create right just after that state is directory.
00:03:02.600
00:03:06.609
Now on those two managers servers,
it has been created under Temple occasion.

00:03:06.600
00:03:13.709
Hello directory, if you want to verify
you can log-in to your manage servers and just observe in your
temple location.

00:03:13.700
00:03:19.209
Now we have hello directory.

00:03:19.200
00:03:24.955
Just observe that by using LSI finality
so that you can see the latest file at the bottom.

00:03:24.955
00:03:29.609
Just now we have been created this
directory, that's it.

00:03:29.600
00:03:40.109
Fine now, just come back, now the
thing is you are using this area command to create

00:03:40.100
00:03:45.520
a file or to create a directory or delete
a file or get deleted directory.

00:03:45.520
00:03:47.851
Not only that you can do some other
actions as well.

00:03:47.851
00:03:53.709
Let's say state I am providing some
invalid value now see that it is going to give a suggestion.

00:03:53.700
00:04:02.209
We provided this one, but we have
valid values for your state as these things.

00:04:02.200
00:04:08.810
Right fine, and one more thing guys
now I want to create some file.

00:04:08.800
00:04:18.709
Let me yeah, I want to create some
file under root location be clear under suppose route EDC.

00:04:18.700
00:04:27.010
I want to create some demo.txt file,
right, so this is a file.

00:04:27.000
00:04:34.010
That's why you have to mention State
as supposed touch, just enter and see the result.
00:04:34.000
00:04:40.210
You're getting an error called
permission denied because see whatever the ansible or how
come and you're executing

00:04:40.200
00:04:46.510
that is going to exclude on your
remote server with ansible admin user.

00:04:46.500
00:04:51.310
But, you are going to exclude your
tasks under root.

00:04:51.300
00:05:01.409
So, whenever if you want to do some
action under root you should have pseudo privileges see that
suppose, I am trying to read a pseudo.conf file.

00:05:01.400
00:05:05.409
I'm getting permission denied but in
the case for this user if

00:05:05.400
00:05:13.610
you have root access, I mean sudo
privileges root privileges, then you can use pseudo command.

00:05:13.600
00:05:16.510
Yes, now you're able to read your file
you're able to read without getting any error.

00:05:16.510
00:05:20.310
If I do that you're getting permission
denied.

00:05:20.300
00:05:24.810
But if I provide here pseudo you can
able to read your file.

00:05:24.800
00:05:32.810
So, when it is acceptable whenever if
your user is having root privileges, if you remember while
configuring our ansible

00:05:32.800
00:05:47.710
setup, we have created and submit
across all the servers and we provided root privileges as well if
you want to see.

00:05:47.700
00:05:56.110
Let me open va pseudo-file just go
down bottom and see that ansadmin, I am giving all permissions
without password.
00:05:56.100
00:06:02.110
So whenever if I do some action with
ansadmin, it won't ask any root password or sudo password.

00:06:02.100
00:06:11.510
So, that's the reason we provided
pseudo access for your ansadmin because you are going to
configure your system with ansadmin user.

00:06:11.500
00:06:16.710
So, if that user is having root privileges
then only you can able to perform your any action.

00:06:16.700
00:06:29.409
right fine now, just now see that
whatever the task we create executed previously.

00:06:29.400
00:06:36.510
So, this is normally you are running
your command with ansadmin user but I want to run this
command with ansadmin

00:06:36.500
00:06:48.010
user by giving pseudo privileges like
pseudo anything with pseudo if you want to perform.

00:06:48.000
00:06:51.810
We are providing pseudo imprint of
your answer Linux commands.

00:06:51.800
00:07:04.310
So, this thing you can provide in your
ansible ad-hoc simply by giving - b or - - become option, see that
how I am going to run.

00:07:04.300
00:07:07.909
If I run in this way, you are not
providing pseudo privileges.

00:07:07.900
00:07:15.110
If you want to run your ansible ad-hoc
command with pseudo privileges you can mention either - b or - -
become.

00:07:15.100
00:07:18.210
Now just run it and see the result.

00:07:18.200
00:07:26.210
So because of - be we have given for
our ansible ad-hoc command root privileges, so when you can
able to execute

00:07:26.200
00:07:33.110
with root privileges whenever if you
have a for this particular user root privileges because you are
running your command

00:07:33.100
00:07:38.140
with this user only that's why for this
user on your remote servers,

00:07:38.130
00:07:41.563
if you have root privileges, then you
can execute a task under root.

00:07:41.563
00:07:45.810
We are creating on the road for that,
you should have root privileges.

00:07:45.800
00:07:49.010
Yes, we have that's why we done it.

00:07:49.000
00:07:54.098
So, guys how you come to know - be
option you have to provide

00:07:54.098
00:08:00.210
for your answer or command nothing
is there it's very simple, simply run and simple now you are going
to get some help.

00:08:00.200
00:08:05.409
And see the all the options which we
have here go with one by one.

00:08:05.400
00:08:11.210
And somewhere we have privilege
escalation options - be shortcut

00:08:11.200
00:08:26.010
or iPhone - become also you can
mention so this option is useful to run your tasks with root
privileges run operations with become becoming pseudo.

00:08:26.000
00:08:34.808
right anyway does not imply password
prompting means it won't ask any password in case if your user is
has to provide a

00:08:34.799
00:08:43.610
password then for that you need to
write - k option and we will discuss that after some time while
working with passwords

00:08:43.600
00:08:46.909
for time being just assume that you
are having password-based authentication
00:08:46.900
00:08:57.110
and if you observe in via pseudo I
have given no password.

00:08:57.100
00:09:03.910
That means it won't ask any
password, that's what it is saying, I mean no password.

00:09:03.900
00:09:09.110
Oh, no need to provide any password
while running your ansible ad-hoc commands with the root
privileges from your

00:09:09.100
00:09:13.510
ansadmin user because that we have
given in via pseudo.

00:09:13.500
00:09:19.210
So, suppose there in va pseudo if I
remove this no password

00:09:19.200
00:09:22.810
here then you need to provide a
password to run your commands

00:09:22.800
00:09:29.710
with pseudo privileges so that part will
discuss later fine

00:09:29.700
00:09:36.410
now so, ansible if you run in this way
as of now we are working

00:09:36.400
00:09:45.210
with this option - be so what is the use
of - be just to run your ansible ad -hoc command with root
privileges that's

00:09:45.200
00:09:55.610
it so before running with root privileges
make sure that your user should have root privileges that's it and
one more thing,

00:09:55.600
00:10:08.310
see as of now you are basic Syntax
for your ansible ad-hoc command is simply ansible some groups,
right then your module whatever the module you have.

00:10:08.300
00:10:18.210
Let's say, general, let me write a
generalized way groups or servers and combination of groups,

00:10:18.200
00:10:31.710
then -m module then arguments, here
we are adding one extra option called - be so you need,
00:10:31.700
00:10:47.010
to remember - B is nothing but
providing, route privileges for your ansadmin and admin user
because I am

00:10:47.000
00:10:53.510
running these are a command from
Anne's admin user, that's it.

00:10:53.500
00:11:04.310
Right, okay guys, this is the way how
we can work with your file module to create or delete a file or
directory.

00:11:04.300
00:11:14.210
And we have some other options as
well with your file module if you want to see that nothing is there
again, we know that file module.

00:11:14.200
00:11:23.210
And simple see that these all are your
options for your file modules arguments.

00:11:23.200
00:11:24.610
So, some playbooks are there.

00:11:24.600
00:11:31.210
If you observe here path owner group,
these all arguments you can use even in your aura command as
well.

00:11:31.200
00:11:35.115
But, effectively all those things we are
going to use in your playbooks.

00:11:35.115
00:11:40.510
So, before that, we are getting some
idea of how to run playbooks with a different options.

00:11:40.500
00:11:44.710
And one more thing suppose I am
going to run ansible all -m ping.

00:11:44.700
00:11:46.010
So what is the purpose of this?

00:11:46.000
00:11:57.310
Just we are checking connectivity with
your all servers, but suppose if I provide DB then it is going to
check the connectivity connectivity with the DB servers.

00:11:57.300
00:12:03.610
But what are all the DB servers any
way we can open inventory file and we can see under DB group,
but from command line
00:12:03.600
00:12:11.310
before executing if you want to see
you can mention simply --listhost then it we'll give what happened.

00:12:11.300
00:12:13.510
We are under yeah, we are under this
location.

00:12:13.500
00:12:20.110
Our inventory file is there and our
practice directly right, let me move into that.

00:12:20.100
00:12:25.010
So, under DB, these are the servers
which we have that's it.

00:12:25.000
00:12:31.310
See all these things are there in your
ansible command just run ansible - H or simply ansible.

00:12:31.300
00:12:39.110
No problem, it is going to give some
help. Just to go through all the options.

00:12:39.100
00:12:46.710
Don't try to learn just see them one by
one suppose one of the option called -F.

00:12:46.700
00:12:50.010
We know Forks value from your
ansible.CFG file.

00:12:50.000
00:12:57.410
If you mention folks value, then your
answer is going to execute your task parallely that number of
servers.

00:12:57.400
00:13:00.510
So same thing, you can also mention
while running your ha commands on your

00:13:00.500
00:13:09.875
command-line also with -f or --forks,
so remember that always command-line arguments or having
highest priority?

00:13:09.875
00:13:18.310
And one more thing we already saw
that - inventory - i inventory so when you are going to use this if
you don't want to work

00:13:18.300
00:13:24.410
the work with the default inventory,
which is there in your ansible.CFG or the time the external you
can mention
00:13:24.400
00:13:30.110
your inventory file or location with that
file name, so this is a shortcut.

00:13:30.100
00:13:33.210
You can also mention -- inventory,
that's it.

00:13:33.200
00:13:37.110
So, likewise you have different options
here, so just go through them.

00:13:37.100
00:13:40.110
Don't try to learn just go through them
once.

00:13:40.100
00:13:52.296
So, that whenever if you are using you
will get some idea, right, okay guys, thank you for watching this
video.
Transcript
00:00:00.000
00:00:01.300
Friends here

00:00:01.300
00:00:05.700
I just want to show you different
modules to work with files

00:00:05.700
00:00:09.000
using your ansible or command or
maybe playbooks as well.

00:00:10.100
00:00:11.300
See in our previous videos.

00:00:11.300
00:00:15.100
We have seen different modules to
work with your files, like

00:00:15.200
00:00:18.800
copy module fetch module and file
module.

00:00:19.600
00:00:22.600
So apart from this we are having some
other models as well
00:00:22.600
00:00:26.500
to work with your files just simply open
your browser and

00:00:26.500
00:00:29.200
just type file modules.

00:00:30.300
00:00:35.200
That's it and just go with your Files
modules here see that

00:00:35.200
00:00:36.900
here you having only file module
already.

00:00:36.900
00:00:40.100
We know about file module just go
with the files modules.

00:00:41.600
00:00:45.400
Now see that you are going to get
ansible 2.8 version all

00:00:45.400
00:00:47.900
the models which are there to work
with your files.

00:00:48.800
00:00:50.400
See we work with right?

00:00:50.400
00:00:54.900
No copy module fetch module and file
modules apart from that

00:00:54.900
00:00:56.500
you're having different modules here.

00:00:57.200
00:01:00.800
So all are going to work with your files
for different purpose.

00:01:01.500
00:01:04.500
So if you have some time just to open
each and every module

00:01:04.800
00:01:08.400
and just have a look on that anyway
while writing our playbooks

00:01:08.400
00:01:11.200
we are going to use different modules.

00:01:11.500
00:01:14.800
files just go through them.

00:01:15.000
00:01:16.700
Don't try to learn just go through them.
00:01:16.800
00:01:19.800
Once if you go then while working with
your playbooks, you

00:01:19.800
00:01:22.600
will come to know what is the use of
different modules for

00:01:22.600
00:01:23.700
different purpose.

00:01:25.600
00:01:26.000
Right.

00:01:26.600
00:01:27.500
So that's it guys.

00:01:27.500
00:01:29.000
I want to show you that thing here.

00:01:29.300
00:01:30.600
Thank you for watching this video.
Transcript
00:00:00.000
00:00:01.800
Friends, here

00:00:01.800
00:00:05.400
we are going to discuss about how to
install a package like

00:00:05.500
00:00:10.400
get httpd MySQL in genetics or any
other package using ansible

00:00:10.400
00:00:11.400
or Hawk commands.

00:00:12.500
00:00:14.600
See to install a package.

00:00:15.400
00:00:16.600
You need some module.

00:00:17.100
00:00:20.000
So before going to that, let me open
my editor suppose if

00:00:20.000
00:00:21.900
you are using a systems.
00:00:25.200
00:00:28.100
Like Linux then you have to select
modulus.

00:00:31.100
00:00:31.600
M.

00:00:32.600
00:00:36.800
Suppose you are using a systems like
Ubuntu.

00:00:37.900
00:00:42.400
or Debian then you have to use
modulus.

00:00:44.800
00:00:47.400
Apt so now likewise.

00:00:47.400
00:00:50.600
You need to select your modules now
anyway before going to

00:00:50.600
00:00:51.500
work with that already.

00:00:51.500
00:00:54.200
We know the simple and similar
command.

00:00:54.500
00:00:59.000
Let's say I want to run my own school
at our Command suppose

00:00:59.000
00:01:04.300
for to check connectivity with my
managed nodes from ansible

00:01:04.300
00:01:08.300
engine then, you know, simple
Rock'em and is ansible your

00:01:08.300
00:01:09.200
required group.

00:01:09.200
00:01:12.400
Let's say I'm taking some DB group
then I found em ping.

00:01:14.100
00:01:21.100
no, as of now, I have all my managed
nodes as Lennox, that's

00:01:21.100
00:01:24.700
why I am going to select module has
young then simply ansible

00:01:25.300
00:01:27.200
required group module has IAM.
00:01:27.800
00:01:30.700
Now for this module you need some
arguments.

00:01:31.000
00:01:33.200
Those markings arguments are like
name.

00:01:33.300
00:01:35.600
So what is the package you want to
install then?

00:01:35.600
00:01:36.900
What is the state for that?

00:01:38.500
00:01:41.400
If you want to install then you need to
make it as a present.

00:01:41.400
00:01:44.300
If you want to remove that package
from your managed nodes,

00:01:44.300
00:01:48.700
then you have to mention this state as
absent or suppose

00:01:48.800
00:01:51.200
assume that already you have some
package on your host.

00:01:51.500
00:01:53.500
Maybe that is some older version.

00:01:53.700
00:01:56.500
Now you want to install you want to
upgrade that to latest

00:01:56.500
00:01:59.100
version then you have to mention
State as latest.

00:01:59.100
00:01:59.600
That's it.

00:02:01.200
00:02:05.800
Now this is the simple command to
install a package, but

00:02:05.800
00:02:07.900
let me try this on my controller.

00:02:09.699
00:02:11.800
Now let me enter into our practice
directory.

00:02:15.700
00:02:16.400
Now see that first.
00:02:16.400
00:02:18.300
I'm checking for my DB servers.

00:02:18.400
00:02:21.900
So before that just absorb that our
host now.

00:02:21.900
00:02:25.600
Let me check the connectivity with my
DB servers.

00:02:27.200
00:02:30.900
Yes, you are having connectivity with
your managed nodes

00:02:30.900
00:02:32.700
which are there on the road DB
group?

00:02:34.100
00:02:34.500
Fine.

00:02:35.400
00:02:39.400
Now, what I want to do is I want to
install a get package

00:02:39.400
00:02:44.900
on my managed nodes then ansible
on your DB servers.

00:02:45.700
00:02:49.800
So guys why I'm taking em module
means as of now my all manage

00:02:49.800
00:02:51.300
servers or Linux systems.

00:02:51.800
00:02:54.500
That's why I'm taking em, but while
going forward will work

00:02:54.500
00:02:56.200
with the different types of your
systems.

00:02:57.200
00:02:57.700
Okay.

00:02:58.100
00:03:01.300
Now I'm using arguments name.

00:03:01.300
00:03:04.700
I want to install gate not only get
suppose httpd can take

00:03:04.700
00:03:05.900
any package name here.
00:03:06.100
00:03:09.500
Then you need to mention State as
Suppose if you want to

00:03:09.500
00:03:11.300
install State as present.

00:03:12.600
00:03:15.800
Suppose if already some get is there
and if you want to I

00:03:15.800
00:03:18.400
mean some old version of get is there
and if you want to

00:03:18.400
00:03:21.700
install the latest version you can also
mention here latest.

00:03:24.800
00:03:27.300
And while magazine latest suppose
assume that you are not

00:03:27.300
00:03:28.800
having any get on your remote
servers.

00:03:28.800
00:03:31.000
No problem that it will install latest
version.

00:03:31.000
00:03:31.500
That's it.

00:03:32.800
00:03:33.200
Right.

00:03:33.600
00:03:34.000
See now.

00:03:34.000
00:03:35.900
Let me run this and see the output
first.

00:03:39.000
00:03:45.300
see you are going to get an error like
You need to be route

00:03:45.300
00:03:46.600
to perform this command.

00:03:46.800
00:03:49.000
We know that suppose if you want to
install any package on

00:03:49.000
00:03:51.000
your unix-like systems.
00:03:51.000
00:03:53.500
You should be the root right now.

00:03:54.500
00:03:57.400
We are not running from route, but we
are running from ants

00:03:57.400
00:04:00.100
admin user even on your managed
nodes.

00:04:00.100
00:04:04.400
Also you are going to run your task
with answered been user,

00:04:05.400
00:04:08.500
but I want to run with Anne's admin
user by providing root

00:04:08.500
00:04:10.500
privileges for my aunt's admin user.

00:04:11.100
00:04:14.300
So if you remember while During our
ansible setup.

00:04:14.900
00:04:19.700
We have provided root privileges for
your all answered mean

00:04:19.700
00:04:22.800
users across all the manager servers
now.

00:04:22.800
00:04:26.200
I need to tell to my Rock'em and
please run this with Anne's

00:04:26.200
00:04:30.300
admin user by taking root privileges if
you remember while

00:04:30.300
00:04:32.500
working with file module as well.

00:04:32.500
00:04:36.700
We use - be or - - become option now,
let me run this with

00:04:36.700
00:04:37.700
- be option.

00:04:38.800
00:04:39.800
Now see the result.

00:04:42.700
00:04:44.700
Now it is going to install your package.
00:04:45.200
00:04:45.400
Yes.

00:04:45.400
00:04:46.200
It has been done.

00:04:46.400
00:04:50.700
If You observe here change true
installed what it installed

00:04:50.700
00:04:51.900
get that's it.

00:04:53.400
00:04:55.600
Now let me install some httpd.

00:04:56.100
00:04:59.100
So before going to that, let me login
into any one of the

00:04:59.100
00:05:01.200
managed server and let me check it.

00:05:03.000
00:05:05.700
So I am going to login into one of the
manage server and

00:05:05.700
00:05:08.300
I am checking get question.

00:05:08.400
00:05:08.700
Sorry.

00:05:12.900
00:05:15.000
Yes get is there same way?

00:05:15.000
00:05:19.000
Let me check which httpd is there
there is no httpd.

00:05:19.000
00:05:25.200
Now I am trying to install httpd using
my M module just a

00:05:25.200
00:05:26.600
name is httpd.

00:05:27.500
00:05:28.000
That's it.

00:05:28.200
00:05:32.000
So guys why I'm providing here - be
means I am not running

00:05:32.000
00:05:35.100
from the root user in case if I were
running from from the
00:05:35.100
00:05:37.300
root user then by default that is the
root user.

00:05:37.400
00:05:40.700
So you have privileges to install some
package if you are

00:05:40.700
00:05:45.000
running from other user And if that
user is having root privileges,

00:05:45.400
00:05:47.800
you need to mention that while
running your aunt's block

00:05:47.800
00:05:51.900
commands in this way your command
with - be option.

00:05:52.100
00:05:56.200
So I even be option means your
ansible Rock'em and we'll

00:05:56.200
00:06:00.000
run with this answered been user by
taking root privileges.

00:06:00.400
00:06:01.000
That's it.

00:06:01.700
00:06:03.200
Now, let me run it and see the result.

00:06:05.800
00:06:06.900
It is going to install.

00:06:08.400
00:06:09.700
That's it has been done.

00:06:09.900
00:06:13.500
You can check it here installed httpd
now, let me login into

00:06:13.500
00:06:14.800
one of the managed server.

00:06:16.000
00:06:19.900
So previously we run here which httpd
now I'm running that

00:06:19.900
00:06:21.200
now there is httpd.

00:06:21.600
00:06:25.100
So just now we installed httpd and all
DB servers with the
00:06:25.100
00:06:26.800
help of your animal or not command.

00:06:29.000
00:06:35.600
Right fine now, just let me run this by
providing some invalid

00:06:35.600
00:06:40.400
state. I'm in state so that you can see
the list of your

00:06:40.500
00:06:42.800
available options for your state.

00:06:44.800
00:06:49.500
Installed latest present removed or it
can also take I mean

00:06:49.600
00:06:52.800
absent. But we provided this option.

00:06:53.200
00:06:54.900
So this option is not a valid option.

00:06:55.100
00:06:56.800
These are the valid options.

00:06:56.800
00:06:58.100
So based on your requirement.

00:06:58.100
00:07:01.500
You need to select your required state
name in were ansible

00:07:01.500
00:07:02.500
or not commands.

00:07:04.700
00:07:06.100
Right, that's it.

00:07:06.400
00:07:11.000
So guys suppose you don't know how
to use on what are the

00:07:11.000
00:07:15.500
different available options for your M
module nothing.

00:07:15.500
00:07:21.700
Is there simply go with your browser
and M module and Sybil?

00:07:21.800
00:07:22.300
That's it.

00:07:22.900
00:07:26.300
So we're going to get very first URL
just open that and just
00:07:26.300
00:07:27.800
go through that from top to down.

00:07:29.600
00:07:33.400
So currently on 2.8 the M package is
going to use Python

00:07:33.400
00:07:36.500
to in case you have Python 3 you
need to do some setup will

00:07:36.500
00:07:40.700
discuss that later now just go down
we're having different

00:07:40.700
00:07:42.100
arguments options here.

00:07:42.300
00:07:45.100
So we have taken as a from name and
state but along with

00:07:45.100
00:07:47.000
that you're having different things.

00:07:47.300
00:07:50.000
So all those things we can effectively
use in your playbooks.

00:07:52.500
00:07:55.700
And if you come down with your M,
you're having some playbooks

00:07:55.700
00:07:56.100
as well.

00:07:56.600
00:07:58.800
So nothing is their playbook is nothing
but writing your

00:07:58.800
00:08:02.800
module at our Command inside a file
with some syntax.

00:08:02.800
00:08:03.300
That's it.

00:08:05.000
00:08:08.200
Suppose if I want to update all
packages, then you can do

00:08:08.400
00:08:11.600
name equals to star in quotation and
then State equals to

00:08:11.600
00:08:15.600
latest so that you know, all your
managed nodes all packages
00:08:15.600
00:08:17.200
will be updated automatically.

00:08:17.800
00:08:21.900
That's it the same way suppose if you
want to install any

00:08:21.900
00:08:26.200
package on your open to then there is
a PT package.

00:08:29.900
00:08:30.800
Just open that.

00:08:34.000
00:08:37.600
See you have your having here
information like for Debian

00:08:37.600
00:08:43.200
Ubuntu apt packages, right and just go
through all the options

00:08:43.200
00:08:46.900
and just have a look on this but don't
try to learn as of

00:08:46.900
00:08:47.799
now just go through them.

00:08:47.799
00:08:48.200
That's it.

00:08:48.500
00:08:51.200
So while writing playbooks you will get
good idea how to

00:08:51.200
00:08:52.600
use all the options.

00:08:53.600
00:08:55.900
Now, we have some of the example
for your playbooks as well.

00:08:56.299
00:08:59.100
But before going to write this much
type poem in this type

00:08:59.100
00:09:02.000
of playbooks, we should have some
idea how to write will

00:09:02.000
00:09:03.600
discuss that Okay.

00:09:04.600
00:09:05.200
Okay guys.

00:09:05.300
00:09:06.500
Thank you for watching this video.
Transcript
00:00:00.000
00:00:04.840
Friends here, we are discussing the
Command Module.

00:00:04.840
00:00:07.523
See first of all, Command Module is
like a shell module.

00:00:07.523
00:00:09.414
Then what is the use of shell module?

00:00:09.414
00:00:15.910
We already discussed about shell
module just to exclude some binary commands on your managed
nodes.

00:00:15.900
00:00:22.010
I mean you are unix-like system
commands if you want to execute on your managed nodes you
can use shell module.

00:00:22.000
00:00:25.580
Now, Command Module is also useful
to execute your binary commands.
00:00:25.580
00:00:30.910
So, let me open my ansible controller
and see here.

00:00:30.900
00:00:36.510
So, I have my one server in this
inventory, anyway, I have my default inventory as well.

00:00:36.500
00:00:39.210
But, I want to work with this custom
inventory file.

00:00:39.200
00:00:47.710
So, with -i option I can include that all
so suppose, I want to execute a task called up time on that.

00:00:47.700
00:00:54.910
So, use the shell module with the
argument as uptime, right now same thing.

00:00:54.900
00:01:02.910
I am going to get using Command
Module as well, let me use command.

00:01:02.900
00:01:05.310
You're getting the same result.

00:01:05.300
00:01:14.910
See, if I don't mention any module on
my command line, then generally to perform any task you need
some module.

00:01:14.900
00:01:24.310
But if I don't mention any module
name on my command line then ansible will fetch the default
module has command.

00:01:24.300
00:01:28.510
So, this is one of the important point
while working with your ansible ad-hoc commands.

00:01:28.500
00:01:36.310
So, on your command line of ansible
or in your ansible ad-hoc commands, what is the default module
command?

00:01:36.300
00:01:42.310
Just implementing arguments, I'm not
giving any module name by default ansible will fetch modulus
command,

00:01:42.300
00:01:48.110
if you don't mention any module name
on your ad-hoc commands, that's it.
00:01:48.100
00:01:53.410
So, that's why this is the default
module on your ansible ad-hoc commands, now,

00:01:53.400
00:01:56.700
anyway, you are excluding your
commands through the shell as

00:01:56.700
00:01:59.292
well as command then what is the
difference between these two?

00:01:59.292
00:02:05.210
See, with the Command Module the
command will be executed

00:02:05.200
00:02:09.109
without being proceeded through a
shell see whenever if you

00:02:09.100
00:02:15.810
are going to proceed with the shell you
are going to execute your commands through shell.

00:02:15.800
00:02:19.900
Now Command Module is not using
your shell on your manager node.

00:02:19.900
00:02:24.910
Simply, it is going to execute your
commands through your python.

00:02:24.900
00:02:29.310
Right now, because of these
sometimes you may not your you

00:02:29.300
00:02:36.709
are not sure that your Command
Module will pick like some environment variables and some
operators like this.

00:02:36.700
00:02:43.109
It may not work on these things come
and let me show you that simple example.

00:02:43.100
00:02:52.310
Suppose first of all, what I am doing is
ansible - i inventory, I am using Command Module.

00:02:52.300
00:02:54.310
That's why no need to mention even
though if you want to

00:02:54.300
00:02:57.109
mention you can mention but even if
you don't mention your
00:02:57.100
00:03:00.910
answer will fetch that as the default
module now on my manager

00:03:00.900
00:03:09.010
node, I want to find list of files and
then I want to store that into my result into my results dot txt.

00:03:09.000
00:03:12.709
See, the result what you are getting.

00:03:12.700
00:03:18.109
Yeah, I did not provide it group name
or server name, let me provide simply all anyway.

00:03:18.100
00:03:20.910
I have only one server in that
inventory, no problem.

00:03:20.900
00:03:28.209
See that cannot access myrest.txt no
such file or directory non-zero return code.

00:03:28.200
00:03:38.910
Basically, this operator is not working
but same syntax if I go and work with shell module, then it will
work, that's it.

00:03:38.900
00:03:45.209
Now just login with your manager
server and see the result.

00:03:45.200
00:03:53.010
See you have my result what we have
taken my rest something that file is there.

00:03:53.000
00:03:58.609
Alright, so that is the difference
between your Command Module and she'll module.

00:03:58.600
00:04:02.010
So simply remember that if you don't
want to work with anyone

00:04:02.000
00:04:04.510
meant variables and some operators
like less than, greater than,

00:04:04.500
00:04:08.800
Pipeline and ansible then go with
Command Module.

00:04:09.000
00:04:13.910
But, if you want to work with anyone
variables and these things then go with shell model, that's it.
00:04:13.900
00:04:22.110
And anyway, finally Command Module
is the more secure one because it will not be affected by the users
environment.

00:04:22.100
00:04:25.810
So sometimes you don't want to work
with any armed variables

00:04:25.800
00:04:28.610
then go with Command Module if you
want to work with anyone

00:04:28.600
00:04:32.610
meant variables and operators like this
then go with your shell module.

00:04:32.600
00:04:42.503
That's it, Okay. Thank you for
watching this video.
Transcript
00:00:02.000
00:00:02.700
[no audio] Friends, here

00:00:02.700
00:00:05.400
we are going to discuss about ansible
facts.

00:00:05.600
00:00:09.800
So simply what is the ansible fact or
what are ansible facts

00:00:10.400
00:00:14.500
see ansible facts are nothing but
information about your

00:00:14.500
00:00:15.500
managed nodes.

00:00:15.900
00:00:19.800
So those are information like, you
know, what is the waist

00:00:19.800
00:00:23.300
distribution of you're managing nodes
or node or what is

00:00:23.300
00:00:24.600
the Ways release for that?
00:00:25.000
00:00:29.300
What type of processor is using your
manager nodes and what

00:00:29.300
00:00:31.500
is the python location on your
manager nodes?

00:00:32.100
00:00:33.600
What is the host name for that?

00:00:33.700
00:00:35.100
What is the domain name for that?

00:00:35.300
00:00:36.900
What is the IP address for that?

00:00:37.500
00:00:41.000
So all those things are called simply
and simple facts.

00:00:42.300
00:00:48.000
Now you can collect or gather this
facts by running a task

00:00:48.300
00:00:49.800
on your ansible controller.

00:00:51.500
00:00:55.000
See the task of collecting this remote
system information

00:00:55.000
00:00:58.900
is called as Gathering facts means if
you want to collect

00:00:58.900
00:01:02.800
a facts, then you can have to run
some task that is nothing

00:01:02.800
00:01:07.400
but Gathering facts and whatever the
collected or gathered

00:01:07.400
00:01:08.400
information is there.

00:01:08.400
00:01:12.300
No, I mean some information that is
called simply facts or

00:01:12.300
00:01:15.300
variables. Right.

00:01:15.400
00:01:18.900
Now you can gather or collect your
facts.
00:01:19.000
00:01:24.000
I mean about your manager node
information using set up module

00:01:24.000
00:01:25.500
in your commands.

00:01:26.200
00:01:28.400
Of course, you can also use this
module in your playbooks

00:01:28.400
00:01:28.800
as well.

00:01:30.600
00:01:35.200
So on your command line, if you want
to collect the information

00:01:35.200
00:01:38.400
about your managed nodes, you need
to run a task so that

00:01:38.400
00:01:40.300
task with respect to set up module.

00:01:41.200
00:01:43.300
Now, whatever the information you are
going to collect with

00:01:43.300
00:01:44.400
the help of setup module.

00:01:44.500
00:01:46.800
That is nothing but ansible facts.

00:01:49.100
00:01:51.600
And one more thing guys, so well
going forward we are going

00:01:51.600
00:01:53.800
to use the setup module in playbooks
as well.

00:01:53.800
00:01:58.900
But even though if it don't use this
setup model by default

00:01:59.000
00:02:01.600
playbooks will run this setup module.

00:02:03.100
00:02:08.000
And it will gather the facts about your
managed nodes see

00:02:08.000
00:02:08.800
on your command line.
00:02:08.800
00:02:12.800
We are going to run setup module to
gather facts, but playbooks

00:02:12.800
00:02:13.400
by default.

00:02:13.400
00:02:14.600
It will run the setup module.

00:02:14.700
00:02:18.000
We know not to write any code to run
your setup module in

00:02:18.000
00:02:18.800
your playbooks.

00:02:19.200
00:02:20.600
It's very very important.

00:02:21.700
00:02:26.800
Fine now so setup module to gather
your facts then what is

00:02:26.800
00:02:27.800
the Syntax for that?

00:02:27.900
00:02:29.300
So simply ansible?

00:02:30.000
00:02:33.700
I may not or command syntax ansible
to are required a group

00:02:33.700
00:02:36.500
or groups or servers - um set up now.

00:02:36.500
00:02:38.800
Let me run this on your controller.

00:02:41.000
00:02:42.800
Let me enter into my practice
directory.

00:02:43.100
00:02:48.200
So I want to run this setup module on
my DB servers.

00:02:49.200
00:02:52.100
I want to get the information about my
DB servers.

00:02:52.400
00:02:55.500
I want to get the facts of my DB
servers.

00:02:55.900
00:02:59.400
So simply ansible your group - mm
setup.
00:02:59.600
00:03:02.600
Now it is going to give you some facts
about your managed

00:03:02.600
00:03:04.600
nodes which are there in your DB
group.

00:03:05.100
00:03:06.700
Just enter the knobs or the output.

00:03:07.900
00:03:10.600
So you're going to get some
information for your two servers.

00:03:10.600
00:03:13.500
So that's why what I am doing is I am
going to run only for

00:03:13.500
00:03:18.700
one server so that it is very clear to
understand to see

00:03:18.700
00:03:22.500
the facts because same facts are
going to repeat for your

00:03:22.500
00:03:26.400
servers but fact values may be
different based on you are

00:03:26.400
00:03:27.300
managed node.

00:03:28.100
00:03:30.300
Now, I want to run on This Server.

00:03:30.400
00:03:34.200
I mean, I want to collect my facts for
This Server.

00:03:34.500
00:03:38.400
So simply - em set up module that sit
now see the result.

00:03:40.600
00:03:43.300
If you go through this output, you can
see different values

00:03:43.300
00:03:46.700
here and this information whatever the
information you are

00:03:46.700
00:03:50.100
getting through your setup module that
is like a dictionary
00:03:50.300
00:03:52.900
and that dictionary see that this is like
a dictionary.

00:03:54.000
00:03:58.200
and that dictionary consists of some
list of values and sometimes

00:03:58.200
00:04:02.500
you may or directly string I mean text
Right.

00:04:02.700
00:04:08.300
So setup module Ozzy or setup model
is useful to gather your

00:04:08.300
00:04:10.500
facts about your managed nodes.

00:04:12.800
00:04:15.500
Now if you go from top to down you're
going to see different

00:04:15.500
00:04:19.399
informations about the war managed
nodes, you can go through

00:04:19.399
00:04:22.500
that from top to down so ansible
distribution.

00:04:22.700
00:04:25.300
I have been created actually my
manage server from Amazon

00:04:26.000
00:04:26.700
Amazon Linux.

00:04:26.700
00:04:27.800
I have been selected.

00:04:29.100
00:04:30.800
Right then see that.

00:04:30.800
00:04:32.000
What is the ansible domain?

00:04:32.200
00:04:34.000
This is from AWS Cloud.

00:04:34.000
00:04:35.800
That's why domain is easy to do
internal.

00:04:36.600
00:04:40.100
So likewise you have different
informations about your managed
00:04:40.100
00:04:44.300
nodes. So those are nothing but facts
so you can gather your

00:04:44.300
00:04:46.000
facts using set up module.

00:04:46.700
00:04:47.200
That's it.

00:04:48.800
00:04:52.700
So these all are your facts see what is
the ansible known

00:04:52.700
00:04:57.000
name? And what is the unsub Lewis
family red hat and what

00:04:57.000
00:05:00.300
is the package it is using to install any
packages yum package

00:05:01.200
00:05:03.100
likewise see what is the processor?

00:05:04.500
00:05:06.400
So you're going to get this
informations?

00:05:06.700
00:05:10.300
So by default whenever if you run this
setup module you're

00:05:10.300
00:05:13.500
going to get different informations, but
suppose I want to

00:05:13.500
00:05:14.500
get only.

00:05:15.800
00:05:19.800
A let's say anything you can take I
don't want to get all

00:05:19.800
00:05:20.600
those things suppose.

00:05:20.600
00:05:23.000
I want to get only ansible mounts
point.

00:05:24.500
00:05:28.600
What is the Mount points on my
manager node then by default?

00:05:28.600
00:05:31.800
If you run your command, you're going
to get all informations,
00:05:31.800
00:05:35.600
I mean different facts or different
variables, but I want

00:05:35.600
00:05:42.000
to get only Mount Point information
then simply ansible mounts

00:05:42.000
00:05:42.900
now see the results.

00:05:45.200
00:05:47.800
Or you're going to get you're going to
get now only Mount

00:05:47.800
00:05:49.300
Point informations.

00:05:49.500
00:05:52.500
So actually you're going to get what
you are using a filter.

00:05:53.900
00:05:57.600
So like, you know, it's like a grep
command or set command

00:05:57.600
00:05:58.900
in your unix-like systems.

00:05:59.300
00:06:02.700
We are filtering them from the entire
output from the entire

00:06:02.700
00:06:06.100
facts. We want to see only some of
the facts so my required

00:06:06.100
00:06:07.500
facts is ansible facts.

00:06:09.500
00:06:10.000
That's it.

00:06:10.500
00:06:13.300
So likewise you can filter any option
any value.

00:06:14.500
00:06:15.900
Let's say one more thing suppose.

00:06:15.900
00:06:18.200
I want to take you can take anything.

00:06:18.200
00:06:18.800
No problem.

00:06:19.700
00:06:21.500
But you need to take your key.
00:06:21.500
00:06:23.700
If you are good at python dictionaries.

00:06:23.700
00:06:24.600
You can easily understand.

00:06:24.600
00:06:26.900
Otherwise, don't worry while going
forward will discuss with

00:06:26.900
00:06:28.800
the ml Basics there.

00:06:28.800
00:06:33.300
You can understand about keys and
values now see suppose.

00:06:33.300
00:06:37.000
I want to see ansible architecture then
simply.

00:06:37.300
00:06:40.100
I mean ansible architecture means
you are managed node architecture.

00:06:42.400
00:06:48.400
see that you're getting this is the
architecture of I manage

00:06:48.400
00:06:51.300
node. And if you absorb by default,
you're going to get one

00:06:51.300
00:06:55.300
of the fact that is called python
because without having

00:06:55.300
00:06:57.600
python you can't exclude any task.

00:06:57.700
00:07:01.600
That's why by default you are going to
get your python facts

00:07:01.600
00:07:02.000
as well.

00:07:03.300
00:07:03.800
Right.

00:07:03.800
00:07:08.700
So guys, this is about your ansible
facts, right and one

00:07:08.700
00:07:09.300
more thing.
00:07:10.200
00:07:15.700
There are two types of ansible facts
one is custom fact or

00:07:15.700
00:07:19.100
sorry default facts and second one is
custom facts.

00:07:19.400
00:07:22.500
So default facts are nothing, but see if
you run your setup

00:07:22.500
00:07:25.300
module you're going to get some facts
or some variables or

00:07:25.300
00:07:26.100
some information.

00:07:26.100
00:07:29.600
They are all called simply default
facts.

00:07:30.500
00:07:35.700
but other than that if you want to
Collect some extra information.

00:07:36.400
00:07:37.800
Yes, you can collect it.

00:07:37.800
00:07:41.200
So for that you need to create some
custom facts on your

00:07:41.400
00:07:42.500
managed nodes.

00:07:43.200
00:07:46.100
So how to create your custom fats and
how to work with your

00:07:46.100
00:07:47.000
custom facts.

00:07:47.000
00:07:48.600
We will see in next video.

00:07:49.500
00:07:50.100
Okay guys.

00:07:50.100
00:07:51.900
Thank you for watching this video.
Transcript
00:00:00.000
00:00:04.930
Friends here, we are going to discuss
ansible custom facts.

00:00:04.930
00:00:10.783
See already, we know that there are
two types of ansible facts: that are default facts and custom facts.

00:00:10.783
00:00:16.258
So, first of all, facts are nothing but
information about your managed nodes.

00:00:16.258
00:00:24.597
See, whenever if you run your setup
module by default you are going to get some information about
your managed nodes.

00:00:24.597
00:00:29.743
So, they are nothing but facts or
variables then what about custom facts?

00:00:29.743
00:00:39.129
See, other than default facts, if you
want to collect any extra information about your managed
00:00:39.129
00:00:47.872
nodes, then you have to create a
custom facts on your managed nodes so that you can get that
custom facts from your ansible engine.

00:00:47.872
00:00:55.110
And one more thing if you want to
collect a default or custom facts, we have to use set up module
only there

00:00:55.100
00:00:58.110
is no separate module to collect
custom facts.

00:00:58.100
00:01:06.709
So, by default you also going to get
custom facts using set up module if you have a custom facts on
your managed nodes.

00:01:06.700
00:01:18.910
So, finally why we need custom facts
simply custom facts or required to get user-defined facts?

00:01:18.900
00:01:24.110
Right, see let me use simple real-time
scenario suppose,

00:01:24.100
00:01:35.310
I'm having some number of servers in
my environment; for every week, I need to find out are different
informations about your about my managed nodes.

00:01:35.300
00:01:45.510
Let's say a very simple example I am
taking what is the git version is there on my managed nodes or
what is the HTTP version or weblogic question or DB version?

00:01:45.500
00:01:47.810
Maybe any other applications or two?

00:01:47.800
00:01:55.110
So, what should I need to find out on
all my manage notes for every week just it's kind of inventory
every week?

00:01:55.100
00:01:59.410
I need to do some inventory. Right.

00:01:59.400
00:02:07.836
Anyway, you can write your playbooks
to get your required information for your managed nodes, or you
can run some more commands.
00:02:07.836
00:02:10.410
But if you go with our commands, you
need to run

00:02:10.400
00:02:14.410
number of rock commands to get get
version to get HTTP diversion.

00:02:14.400
00:02:17.510
Separate are all commands, you need
to run suppose.

00:02:17.500
00:02:28.609
But, other than that, you can write
simply one Playbook and you can get them but if you create
custom facts to get all this information then your playbook is very
simple.

00:02:28.600
00:02:35.709
But, guys remember that custom facts
are not mandatory if you want you can create custom facts.

00:02:35.700
00:02:47.609
But, if you create custom facts your
playbooks are very easy to write you can reduce the number of
lines in your playbooks.

00:02:47.600
00:02:50.109
I'm having some number of servers in
my environment.

00:02:50.100
00:02:56.510
We know we have different
environments like prod, non-productive, QA servers, right?

00:02:56.500
00:03:04.810
Now, while writing playbooks based on
the environment if it is prod server, then I need to do some task.

00:03:04.800
00:03:09.510
If it is non-prod, I need to do different
tasks like wise to take some decision.

00:03:09.500
00:03:13.109
If you have a fact about your
environment, then it is very

00:03:13.100
00:03:18.510
easy to take decision inside of your
playbooks that means on each and every managed node,

00:03:18.500
00:03:22.100
I will create one variable environment
equals to prod and in suppose,
00:03:22.800
00:03:26.810
so, for some servers, I will create an
environment equal to prod if they are

00:03:26.800
00:03:31.709
for some servers, I will create anyone
medication on prod.

00:03:31.700
00:03:37.609
Right, based on that fact while running
my Playbooks, I will take decision very easily.

00:03:37.600
00:03:41.709
So likewise, we have some
requirements with custom facts.

00:03:41.700
00:03:45.010
So if you go with custom facts that are
helpful while writing

00:03:45.000
00:03:49.910
your playbooks, but remember that
they are not mandatory.

00:03:49.900
00:04:05.010
Let me take one simple example:
suppose, see that I want to find get version and HDD version on
all my manage servers.

00:04:05.000
00:04:09.310
Let me enter into my practice
directory, I have a inventory.

00:04:09.300
00:04:15.010
So, let me first check connectivity with
all my managed nodes.

00:04:15.000
00:04:21.010
Yes that able to reach and guys if I
observe here, I have taken private eye piece of my managed
nodes because

00:04:21.000
00:04:25.610
my ansible engine is also from my
AWS cloud and my manager notes are also from AWS Cloud.

00:04:25.600
00:04:30.010
Then I can take private IP's as well.

00:04:30.000
00:04:36.110
Right, if your ansible engine is from
outside of your AWS Cloud, then you have to go with public IP.

00:04:36.100
00:04:43.810
Okay, fine, now my requirement is,
first of all, I need to find out get version on all my managed nodes.
00:04:43.800
00:04:49.010
Let me run any ad-hoc and to get that
information.

00:04:49.000
00:04:54.009
So, guys, you want to get the
information for getting that gits version.

00:04:54.009
00:04:58.010
So, if you want to run any command
on your managed nodes, we have two options.

00:04:58.000
00:05:03.510
Earlier, we have seen one of the
options that is using the shell module, and we also having
Command Module as well.

00:05:03.500
00:05:07.300
We'll discuss that so for time being,
already, we know shell

00:05:07.300
00:05:15.010
module, social model, arguments are
nothing but the commands which you need to exclude on your
managed nodes.

00:05:15.000
00:05:24.510
Let's say I want to run simply --
version, right, you're going to get for all your managed nodes.

00:05:24.500
00:05:31.810
What is the git version? So here
maybe different version and the same time I need to get now.

00:05:31.800
00:05:42.210
I want to get the HTTP version, so
suppose if I run http - version.

00:05:42.200
00:05:46.710
See here, I'm not getting but here you
are getting your HTTP version.

00:05:46.700
00:05:49.234
Right, Now, let me run instead of
httpd.

00:05:49.234
00:06:00.610
If you go with the come by mentioning
complete path, then there is a chance to get let me try user I think
in has been you have httpd, right?

00:06:00.600
00:06:08.610
Yes, now you are getting your HTTPD
all your servers and if you observe I am not getting I mean, I am
00:06:08.600
00:06:15.010
getting along with your this version
some when it was built.

00:06:15.000
00:06:18.110
Anyway, you're getting your HTTP
watching on git version.

00:06:18.100
00:06:24.310
But, to get your git version of HTTP
version, suppose if it is repetitive tasks, I mean every week you
have to do

00:06:24.300
00:06:31.710
this you need to run this entire out of
command here and this command to get httpd.

00:06:31.700
00:06:38.510
And, this what is that git version
command, these are all Command, right?

00:06:38.500
00:06:41.810
Now, instead of this just to create
some facts on your manager node,

00:06:41.800
00:06:48.110
so I will write simply I will create one
fact on my manager node in that.

00:06:48.100
00:07:00.610
I'm going to create a to collect git
version as well as HTTP version then it is very easy to collect with
one out of command using set up module.

00:07:00.600
00:07:08.210
Okay, first of all, don't confuse now
first, let me show you what are the steps to create a custom facts
on your managed nodes.

00:07:08.200
00:07:15.510
So, for time being, custom facts are
nothing, but you are required values suppose, I need get version
and HTTP version.

00:07:15.500
00:07:25.065
So, how can I create a fact for that to
collect the information about your get version and HTTP version
through your ad-hoc commands?

00:07:25.065
00:07:29.110
So, while going forward we will see the
same thing in your playbooks as well.
00:07:29.100
00:07:37.010
So, first of all, the steps what you
need to create a custom facts are nothing, but you have to create
under root 8 EC

00:07:37.000
00:07:43.310
under Ansible facts. d - directory on
your all managed nodes, whatever, the minor is nodes.

00:07:43.300
00:07:48.409
You want to work with custom facts for
all those managed nodes.

00:07:48.400
00:07:56.110
You need to create do TTC and simple
facts.d so guys be clear for your managed nodes.

00:07:56.100
00:07:57.510
You are not having any ansible.

00:07:57.500
00:08:04.409
That's why you don't have any
directory called ansible on your managed nodes that means on all
your managed nodes under

00:08:04.400
00:08:07.510
root it is you need to create ansible
along with facts,

00:08:07.500
00:08:12.110
need a tree inside of this that is very
first step.

00:08:12.100
00:08:21.810
Then second thing inside of these
facts.d place one or more custom facts files with extension as dot
fact can give

00:08:21.800
00:08:25.909
any name but the extension should be
.fact.

00:08:25.900
00:08:39.110
First thing, we have to create facts. d
under root, under ansible then under facts.d you can create any
number of files files are nothing but scripts, maybe shell scripts, or
python script, or Perl script.

00:08:39.100
00:08:46.510
What about the script, you know
based on that you have to write your script to collect the
information what you need?
00:08:46.500
00:08:57.310
But make sure that that file should be
and with .fact even though if it is a shell or python don't write .h, .p
by you have to write with DOT fact.

00:08:57.300
00:09:02.710
Then step 3 the output of the fact file
should be a Json

00:09:02.700
00:09:12.510
because see guys if you observe let
me run ansible all -m set up module.

00:09:12.500
00:09:14.410
So, set up module is going to collect
your facts.

00:09:14.400
00:09:19.410
Right see all are in terms of this curly
brace.

00:09:19.400
00:09:23.910
Basically, there is a dictionary or Json
format output.

00:09:23.900
00:09:31.610
So, this entire output is nothing, but
Json format, that's why whatever the file you are going to create
inside of facts

00:09:31.600
00:09:38.310
.d with extension is dot fact, that
output should be a Json format.

00:09:38.300
00:09:46.510
Right fine, and finally, you need to
have execution permission for that .fact file.

00:09:46.500
00:09:50.410
So, these are the steps to create
custom facts.

00:09:50.400
00:09:56.010
Now what we need to do, we need to
login into each and every man a server and on each and every
managed server.

00:09:56.000
00:10:01.210
We need to create this directory.

00:10:01.200
00:10:12.510
ETC / ansible / facts.d and then inside
of that some file shell script or python script but our the script, you
know based on that you can create.
00:10:12.500
00:10:19.010
Right, now we can log in into each and
every manage servers and we can create this folder.

00:10:19.000
00:10:24.310
I mean this data structure inside of
that you can do this .fact and we can write some shell script on
you can provide

00:10:24.300
00:10:29.910
some execution permissions, but I
don't want to login with each and every managed node because
already we are good with

00:10:29.900
00:10:37.210
some modules of your ansible through
the time trying to create your required facts on your manager
notes.

00:10:37.200
00:10:45.410
But, before going to that, let me show
you this process only were ants bring your itself wherever it may
be.

00:10:45.400
00:10:49.910
So anyway in ansible engine by
default, right?

00:10:49.900
00:10:56.710
We created under root ETC ansible if
you remember because these are a chelate server, that's why we
created ansible

00:10:56.700
00:11:02.410
by default in less than versions of your
Oracle, or if you go with the m command installation of your
ansible, you will

00:11:02.400
00:11:07.010
get this the home for your ansible now,
hears what you have to do.

00:11:07.000
00:11:17.610
Guys, now first of all, I'm showing you
on your ansible engines are were to work with your custom facts.

00:11:17.600
00:11:20.410
No, same thing, you have to create on
your manage servers, but I don't want

00:11:20.400
00:11:23.710
to go and login to manage servers and
I don't want to do that action.
00:11:23.700
00:11:25.500
I will do with the ad-hoc comments.

00:11:25.500
00:11:34.110
Fine now see that first of all you need
to create facts.d directory inside of your ansible anywhere.

00:11:34.100
00:11:38.510
We are with the ansadmin let me use
pseudo privileges.

00:11:38.500
00:11:51.310
Yes, I created, okay, let me enter into,
route that's better.

00:11:51.300
00:12:03.810
So CD ETC, and simple facts.d, What
do we have here, git? Let me check it.

00:12:03.800
00:12:21.010
No, let me install git. Just give me a
minute.

00:12:21.000
00:12:37.410
I will install this get as well as M,
install m, install httpd, okay, fine.

00:12:37.400
00:12:50.510
Now first of all, we created facts.d
directory under root TC under ansible, now we move into that
facts.d now before going to create your facts files.

00:12:50.500
00:12:59.510
Let me check, What is the commands
for your to get your get version and see directly?

00:12:59.500
00:13:01.410
If you're running from your command
line.

00:13:01.400
00:13:10.010
You can simply Run httpd - version
you're going to get, now see you guys from this output.

00:13:10.000
00:13:19.710
I don't want to get this git version
2.1.8.1 so simply I want to get only get two dot one dot 2.1 8.1.

00:13:19.700
00:13:31.510
So, simply AWK I can use simply print
$3: 1, 2, 3, yes $3.

00:13:31.500
00:13:37.610
Yes, the same way from HTTP
version, also, I don't want to get all the output.
00:13:37.600
00:13:44.410
I want to get only Apache 2.0
something this information, This is at 1 2 3.

00:13:44.400
00:14:03.910
Yeah, this is also in first-line and these
are your Linux commands guys. Sorry $3.

00:14:03.900
00:14:08.710
Yes, we are getting now what I am
doing is I am going to create one shell script.

00:14:08.700
00:14:14.882
So inside that shell script, I will use
these two commands just observe that first time how I am going to
create custom facts.

00:14:14.882
00:14:26.910
So, you need to write some shell
script, but that shell script extension should be dot fact, let's say
what I want to do is let me create any any script name.

00:14:26.900
00:14:33.210
I am going to take get and httpd
version dot fact.

00:14:33.200
00:14:37.710
No, first of all, let me write these the
command to get your git version.

00:14:37.700
00:14:49.210
I want to store this into a variable
called git version, and then I want to get httpd version as well.

00:14:49.200
00:15:06.810
So, for that already to be done a
command,Let me copy that, that's it.

00:15:06.800
00:15:09.010
Right now and one more thing.

00:15:09.000
00:15:16.810
I have to mention your shebang line,
bin bash or if it is python you can mention your python location.

00:15:16.800
00:15:24.710
I mean if your fact file is python script,
then you can mention that.

00:15:24.700
00:15:37.710
What happened? When I get, yeah
now let me, that's it.

00:15:37.700
00:15:47.210
Now, finally, the output of this script
should be a Jason just means you have to get in terms of curly
braces your output key and value pair representation.

00:15:47.200
00:16:01.510
Let me show you that simply with the
cat, see how what I am doing is, so simply I'm writing my required
variable that is git version.

00:16:01.500
00:16:07.310
So git version value, we are storing
into a variable called git version first.

00:16:07.300
00:16:16.710
I will run this manually then I will use
this in your Ansible as a custom facts now.

00:16:16.700
00:16:22.610
I want to see httpd version as well.

00:16:22.600
00:16:41.110
Som this variable I mean the HTTP
version variable this one, that's it.

00:16:41.100
00:16:47.410
Now, let me save it and first let me run
this here before going

00:16:47.400
00:16:49.810
to run you should have a execution
permission.

00:16:49.800
00:16:58.510
Let's simply provide 7555 permission
for this now, I am going to run this.

00:16:58.500
00:17:08.710
What happened? Git version fact line
number six-line number six what happened?

00:17:08.700
00:17:10.210
Oh, sorry, that is a variable right?

00:17:10.200
00:17:30.410
I provided parentheses, yeah, see
here, If it is a command you have to take parentheses, right but
this is a variable don't take parentheses.

00:17:30.400
00:17:40.109
Yeah, now it's fine. You are going to
get your see the output, what happened in line Number 11, I
command not found maybe type.

00:17:40.099
00:17:49.510
Oh, yeah at the end, I provided I that
is my type o, sorry for this.
00:17:49.500
00:17:51.710
Now you're getting your output in
terms of curly braces.

00:17:51.700
00:17:56.210
There is a key and value there is a key
and value, this is nothing but Json format.

00:17:56.200
00:18:09.010
I know what I'm doing is just now, I
created, custom fact, so be clear, what are the steps we followed
under

00:18:09.000
00:18:15.510
ansible we created facts.d then inside
of a facts.d I created one shell script.

00:18:15.500
00:18:25.710
But extension with the .fact, then I
have taken a cake are such that the output of that fact file should
be a Json and I provided execution permission as well.

00:18:25.700
00:18:36.710
Now, let me move into ansadmin user
and let me move into our practice directory

00:18:36.700
00:18:41.210
Now, in my separate inventory in this
file, I have a local host now.

00:18:41.200
00:18:52.810
Simply, I'm running and simple on this
inventory localhost I am running setup module.

00:18:52.800
00:18:57.710
Now, you're going to collect the
localhost information.

00:18:57.700
00:19:02.510
I mean localhost default facts along
with that your custom facts. What are your custom facts?

00:19:02.500
00:19:14.710
If you remember, Git version and
HTTP version, but where are there in this output only you have so
if you want to search you can search instead of that.

00:19:14.700
00:19:23.310
You can simply grab and see that let
me provide get a grip - I get version.

00:19:23.300
00:19:37.310
See the result. See you're getting get
version somewhere you have and I need along with get let me use
a grip.
00:19:37.300
00:19:41.910
We followed yeah, we found this
HTTP version as well, right?

00:19:41.900
00:19:45.710
Now, let me run and see the result.

00:19:45.700
00:19:50.810
Yes, you're getting your git version as
well as HTTP version.

00:19:50.800
00:19:54.710
See apart from your default facts, now
you're getting your custom facts results.

00:19:54.700
00:20:00.310
Also inside of your set up module
output C.

00:20:00.300
00:20:06.810
What is the key for these two
variables? Your fact file name.

00:20:06.800
00:20:20.010
See we have created a shell script get
underscore HTTP underscore .fact now if you remember in last
class we have discussed about setup module and with filters as
well.

00:20:20.000
00:20:33.010
So, argument filter, here you can
provide one filter such that you're going to get only your custom
facts from this entire facts by default set of facts is going to get all
the facts.

00:20:33.000
00:20:42.610
Now, I can filter I want to get only my
custom facts now custom facts are going to store under ansible
local.

00:20:42.600
00:20:53.910
Now see the result, something like
that see that in ansible facts under ansible local we created only
one fact file.

00:20:53.900
00:21:00.210
That's why this is one-factor file
information the same way if we created multiple facts files for
multiple informations,

00:21:00.200
00:21:11.210
you are going to get or all the
information if you want to get only one fact file, you just create this
shall scape with your required number of values, that's it.

00:21:11.200
00:21:21.510
Now that's fine, as of now, We work
with you are-- Local Host now we need to do this setup on your
manager notes as well.

00:21:21.500
00:21:26.110
See in your real-time, you have some
hundreds of servers to create our custom facts,

00:21:26.100
00:21:29.910
you know need to login into each and
every manner server or not to create them.

00:21:29.900
00:21:32.910
We have answered a lot of commands
we use them.

00:21:32.900
00:21:39.010
So, before going to that first, let me
create all my manuals and nodes under root.

00:21:39.000
00:21:46.710
It is see under ansible facts .d
directory be clear, this is our very first step.

00:21:46.700
00:21:51.210
Anyone ever managed nodes you
have and you don't have ansible and facts .d directory.

00:21:51.200
00:21:54.510
You need to create this directory first.

00:21:54.500
00:22:03.810
Now if you remember from your path
of from your file module we can able to create a directory on your
managed nodes.

00:22:03.800
00:22:08.110
So, you can recollect simply ansible
on all my managed nodes.

00:22:08.100
00:22:12.810
I am going to use the file module, with
arguments as path.

00:22:12.800
00:22:15.610
So, what is the path and the root
EDC?

00:22:15.600
00:22:21.010
I need to create ansible and then
facts.d directory.
00:22:21.000
00:22:23.010
What is the state I need to create a
directory?

00:22:23.000
00:22:29.310
Otherwise, it will become by default
file, that should be a directory now.

00:22:29.300
00:22:38.210
Let me run this, now by these on all
my manager nodes I am going to create and simple .facts that a
tree but that is under root EDC.

00:22:38.200
00:22:48.910
No, that's we're getting permission
denied so, you know if have a root privileges for your answered
many user with hyphen be or hyphen hyphen become you can
execute this ad hoc command on your managed nodes with root

00:22:48.900
00:22:59.110
privileges by providing -b now, I am
running that see that it has been creating change through, change
your true.

00:22:59.100
00:23:07.910
It has been created this directory and
all my manager nodes, right fine.

00:23:07.900
00:23:11.310
What is the next step on all your
managed nodes?

00:23:11.300
00:23:16.910
You need to create a facts, yeah, I'll be
created under inside of your fax the directory.

00:23:16.900
00:23:25.710
You have to create a one fact file with
extension is .fact, So whatever the file you want to create already
we have on your managed nodes.

00:23:25.700
00:23:35.810
So what is that? See through TTC
ansible facts this file already.

00:23:35.800
00:23:40.910
We created and under our Local Host
so same file, I need to create on I mean same file I need to copy
to all.

00:23:40.900
00:23:50.910
I need to create on I mean same file I
need to Copy to all my manager nodes so that I can get my get
watch in and HD DVD version.

00:23:50.900
00:23:54.010
So, guys, how we can copy a file to
your manager nodes.

00:23:54.000
00:23:59.110
So simply ansible all - mm copy
module arguments.

00:23:59.100
00:24:04.810
So what are the source of the
argument? What is your Source on your ansible engine?

00:24:04.800
00:24:20.310
This is the file, then what is the
destination in a remote managed node under root EDC under
ansible under facts dot d same file name.

00:24:20.300
00:24:26.610
What is that file name this one? And
we need to provide execution permission as well.

00:24:26.600
00:24:33.410
Yes, we have one argument to provide
your execution permissions, that's it.

00:24:33.400
00:24:38.910
Now, let me run it through dark
command, it is going to complete your task.

00:24:38.900
00:24:49.510
So what is the problem? Yeah, while
creating facts.d, yeah, that is under root right?

00:24:49.500
00:25:00.210
Let me try with -b option. Yes, then so
what is the direct what is the file you move under?

00:25:00.200
00:25:03.110
I mean the remote location in this
location.

00:25:03.100
00:25:14.310
This is the file now, it is very simple to
collect your get and HTTP version of on all your manage node
simply by running.

00:25:14.300
00:25:21.710
This command set up module with the
filter as ansible local by set up by default going to correct all the
modules.
00:25:21.700
00:25:30.010
I mean all the facts, but we need to
get only our created facts then filter and simple local.

00:25:30.000
00:25:39.510
Now see the result, I run Local Host,
right, not localhost.

00:25:39.500
00:25:43.310
We want to work with our managed
nodes which are there in default inventory.

00:25:43.300
00:25:57.410
Now, if I don't provide any inventory
that is your hands will collect a default inventory based on your
ansible.CFG, so ansible will let me run it.

00:25:57.400
00:26:09.610
See that, on the first server, your git
version is 2.1.4.5, OK we are not getting httpd version.

00:26:09.600
00:26:19.710
So let me do one thing: to TTC and
Sable facts your file.

00:26:19.700
00:26:25.810
Let me provide a complete path for
your httpd, then it's better.

00:26:25.800
00:26:34.910
Root user s bin now, let me copy this
file once again, so I'm going to copy this.

00:26:34.900
00:26:36.510
So, we have a modification in this file.

00:26:36.500
00:26:46.410
That's why your task is going to
execute change it to means now your task has been executed in
case the content which is there in this file and your source file.

00:26:46.400
00:26:53.910
If both are same it won't execute your
task because ansible is idempotent.

00:26:53.900
00:27:12.710
Okay now, let me run, let me collect
your custom facts, yes, now you are getting 2.1.4.5 Apache
version What happened here?

00:27:12.700
00:27:23.910
You're not collecting? Hmm, let me log
into the server.
00:27:23.900
00:27:29.910
Maybe something wrong. Let me
check it.

00:27:29.900
00:27:44.500
Let me run it through TTC and simple
facts.d it's not copied, yeah, we copied for.

00:27:48.400
00:27:55.810
All right, oh, what is wrong here?

00:27:55.800
00:28:02.710
Okay, Target, you just sell in ux but
python building or not installed.

00:28:02.700
00:28:05.510
Yeah, so this is all a chelate, right?

00:28:05.500
00:28:11.910
So, how to work with our hl8, we have
a small procedure for that, we'll discuss later.

00:28:11.900
00:28:15.823
Now anyway for remaining servers
you are able to fetch your information.

00:28:15.823
00:28:19.410
Yeah, one of them or manage servers
is or a chelate in or agility.

00:28:19.400
00:28:26.310
We need to do some setup to work
with your Ansible or commands or playbooks?

00:28:26.300
00:28:31.210
We will see how to work with Aurora
chelate and I will create a separate video for that.

00:28:31.200
00:28:37.710
So, guys, this is the way how we can
create or custom facts and how we can fetch them.

00:28:37.700
00:28:44.610
Right, so these are the steps you need
to remember to create and collect your custom facts.

00:28:44.600
00:28:54.849
Thank you for watching this video.
Transcript
00:00:00.000
00:00:01.900
Friends, here

00:00:01.900
00:00:04.800
we are going to discuss about ansible
inventories.

00:00:05.300
00:00:09.000
See we are using ansible to manage
or to work with a number

00:00:09.000
00:00:13.200
of servers which are there in your
infrastructure and whenever

00:00:13.200
00:00:17.400
if you want to work with your servers
Which are there in

00:00:17.400
00:00:23.600
infrastructure then we are creating a
file with your manage

00:00:23.600
00:00:27.300
servers eyepiece on your ansible
engine and that file is
00:00:27.300
00:00:28.600
called ansible inventory.

00:00:29.500
00:00:33.700
So simply the collection of host is
known as ansible inventory.

00:00:34.400
00:00:37.000
Let me show you already we know
that let me show you on my

00:00:37.000
00:00:39.500
ansible engine the suppose.

00:00:39.500
00:00:41.100
I have a host file.

00:00:41.200
00:00:45.800
So this is ansible inventory file and in
these directly you

00:00:45.800
00:00:46.400
can mention.

00:00:46.500
00:00:49.400
Hours without any groups, but based
on functionality.

00:00:49.400
00:00:50.700
We can also group them.

00:00:51.300
00:00:53.700
Somebody bees are were some our
web server some or middleware

00:00:53.700
00:00:56.800
server some more some monitoring
tool servers, right?

00:00:57.000
00:00:58.300
That is our requirement.

00:00:59.100
00:00:59.700
That's fine.

00:01:00.400
00:01:03.700
But in you are answerable, we have
two types of inventories

00:01:03.700
00:01:06.900
one is static inventory and one more is
dynamic inventory.

00:01:09.200
00:01:13.400
See static inventory is nothing but up
to now whatever the
00:01:13.400
00:01:16.000
inventory file we use that is static
inventory.

00:01:16.900
00:01:21.900
And once if you write your eyepiece in
your inventory file,

00:01:21.900
00:01:27.300
then they are fixed suppose just
assume that these are the

00:01:27.300
00:01:29.700
my public IP smaller my manager
words.

00:01:30.800
00:01:34.700
I know just one hour before actually, I
stopped my manager

00:01:34.700
00:01:38.200
verse on my lbs cloud and just now I
restarted them.

00:01:39.300
00:01:42.600
So because of that what will happen
your public IP will change

00:01:42.600
00:01:46.300
but now this inventory file won't work
with your AWS cloud

00:01:46.300
00:01:50.200
with for your manage servers because
we stopped and started

00:01:50.200
00:01:51.000
our manage servers.

00:01:51.000
00:01:54.700
Now eyepiece has been changed Now
new IPS are there so what

00:01:54.700
00:01:57.500
you have to do you need to go to your
AdWords account and

00:01:57.500
00:02:00.900
you need to copy your public IP for
each and every server

00:02:00.900
00:02:04.500
and then you have to copy that IPC
how to paste in this inventory
00:02:04.500
00:02:08.199
file. Here you have to taste it then only
this inventory

00:02:08.199
00:02:10.100
file will work with your manage
servers.

00:02:11.199
00:02:14.000
But I assume that you have some
hundreds of servers or thousands

00:02:14.000
00:02:14.700
of servers.

00:02:15.100
00:02:19.000
If you stop on start then for all
thousands of servers, you

00:02:19.000
00:02:22.500
need to manually copy and paste your
public IP is not is

00:02:22.500
00:02:24.500
not a good practice waste of time.

00:02:25.900
00:02:26.300
Right.

00:02:26.600
00:02:31.900
So whenever if you have a servers
and if your servers are

00:02:31.900
00:02:36.700
going to change your eyepiece,
dynamically, then at the time

00:02:36.700
00:02:39.800
you can use some different inventory
file that is called

00:02:39.800
00:02:40.900
Dynamic inventory.

00:02:42.800
00:02:48.200
Right and this dynamic entry is simply
a script that script

00:02:48.200
00:02:50.500
maybe she'll or python or maybe any
script.

00:02:51.900
00:02:55.500
And this Dynamic inventories are
useful for dynamic environments.
00:02:56.700
00:03:00.200
Let's say a very simple example, if you
stop and start your

00:03:00.200
00:03:02.000
servers you are going to change your
IP.

00:03:02.000
00:03:05.700
I mean your AWS servers are going to
get new public IP.

00:03:06.100
00:03:08.600
That is dynamic environment, right?

00:03:08.600
00:03:12.400
Not only AWS Cloud environments or
basically Dynamic environments.

00:03:14.100
00:03:17.700
Now if you want to work with Dynamic
inventories with your

00:03:17.700
00:03:20.700
Dynamic environments, then Dynamic
inventory is the best

00:03:20.700
00:03:23.900
one. But not mandatory that is the
best one.

00:03:24.400
00:03:26.400
It's better to use Dynamic inventory
whenever if you are

00:03:26.400
00:03:29.100
going to work with your Cloud
environment.

00:03:30.700
00:03:35.000
Right and guys I am saying that this
Dynamic environment

00:03:35.100
00:03:38.600
this Dynamic inventory is a shell or
python script, but don't

00:03:38.600
00:03:41.200
worry, you know need to implement
this Dynamic inventory

00:03:41.700
00:03:45.800
by default ansible is going to support
with some scripts

00:03:45.800
00:03:46.900
for some clouds.
00:03:47.200
00:03:50.700
Let's say some of the clouds AWS ec2
open Stock Google Cloud

00:03:50.700
00:03:56.700
engine spacewalk as your jails some
other clouds for that

00:03:56.700
00:03:59.200
clouds already and still has developed
a dynamic inventory

00:03:59.200
00:04:05.100
script. Fine now before going to work
with your Dynamic inventory.

00:04:05.100
00:04:08.300
I want to show you one more thing see
as of now.

00:04:10.500
00:04:14.000
We have this inventory and this
inventory information is

00:04:14.000
00:04:15.400
there in your ansible.

00:04:15.400
00:04:16.300
CFG file?

00:04:19.300
00:04:23.500
Suppose if I want to work with any
other inventory other

00:04:23.500
00:04:29.300
than this inventory file what we can do
ansible we can mention

00:04:29.300
00:04:33.900
our custom inventory file by using
simply - I some inventory

00:04:34.000
00:04:35.800
in that you may have any number of
servers.

00:04:36.300
00:04:40.600
So I want to work with all let's say I
want to check ping

00:04:40.600
00:04:47.100
activity. But same thing if I go and
work with my default

00:04:47.100
00:04:50.400
inventory, you are not going to get that
because those are
00:04:50.400
00:04:54.000
the my eyepiece for before one hour.

00:04:54.100
00:04:56.100
Now, I stopped and started my
servers.

00:04:56.100
00:04:58.200
Now you're going to get new eyepiece.

00:04:58.700
00:05:01.600
That's why previously whatever you
have your eyepiece in

00:05:01.600
00:05:03.100
your static inventory file.

00:05:03.200
00:05:07.600
Those are not going to work with my
environment see that

00:05:07.800
00:05:13.300
not able to reach But in this type of
situation you need

00:05:13.300
00:05:14.700
to work with Dynamic inventory.

00:05:14.700
00:05:17.900
So what dynamic inventory will do
Dynamic inventory will

00:05:17.900
00:05:19.700
fetch automatically your eyepiece.

00:05:21.400
00:05:21.800
Right.

00:05:22.300
00:05:27.600
Anyway, first of all, I am saying that
already Dynamic inventory

00:05:27.600
00:05:31.100
skits or there with your ansible, you
know need to develop

00:05:31.400
00:05:34.300
but if you want to develop your custom
Dynamic inventory,

00:05:34.400
00:05:36.900
then you have to write some Python
scripts or shell scripts.

00:05:37.900
00:05:40.100
So suppose if you are good at shell
script just go and Implement
00:05:40.100
00:05:44.800
shell script to find your IP is
dynamically or python.

00:05:44.800
00:05:45.800
Just go with python.

00:05:46.400
00:05:55.600
Anyway, let me open my
docs.google.com website so we are

00:05:55.600
00:05:57.900
going to work with inventory let's
select here inventory

00:05:58.400
00:06:01.800
and if You observe here somewhere
we have Dynamic inventories

00:06:01.900
00:06:04.800
just select this working with Dynamic
inventories and if

00:06:04.800
00:06:07.700
You observe here we have inventory
scripts just click on

00:06:07.700
00:06:13.900
that now here based on your
environment maybe Azure or Google

00:06:13.900
00:06:16.800
cloud or AWS Cloud we have different
types of dynamic real

00:06:16.800
00:06:21.900
Dynamic Scripts As of now I want to
work with AWS Cloud.

00:06:22.000
00:06:28.000
So we have here Dynamic inventory
scripts for your AWS Cloud.

00:06:28.600
00:06:33.400
So now if you want to work with your
AWS Cloud using Dynamic

00:06:33.400
00:06:36.100
inventory, what we have to do is first
of all, you need to

00:06:36.100
00:06:39.500
download these two files from your
official repository of
00:06:39.500
00:06:43.400
tangible. So just go and open these
two files.

00:06:46.000
00:06:50.200
Copy and paste it and provide the
same name on your localhost.

00:06:50.200
00:06:53.700
I mean on your ansible engine so
already I download them

00:06:54.500
00:06:55.000
see that.

00:06:56.900
00:07:00.800
I how this is e 2 dot p y and easy to
Dot N I so this is

00:07:00.800
00:07:01.600
dynamic inventory.

00:07:01.700
00:07:03.600
And for this some settings are there in
this?

00:07:04.000
00:07:05.000
So what are those settings?

00:07:05.000
00:07:08.000
I will show you then suppose.

00:07:08.100
00:07:10.900
We have a python script and already I
have a execution permission

00:07:10.900
00:07:11.400
for that.

00:07:12.400
00:07:13.800
Now, let me try to run that.

00:07:15.900
00:07:22.500
See the result no module named both
to see this is a python

00:07:22.500
00:07:25.300
script and you are going to work with
your AWS cloud.

00:07:28.500
00:07:32.900
So if you want to work with AWS
Cloud using python, you need

00:07:32.900
00:07:35.000
both to orbit, two three modules
suppose.
00:07:35.000
00:07:38.900
This is using both the ones but
priorities for Bo to now,

00:07:38.900
00:07:39.900
let me show you.

00:07:41.300
00:07:44.600
By gripping simply bow to see that it is
going to use boot

00:07:44.900
00:07:48.400
photo 3 as well as boto if photo is
there is going to work

00:07:48.400
00:07:50.400
with boto if what are the reasons that it
is going to work

00:07:50.400
00:07:55.100
with moto3 now, let me install your
boat of first so pseudo.

00:07:56.300
00:08:02.800
pip to install boto We install now let
me run it and see

00:08:02.800
00:08:03.600
the result.

00:08:04.700
00:08:06.600
Yeah before going to run that.

00:08:09.300
00:08:16.300
see We how to work with our AWS
Cloud using your python script.

00:08:16.800
00:08:20.200
So with what AWS account you want
to work.

00:08:21.300
00:08:24.800
So for that for that account related
programmatic access

00:08:24.800
00:08:29.100
keys or credentials, you need to
configure on your environment

00:08:29.100
00:08:33.299
on your Ansel engine or you can also
assign I am roll to

00:08:33.299
00:08:36.100
your ansible engine if you are ansible
server is also from
00:08:36.100
00:08:37.200
your AWS Cloud.

00:08:37.600
00:08:41.100
So anyway, our ansible engine is from
our AWS Cloud now I

00:08:41.100
00:08:48.100
am going to assign Roll to my aunt's
Bill engine, but I already

00:08:48.100
00:08:48.700
assigned first.

00:08:48.700
00:08:52.700
Let me remove that so that I will run
my script and I will

00:08:52.700
00:08:53.400
show you that.

00:08:56.000
00:08:56.600
No roll.

00:09:00.100
00:09:05.200
apply close it now.

00:09:05.200
00:09:08.600
Let me run it your script once so what
is the result you're

00:09:08.600
00:09:12.900
going to get Observer at the end
check your credentials see

00:09:12.900
00:09:15.600
with what account you want to work
that credentials you need

00:09:15.600
00:09:19.700
to pass on your host second way is
you can also assign a

00:09:19.700
00:09:23.800
role for your ansible engine server if
that is from AWS Cloud.

00:09:24.600
00:09:27.100
So anyway, our engine is from AWS
Cloud now, I am going to

00:09:27.100
00:09:27.900
assign a role.

00:09:31.200
00:09:32.100
Attach or replace.

00:09:32.100
00:09:32.800
I am roll.
00:09:33.000
00:09:36.700
I'm going to select any one of the role
already created a

00:09:36.700
00:09:42.100
role such that the troll is having full
easy to access.

00:09:42.900
00:09:45.700
So if you want to know how to create
just simply create a

00:09:45.700
00:09:46.300
new role.

00:09:47.900
00:09:48.600
Go to here.

00:09:49.000
00:09:54.200
So what is the role we want to create
for easy to just select

00:09:54.200
00:09:56.700
ec2 here and next permissions.

00:09:57.100
00:10:00.400
So I need to give easy to full
permissions.

00:10:01.800
00:10:05.200
Because my script has to work with
easy to just if you want

00:10:05.200
00:10:06.600
to provide tax you can provide.

00:10:07.700
00:10:12.900
Then let's let's say ec2 full access.

00:10:15.100
00:10:18.800
For ansible now, I will select this one.

00:10:21.300
00:10:23.500
Now go to your page refresh it.

00:10:25.800
00:10:27.900
This one is easy to full access for
ansible.

00:10:28.100
00:10:28.600
That's it.

00:10:28.800
00:10:32.600
Now assign that role for your ec2
instance.

00:10:33.300
00:10:36.100
I mean ansible engine server now, let
me run it and see the
00:10:36.100
00:10:38.200
result what you are going to get.

00:10:40.800
00:10:44.800
You're going to get some information
about your AWS manage

00:10:44.800
00:10:47.500
servers. But If You observe here we
are getting different

00:10:47.500
00:10:52.300
informations. like some facts of your
manage servers through

00:10:52.300
00:10:58.100
your ec2 that py right now just come
down on somewhere.

00:10:58.100
00:11:02.100
You can see you're all ec2 instances
are with the group called

00:11:02.100
00:11:05.200
easy to now this is a group name.

00:11:05.200
00:11:09.500
So in our normal inventory file
suppose, if I open cat host

00:11:09.500
00:11:11.800
with DB there is a group under this
group.

00:11:11.800
00:11:13.000
I have these two servers.

00:11:13.300
00:11:16.500
So by default your ec2 not be Y is
going to give a group

00:11:16.500
00:11:19.800
called ec2 under that you're going to
get all your eyepiece.

00:11:21.100
00:11:21.700
That's fine.

00:11:23.200
00:11:26.500
I know if I want to check with the
connectivity of all these

00:11:26.500
00:11:31.000
servers what I have to do simply
ansible - I now we don't

00:11:31.000
00:11:32.100
how static inventory.
00:11:32.100
00:11:32.600
Dynamically.

00:11:32.600
00:11:34.500
We have to fetch our servers now.

00:11:34.500
00:11:38.600
Let me run our easy to let me provide
inventory as a script

00:11:39.300
00:11:43.500
C. We know - is - I is for custom
inventory now ec2 dot p

00:11:43.500
00:11:46.200
y is the dynamic inventory that
inventory will fetch your

00:11:46.200
00:11:49.300
servers in the at just now we have
seen one of the group

00:11:49.300
00:11:51.900
called is you to now with all those
servers.

00:11:51.900
00:11:53.900
I I want to check ping activity.

00:11:55.200
00:11:56.900
See the result what you're going to
get.

00:11:58.400
00:12:00.900
So easy to is one of the group by
default which you are going

00:12:00.900
00:12:03.000
to get by using your Dynamic
inventory.

00:12:04.200
00:12:07.300
Yes, all servers are able to reach now.

00:12:07.300
00:12:10.400
Let me run once again our static
inventory.

00:12:10.800
00:12:14.200
We have we may have any number of
groups right in our inventory

00:12:14.200
00:12:18.500
based on our required servers the
same way by default.
00:12:18.500
00:12:23.200
Your ec2 dot p y is going to give some
groups just observe

00:12:23.200
00:12:23.900
all the groups.

00:12:25.800
00:12:31.100
see based on Region, it has given
based on John also has

00:12:31.100
00:12:34.400
given with what John you want to work
with what region you

00:12:34.400
00:12:35.500
want to work that group.

00:12:35.500
00:12:38.900
You have to select while working with
this is default inventory

00:12:38.900
00:12:42.700
guys. I mean ansible is providing one
inventory for your

00:12:43.300
00:12:47.000
AWS Cloud, but if you want to create
your custom class dynamically

00:12:47.000
00:12:48.400
based on your required group.

00:12:48.400
00:12:51.300
Yes, we can also create so in next
video, we will see that

00:12:51.300
00:12:54.500
how to create custom inventory with
custom group names.

00:12:55.800
00:12:57.100
Okay fine ansible.

00:12:58.400
00:13:03.300
- I your Dynamic script and I want to
work with suppose U

00:13:03.300
00:13:05.600
s-- is one year servers.

00:13:05.600
00:13:07.600
Yes provide that group name then.

00:13:07.600
00:13:10.400
Just let me run a task called ping task.

00:13:11.900
00:13:14.800
Yes, it's giving right changed false.
00:13:14.800
00:13:18.100
Anyway ping response is pong means
yes, you are able to reach

00:13:18.100
00:13:18.900
with that server.

00:13:19.800
00:13:21.800
That's fine now.

00:13:23.200
00:13:27.200
Assume that I am going to add new
servers already.

00:13:27.200
00:13:30.200
I installed I mean I launched but let me
start it.

00:13:30.400
00:13:33.700
If I start this server This Server is also
going to fetch

00:13:33.700
00:13:38.600
by your Dynamic inventory script but
we have a small problem

00:13:38.600
00:13:39.800
while working with the servers.

00:13:39.900
00:13:42.200
I want to show you that that's why I
launched this.

00:13:43.000
00:13:46.500
Let me run this just wait for some time.

00:13:46.600
00:13:47.900
It's very very important guys.

00:13:48.000
00:13:48.700
Be careful.

00:13:54.900
00:14:00.500
Now the IP for this is 384 to and for
now, let me run your

00:14:00.500
00:14:04.100
inventory script once just now I run
that right.

00:14:09.200
00:14:09.900
Is it running?

00:14:09.900
00:14:10.600
Yeah, no.

00:14:10.700
00:14:12.900
Let me yeah now it's running.
00:14:12.900
00:14:15.300
Let me run your script once and see
the result.

00:14:19.900
00:14:20.700
What happened?

00:14:23.800
00:14:30.000
easy to see why Okay, just to go to
your ec2 group.

00:14:30.300
00:14:31.400
Where is your ec2?

00:14:33.500
00:14:35.000
One two three four.

00:14:35.300
00:14:37.300
Oh man, it's running right or happen.

00:14:39.500
00:14:41.200
Oh Liesl still it is initializing.

00:14:41.200
00:14:41.800
Just wait.

00:15:00.600
00:15:02.300
And now let me run once again.

00:15:02.300
00:15:04.600
You are easy to dot py script.

00:15:24.200
00:15:24.900
Just wait.

00:15:33.900
00:15:34.300
.

00:15:34.300
00:15:38.300
Easy to sorry dot slash easy to dot P.

00:15:38.300
00:15:38.700
Why?

00:15:48.300
00:15:49.600
Where is your ec2?

00:15:52.400
00:15:53.600
It's not picking.

00:16:07.000
00:16:07.900
Just wait.

00:16:09.600
00:16:11.400
It's taking time to initialize.

00:16:20.000
00:16:27.200
motor running just wait or observe the
output now for this
00:16:27.200
00:16:31.300
script. Under easy to see that how
many instances are there

00:16:31.300
00:16:34.400
previously we have only for now we
have Phi what is that

00:16:34.400
00:16:35.000
extra one?

00:16:35.000
00:16:40.200
Just now we launched one server,
right 384 1012 and for this

00:16:40.200
00:16:45.600
one. Yes, now you are able to collect
our you Oliver instances,

00:16:45.600
00:16:50.500
but now let me check that or able to
Ping with all your servers

00:16:50.500
00:16:51.100
or not.

00:16:52.400
00:16:53.100
Be clear.

00:16:54.100
00:16:56.700
I'm going to run first ping activity with
all my servers

00:16:57.000
00:17:00.300
then we will see the We'll go with the
discussion.

00:17:01.200
00:17:02.300
So under easy to group.

00:17:02.300
00:17:03.200
We have all servers.

00:17:03.200
00:17:05.300
I want to check the connectivity with
all servers.

00:17:06.098
00:17:07.900
You're going to get only for for servers.

00:17:07.900
00:17:10.598
You are not going to get for one server
that salary just

00:17:10.598
00:17:11.598
now we launched it.

00:17:12.598
00:17:14.300
What is the reason you can guess?
00:17:18.400
00:17:23.400
permission denied the reason is
because if you remember if

00:17:23.400
00:17:26.000
you want to work with your manager
servers, you can work

00:17:26.000
00:17:28.700
with using two ways One is using
password one more is using

00:17:28.700
00:17:30.200
password less and one more thing.

00:17:30.500
00:17:32.700
You have to create suppose a man's
admin user.

00:17:32.800
00:17:33.700
That's not mandatory.

00:17:33.700
00:17:37.900
But of course we created one
answered me user on all your

00:17:37.900
00:17:40.800
manage servers but this server just
now we launched, you

00:17:40.800
00:17:44.599
know, there is no configuration for this
server to work with

00:17:44.599
00:17:46.400
your ansible first thing.

00:17:46.500
00:17:49.599
You have to know some user of that
server and then some password

00:17:49.599
00:17:50.400
for that server other.

00:17:50.500
00:17:53.000
Guys, you should have you should
have a sump as well as authentication

00:17:53.000
00:17:56.700
between those two servers, but we
didn't do that configuration

00:17:56.700
00:17:58.400
then how it will work with your ansible.

00:17:58.900
00:18:00.500
That's why it is giving permission
denied.
00:18:01.800
00:18:02.200
Right.

00:18:02.500
00:18:04.700
So in real time, you won't do like this.

00:18:06.400
00:18:07.500
Let me stop it.

00:18:09.500
00:18:10.800
Then how you are going to work?

00:18:12.100
00:18:17.600
See suppose you are going to use
Auto scaling concept then

00:18:17.600
00:18:19.000
in your auto scaling group.

00:18:19.200
00:18:20.800
What you will do first.

00:18:20.800
00:18:23.500
You will set up one server and for that
server, you will

00:18:23.500
00:18:27.000
take one Ami from the tummy you are
going to launch your

00:18:27.000
00:18:29.900
servers using Auto scaling group now
already.

00:18:29.900
00:18:33.800
This is my manager node and through
which I mean for this

00:18:33.800
00:18:36.900
I'm using I can able to use my ansible
as of now.

00:18:36.900
00:18:41.800
That's why from this node if I create
some extra nodes automatically

00:18:42.000
00:18:44.900
And also work with that because that
is the copy of your

00:18:44.900
00:18:46.200
existing node, right?

00:18:46.900
00:18:50.000
That means already same
configuration details are there on
00:18:50.000
00:18:53.300
the new servers which you are going
to launch the first of

00:18:53.300
00:18:54.600
all, let me take Maya me.

00:18:57.800
00:18:57.900
Okay.

00:18:57.900
00:18:59.200
This is very very important.

00:18:59.300
00:18:59.900
Most of the people.

00:18:59.900
00:19:04.300
They don't know they will try to run by
launching new servers.

00:19:04.300
00:19:07.600
They will try to run this do command
or something any commands,

00:19:07.600
00:19:09.900
but they are going to get error like this
permission denied

00:19:10.600
00:19:12.900
but we are saying that Dynamic
inventory is going to fetch

00:19:12.900
00:19:15.100
automatic all the IPS so that we can
work with that.

00:19:15.800
00:19:18.600
But yes Dynamic inventory will fetch
all the eyepiece of

00:19:18.600
00:19:21.100
your manager notes whenever if you
launch some new servers,

00:19:21.800
00:19:25.400
but there is a some condition based
on your requirement.

00:19:25.400
00:19:27.400
You need to create your servers and
with that.

00:19:27.600
00:19:31.200
Verse you can work but while creating
your servers suppose
00:19:31.200
00:19:35.100
I am taking one of the example
automatically I need to do

00:19:35.100
00:19:36.000
some configuration.

00:19:36.000
00:19:38.200
Also on my new launcher server.

00:19:39.500
00:19:41.300
So in order scaling group what we will
do.

00:19:42.700
00:19:50.700
suppose ansible node, I am taking Let
me create an image

00:19:50.700
00:19:57.400
first. Now if I create a new man a
server from this then

00:19:57.500
00:20:02.600
this configuration is also I mean from
this Ami then this

00:20:02.900
00:20:06.400
from this of me if I create a new
manager server then on

00:20:06.400
00:20:10.400
that also automatically I have
answered main user and I did

00:20:10.400
00:20:12.800
already configuration on my node one
from that.

00:20:12.800
00:20:15.000
We are going to create a new server,
right?

00:20:15.000
00:20:17.000
That's why on the new manager
server.

00:20:17.400
00:20:19.300
We have answered Min user.

00:20:19.600
00:20:22.200
Already he's or also Exchange.

00:20:24.400
00:20:28.700
That's why from this Ami if you are
able to create a server,
00:20:28.700
00:20:34.800
then you can work with that
automatically without any errors.

00:20:35.900
00:20:38.800
I'm not sure whether you are able to
reach with this concept

00:20:38.800
00:20:43.100
or not, but That is the concept.

00:20:44.300
00:20:46.900
So simply most of the times people
what they will do they

00:20:46.900
00:20:47.200
are die.

00:20:47.200
00:20:48.200
We have Dynamic inventory.

00:20:48.200
00:20:51.000
We will run Dynamic inventory and
they are trying to run

00:20:51.000
00:20:53.700
some modules with your I mean out of
comments of playbooks

00:20:53.700
00:20:55.900
with a new launch servers, but they
are going to get an error

00:20:55.900
00:20:57.100
called permission denied.

00:20:57.600
00:20:59.400
Yes, definitely will get permission
denied.

00:21:00.300
00:21:02.300
The reason is with that server.

00:21:02.300
00:21:04.700
You need to do some configuration no,
see whenever if you

00:21:04.700
00:21:07.100
want to work with your manage
servers using ansible.

00:21:07.200
00:21:10.800
We are doing some configuration
across all the server's suppose.

00:21:10.800
00:21:13.300
We are going to create answered
been user then we are going
00:21:13.300
00:21:14.000
to exchange.

00:21:14.200
00:21:17.100
Keys from your aunt's admin user with
your nodes.

00:21:19.100
00:21:21.900
Then only you can able to
communicate with your manager nodes.

00:21:22.300
00:21:26.300
So that's why now suppose whatever
the server I am going

00:21:26.300
00:21:26.900
to launch.

00:21:26.900
00:21:30.900
Newly that server is from my Node 1
but in Node 1 already

00:21:30.900
00:21:34.100
how configuration details that Node 1
details are also going

00:21:34.100
00:21:37.300
to reflect our New Image new
instance.

00:21:38.400
00:21:41.500
Because from this week later Amy
from the tummy, we create

00:21:41.500
00:21:42.300
a new server.

00:21:42.400
00:21:43.700
That's why you don't have any
problem.

00:21:43.900
00:21:46.200
You can able to communicate with the
new launcher server.

00:21:46.600
00:21:46.800
Now.

00:21:46.800
00:21:48.600
Let me run it and see the result first.

00:21:48.600
00:21:51.600
I mean first let me collect my all
eyepiece.

00:21:51.800
00:21:56.100
So what is the launch for instance this
one right double
00:21:56.100
00:22:00.800
nine? Yes, we are able to get double
line under this ec2

00:22:00.800
00:22:05.800
group. This Server You are four
servers previously you have

00:22:05.800
00:22:08.600
now. This is the server just now we
launched so previously

00:22:08.600
00:22:12.300
whenever if you run your ansible all
iPhone em ping command,

00:22:12.300
00:22:14.600
you are able you are not able to reach
with the server.

00:22:15.300
00:22:18.300
The reason is that sir is not having
configuration details.

00:22:18.800
00:22:23.800
Now if I run my ansible all - am I mean
easy to iPhone jumping

00:22:24.700
00:22:28.100
you can able to reach with your new
server as well.

00:22:30.900
00:22:31.600
Just wait.

00:22:33.800
00:22:37.000
Your new server is what is the IP
double nine?

00:22:37.800
00:22:38.800
Just check it varies double.

00:22:38.800
00:22:39.100
Nine.

00:22:39.700
00:22:40.300
Last one.

00:22:41.300
00:22:45.500
One, two, three four.

00:22:45.600
00:22:46.500
Yeah, first one.

00:22:47.000
00:22:48.100
Yes ping-pong.
00:22:49.200
00:22:51.800
Reading response for your ping model
response as pong.

00:22:51.900
00:22:55.800
That means now your arms will is able
to reach with your

00:22:55.800
00:22:57.400
new launch server?

00:22:58.700
00:23:03.100
So guys in your real time, we simply
launch your server and

00:23:03.100
00:23:04.700
we won't work with that.

00:23:05.300
00:23:10.300
So before going to launch, we have
some requirements automatically,

00:23:10.300
00:23:12.700
we have some configuration on your
new launcelot then only

00:23:12.700
00:23:16.400
your answer will reach with that server
one is same user

00:23:16.400
00:23:19.300
and suppose password or second one
is possible as authentication,

00:23:21.000
00:23:24.600
right? So here very important point is
automatically how

00:23:24.600
00:23:27.500
you got past or less on education with
this server.

00:23:28.700
00:23:31.000
The reason is from this manage node.

00:23:31.000
00:23:32.300
We created a me.

00:23:32.500
00:23:34.700
That's why whatever the
configurations are there with this

00:23:34.700
00:23:38.400
Ami. Sorry, what are the
configurations are there with this
00:23:38.400
00:23:40.700
node? They are going to store I me
now from this.

00:23:40.700
00:23:44.100
I mean we launched This Server that's
why this information

00:23:44.100
00:23:44.800
reflected here.

00:23:44.800
00:23:47.600
That's why we are able to reach with
the server using ansible.

00:23:49.200
00:23:50.500
So that is my point.

00:23:50.500
00:23:52.700
I want to say here, right?

00:23:54.200
00:23:56.100
Okay guys, thank you for watching this
video.
Transcript
00:00:00.000
00:00:02.200
Friends here

00:00:02.200
00:00:06.000
we are going to discuss about how to
create a simple custom

00:00:06.000
00:00:10.810
dynamic inventory script for AWS ec2
instances using tags

00:00:10.800
00:00:12.209
seen by default.

00:00:12.200
00:00:15.800
We have dynamic inventory script for
your AWS ec2 instances

00:00:15.800
00:00:17.700
in your ansible repository.

00:00:17.700
00:00:19.610
[no audio]

00:00:19.600
00:00:23.310
You don't need to implement any extra
custom dynamic inventory.
00:00:23.300
00:00:27.110
But if you want based on your
requirement, yes, we can implement.

00:00:27.100
00:00:29.700
So for that I am going to show you
simple scripts and I am

00:00:29.700
00:00:32.200
taking here example as based on
tags.

00:00:32.200
00:00:35.010
I am going to implement my dynamic
inventory.

00:00:35.000
00:00:38.600
Let me show you first of all my
environment. See if you observe

00:00:38.600
00:00:41.200
here. I have three nodes 3 manage
nodes.

00:00:41.200
00:00:43.510
I am going to manage with my ansible.

00:00:43.500
00:00:47.100
And if you observe first node, I am
taking tags in the at

00:00:47.100
00:00:49.309
Env value as DB.

00:00:49.300
00:00:54.210
In tag suppose here DB so Node 1 is
DB node 2 is app server

00:00:54.200
00:00:56.400
and node 3 is DB server.

00:00:56.400
00:00:59.800
So to DB servers one, one app server.
Now.

00:00:59.800
00:01:03.400
What I want to do is if I run my
dynamic inventory step

00:01:03.400
00:01:06.310
I should get output.

00:01:06.300
00:01:07.410
[corrective speech]

00:01:07.400
00:01:10.900
I should have two groups DB group
and our group in that way.
00:01:10.900
00:01:14.210
I need to implement any way before
going to implement.

00:01:14.200
00:01:19.210
Let me run your default or your
dynamic

00:01:19.200
00:01:22.110
inventory, which is there with your
ansible for your AWS

00:01:22.100
00:01:24.810
instances that is ec2.py right?

00:01:24.800
00:01:28.010
So in our previous video we have
been downloaded this right

00:01:28.000
00:01:34.410
see that. And if I run this you don't put
what you are getting.

00:01:34.400
00:01:36.510
You are getting different groups.

00:01:36.500
00:01:37.500
This is one group.

00:01:37.500
00:01:38.300
This is one group.

00:01:38.300
00:01:39.100
This is one group.

00:01:39.100
00:01:40.910
This is one group, right?

00:01:40.900
00:01:43.510
So each group purpose is different
suppose.

00:01:43.500
00:01:46.510
If you observe this group you are here
you are going to get

00:01:46.500
00:01:51.400
from your AWS account all IPs, which
are t2.micro

00:01:51.400
00:01:56.300
servers. If you go to here from region
1US.

00:01:56.300
00:02:01.500
East 1, what are the IPS or if you go
with here from this
00:02:01.500
00:02:06.200
Zone, what are the IPs. Likewise and
if you observe somewhere

00:02:06.200
00:02:09.400
is also giving our tags information as
well see that we have

00:02:09.400
00:02:13.500
app server one app server and we
have DB servers to it by

00:02:13.500
00:02:15.500
default is fetching. You now need to
implement for your

00:02:15.500
00:02:16.700
requirement by default.

00:02:16.700
00:02:21.310
You are going to get max all the
required groups.

00:02:21.300
00:02:25.000
Even though if you want to implement
other than this dynamic

00:02:25.000
00:02:27.600
inventory, if you want to use your own
custom dynamic inventory

00:02:27.600
00:02:30.100
then how we can implement for that
here.

00:02:30.100
00:02:34.910
I am going to show you a simple
words simple python script.

00:02:34.900
00:02:37.700
Of course, you can implement your
dynamic inventory using

00:02:37.700
00:02:39.209
shell script as well.

00:02:39.200
00:02:42.500
But before going to implement you
need to remember that the

00:02:42.500
00:02:45.810
output of your dynamic inventory script
is always a Json file.

00:02:45.800
00:02:48.109
I mean Json output format.
00:02:48.100
00:02:50.410
So if you observe here this entire thing
is adjacent

00:02:50.400
00:02:54.300
format. So curly brace starting you
have curly brace if you

00:02:54.300
00:02:59.100
go up and this is a key. And these are
the values like dictionary

00:02:59.100
00:03:03.709
in your python, but this is a string in
your Json. All right.

00:03:03.700
00:03:05.300
So in this way you need to implement.

00:03:05.300
00:03:08.400
So if I run my python script I need to
get output in terms

00:03:08.400
00:03:13.600
of Json in the I need to have DB group
and app Group then

00:03:13.600
00:03:16.910
how we can implement for that?

00:03:16.900
00:03:20.910
See, I'm going to implement AWS

00:03:20.900
00:03:30.500
dynamic inventory.py. See, I'm going
to run python script

00:03:30.500
00:03:33.300
then I need to mention first of all the
location of your

00:03:33.300
00:03:39.209
python. So on my server how python
in this location then

00:03:39.200
00:03:42.209
see if you want to work with your AWS
services using python.

00:03:42.200
00:03:45.900
You need a module called boto3. And
this is not the default

00:03:45.900
00:03:49.900
module. That's why you need to take
care about this. Try Import.
00:03:49.900
00:03:59.500
boto3 in case if you get any exception
I want to catch that.

00:03:59.500
00:04:02.709
[no audio]

00:04:02.700
00:04:06.500
Print e. And suppose just as in but if
you are not having

00:04:06.500
00:04:09.100
boto3, you're going to get exception.
Other time

00:04:09.100
00:04:10.300
you need to stop your script.

00:04:10.300
00:04:14.459
So I am going to import default
module called sys.

00:04:14.450
00:04:18.000
Then print. Please

00:04:18.000
00:04:21.209
[no audio]

00:04:21.200
00:04:32.400
rectify above exception and then try
again.

00:04:32.400
00:04:36.909
[no audio]

00:04:36.900
00:04:40.800
So if I if we don't have both our tree on
our host then

00:04:40.800
00:04:42.200
we need to stop our script.

00:04:42.200
00:04:44.710
[no audio]

00:04:44.700
00:04:47.800
With some error code let's say one so
actually by default.

00:04:47.800
00:04:51.000
I have bought two three just observe
that let me provide

00:04:51.000
00:04:52.400
execution permissions first.

00:04:52.400
00:04:54.600
This is important to guys you should
have a execution permissions.
00:04:54.600
00:04:57.900
Otherwise your hands will won't run
this script. Now.

00:04:57.900
00:05:01.700
Let me run this see the output
everything is fine because

00:05:01.700
00:05:03.300
already I have both on my host.

00:05:03.300
00:05:06.500
If you don't have boto3, then you need
to install your

00:05:06.500
00:05:09.000
boto3 by using pip install boto3.

00:05:09.000
00:05:11.010
[no audio]

00:05:11.000
00:05:17.460
Or if it is you fear having pip2 then
pip2 install.

00:05:17.450
00:05:21.500
Boto3 so I'm having python to right so
already we reach

00:05:21.500
00:05:25.510
this condition no need to install this.
That's fine.

00:05:25.500
00:05:28.800
And one more thing you want to work
with your partner AWS

00:05:28.800
00:05:32.100
account. Then you need to provide
your credentials on this

00:05:32.100
00:05:35.600
host or you need to assign a
shootable required.

00:05:35.600
00:05:38.000
I am role to this AWS ec2 instance.

00:05:38.000
00:05:41.300
I mean your ansible engine server. For
your ansible engine server,

00:05:41.300
00:05:44.510
you need to assign some IAM role so
that we can implement
00:05:44.500
00:05:46.800
We can run our python script from
here using your boto

00:05:46.800
00:05:51.000
3. So already we saw that how to
assign your role for

00:05:51.000
00:05:54.400
your required ec2 instance right in our
previous video.

00:05:54.400
00:05:56.610
We seen that.

00:05:56.600
00:06:01.110
Now Let me open our dynamic
inventory script.

00:06:01.100
00:06:05.800
So first of all, let me follow my
standard syntax for python

00:06:05.800
00:06:06.967
scripts.

00:06:06.959
00:06:10.418
[no audio]

00:06:10.459
00:06:12.409
I did just for editors.

00:06:12.400
00:06:15.310
No need to use this custom menu
entry dynamic inverter script

00:06:15.300
00:06:17.800
by default your default color dynamic
inventor script is

00:06:17.800
00:06:22.200
going to fetch all your values. Okay.

00:06:22.200
00:06:25.409
Now let me define somewhere my
python script.

00:06:25.400
00:06:31.210
Sorry my main function and let me
create ec2.

00:06:31.200
00:06:35.600
object. So simply boto3.

00:06:35.600
00:06:38.900
Resource, so guys here I am going to
work with one region
00:06:38.900
00:06:42.600
suppose. Let's say us-east1.

00:06:42.600
00:06:45.710
[no audio]

00:06:45.700
00:06:50.610
Fine now, our requirement is we need
to create two groups.

00:06:50.600
00:06:53.409
Let's say one is DB group.

00:06:53.400
00:06:59.210
And one more is suppose what I need
app Group.

00:06:59.200
00:07:02.300
Now I need to find out the host which
are there in these

00:07:02.300
00:07:05.000
two groups through logic now for that.

00:07:05.000
00:07:07.100
I'm implementing get host to function.

00:07:07.100
00:07:12.710
So for that I am passing my easy to
object and while getting

00:07:12.700
00:07:19.409
a DB group instances our Value is DB
if we observe in tax

00:07:19.400
00:07:22.900
we have value as DB or the same time
if you want to work

00:07:22.900
00:07:27.100
with let's say app then guys.

00:07:27.100
00:07:34.110
I am taking this DB and app because if
you go through your

00:07:34.100
00:07:38.600
instances see in your tags Env meant
DB so any Ron meant

00:07:38.600
00:07:41.110
DB now see that?

00:07:41.100
00:07:42.800
Let me implement that function here.

00:07:42.800
00:07:45.310
[no audio]
00:07:45.300
00:07:46.100
Where is it?

00:07:46.100
00:07:51.810
[no audio]

00:07:51.800
00:07:57.700
Get host your easy to object then your
filter value.

00:07:57.700
00:07:59.300
[no audio] Now.

00:07:59.300
00:08:01.800
Let me design my filter based on filter.

00:08:01.800
00:08:05.409
I need to get suppose if I call this line.

00:08:05.400
00:08:09.210
I'm calling this function from here by
passing value as DB.

00:08:09.200
00:08:14.010
So then other time what is your
required filter, so in filter

00:08:14.000
00:08:17.810
we have these two keys or fixed ones.

00:08:17.800
00:08:24.710
name on values and values are
always list now name means

00:08:24.700
00:08:29.500
see based on which key you are
taking Env If You observe

00:08:29.500
00:08:32.600
here key is Env then what about value
value?

00:08:32.600
00:08:36.200
You are passing if it is DB I need to
take that DB.

00:08:36.200
00:08:38.600
So whatever the value you're passing
that will be matched

00:08:38.600
00:08:40.510
to f filter value.

00:08:40.500
00:08:45.309
Then I need to take deck that f that's
it.
00:08:45.299
00:08:51.100
Now see that for each instance in your
ec2 object dot instances.

00:08:51.100
00:08:55.600
[no audio]

00:08:55.600
00:08:59.200
All sorry not all based on filter.

00:08:59.400
00:09:00.300
So what is our filter?

00:09:00.300
00:09:03.310
[no audio]

00:09:03.300
00:09:10.600
f now just simply print your each
instance dot you can take

00:09:10.600
00:09:11.600
private or public.

00:09:11.600
00:09:18.200
I'm going to take private IP address
right now.

00:09:18.200
00:09:21.600
Let me return simply known as of now
on here. Also.

00:09:21.600
00:09:24.800
I am going to write the return on first.

00:09:24.800
00:09:28.200
Let me run this in case you have any
errors you can come

00:09:28.200
00:09:28.900
to know that.

00:09:29.900
00:09:31.700
Yeah, that's a typo.

00:09:31.709
00:10:02.110
[corrective speech]

00:10:02.100
00:10:05.410
Yes, now you're getting your
instances, right?

00:10:05.400
00:10:07.000
But I need to separate them based on
group.

00:10:07.000
00:10:10.910
That's why I see what I am doing is
instead of printing.
00:10:10.900
00:10:12.400
I am returning your values.

00:10:12.400
00:10:14.610
[no audio]

00:10:14.600
00:10:17.000
So whatever the instance I am going
to collect any to append

00:10:17.000
00:10:20.500
that to let's say some empty list called
hosts.

00:10:20.500
00:10:23.010
[no audio]

00:10:23.000
00:10:27.810
And I am going to append for this
host.

00:10:27.800
00:10:34.500
Your each instance dot private IP
address now, I want to

00:10:34.500
00:10:35.610
written that.

00:10:35.600
00:10:40.210
So if you return that that is going to
assign for your DB

00:10:40.200
00:10:44.210
group while calling from this line and it
is going to assign

00:10:44.200
00:10:45.110
for rap group.

00:10:45.100
00:10:52.000
If you call from this line right now, see
that Now finally,

00:10:52.000
00:10:54.510
let me create my all groups.

00:10:54.500
00:10:57.200
So all groups equals to Simply.

00:10:57.200
00:10:59.160
[no audio]

00:10:59.150
00:11:02.500
First thing is one group is DB we need
but what is the servers

00:11:02.500
00:11:05.110
for DB DB group servers?
00:11:05.100
00:11:07.500
See if you call your function you are
getting your list of

00:11:07.500
00:11:10.900
servers with this DB that we are
assigned to this now.

00:11:10.900
00:11:14.400
I am taking DB group under thus these
are the servers in

00:11:14.400
00:11:15.900
your DB group servers.

00:11:15.900
00:11:19.010
[no audio]

00:11:19.000
00:11:23.900
Let's say one more group is our then
under that your rap

00:11:23.900
00:11:26.700
group servers first.

00:11:26.700
00:11:30.910
Let me print simply your all.

00:11:30.900
00:11:39.400
groups just observe the output once
Global name DB groups

00:11:39.400
00:11:40.200
is not defined.

00:11:40.200
00:11:42.510
[no audio]

00:11:42.500
00:11:45.100
Maybe I have taken simply group
there, but here I provided

00:11:45.100
00:11:53.410
groups. Sorry all groups equals 2 DB.

00:11:53.400
00:11:56.100
Yeah, that is simply db group not db
groups, right?

00:11:56.100
00:11:58.410
[no audio]

00:11:58.400
00:12:01.710
Yes under app you are getting one
server under DB are getting

00:12:01.700
00:12:04.310
two servers, but this is python
dictionary.
00:12:04.300
00:12:09.200
But what I need Json, so if you want to
convert a python

00:12:09.200
00:12:12.500
dictionary into Json simply, what you
have to do is let me

00:12:12.500
00:12:15.000
import the default module called.

00:12:15.000
00:12:18.910
[no audio]

00:12:18.900
00:12:24.310
Json now simply you can convert your
dictionary.

00:12:24.300
00:12:33.700
into Jason simply by using Json dot
dumps operation Sorry.

00:12:33.700
00:12:36.610
[no audio]

00:12:36.600
00:12:38.700
But output you're going to see the
same way.

00:12:38.700
00:12:41.810
[no audio]

00:12:41.800
00:12:56.510
[corrective speech]

00:12:56.500
00:12:58.300
Now, let me run this and see the
result.

00:12:58.300
00:13:02.510
We are getting up group and then DB
server screw.

00:13:02.500
00:13:02.700
Now.

00:13:02.700
00:13:06.710
What I am doing is I am running
simply ansible with your

00:13:06.700
00:13:10.200
implemented custom dynamic
inventory script in that we know

00:13:10.200
00:13:13.200
that there are two groups app and DB
let's say I want to
00:13:13.200
00:13:16.400
run with DB and I want to see the
servers which are there

00:13:16.400
00:13:20.110
in this DB Group ansible - I your
dynamic inventor stepd

00:13:20.100
00:13:23.700
the group name from that and then list
host now see the result

00:13:23.700
00:13:25.810
what you are going to get.

00:13:25.800
00:13:28.700
Now your ansible is going to work on
these two servers by

00:13:28.700
00:13:32.010
using this dynamic inventory script
with this group.

00:13:32.000
00:13:34.000
Let's say app Group.

00:13:34.000
00:13:38.610
[no audio]

00:13:38.600
00:13:39.400
See the result.

00:13:39.400
00:13:43.010
[no audio]

00:13:43.000
00:13:44.910
You are getting one server.

00:13:44.900
00:13:45.900
Now in this way.

00:13:45.900
00:13:50.200
You can implement simply your
dynamic inventory script now.

00:13:50.200
00:13:51.800
Let me check the connectivity action.

00:13:51.800
00:13:56.410
[no audio]

00:13:56.400
00:14:00.610
Yes, you guys it is taking some time to
run your python script

00:14:00.600
00:14:01.100
then after that.
00:14:01.100
00:14:04.200
It is going to exclude your ad-hoc
command not only with the

00:14:04.200
00:14:05.700
app. You can also work with DB.

00:14:05.700
00:14:12.110
[no audio]

00:14:12.100
00:14:15.110
Seeing your dynamic inventory Skippy
how only two groups

00:14:15.100
00:14:18.600
DB and app suppose if I take all then
what will happen see

00:14:18.600
00:14:19.300
the result.

00:14:19.300
00:14:22.810
[no audio]

00:14:22.800
00:14:25.100
See not only with your custom.

00:14:25.100
00:14:28.100
I mean static inventory, even though if
you work with a dynamic

00:14:28.100
00:14:31.500
inventory whenever if you mention
simply all by default all

00:14:31.500
00:14:33.900
is the group such that your hands will
is going to consider

00:14:33.900
00:14:37.600
all the servers which are there in your
static inventory

00:14:37.600
00:14:40.900
or which are going to collect your
dynamic inventory that's

00:14:40.900
00:14:44.410
is very important. All is always default
group.

00:14:44.400
00:14:47.600
Right? So guys, let me open once
again our script.

00:14:47.600
00:14:51.000
This is simply dynamic inventory State
simple dynamic inventory
00:14:51.000
00:14:54.610
script based on tags, that's it.

00:14:54.600
00:14:57.300
So now if you want to create some
different groups, yes,

00:14:57.300
00:15:00.810
you can create your different group
simply by implementing

00:15:00.800
00:15:05.910
your code in terms of your boo, two
three.

00:15:05.900
00:15:06.500
Okay guys.

00:15:06.500
00:15:07.900
Thank you for watching this video.

00:15:07.900
00:15:10.900
[no audio]
Transcript
00:00:00.000
00:00:01.800
Friends here.

00:00:01.800
00:00:05.200
We are going to discuss about how to
work with managed nodes

00:00:05.200
00:00:08.000
if managed nodes are not installed
with python.

00:00:09.300
00:00:12.400
See if you remember while installing
and configuring our

00:00:12.400
00:00:16.399
ansible. We have taken some
prerequisites for managing nodes

00:00:17.200
00:00:20.900
that is managed node should be
installed with python 2.6

00:00:20.900
00:00:21.800
or higher version.
00:00:23.200
00:00:28.000
But now our requirement is if
managed node is not installed

00:00:28.000
00:00:32.900
with your python then how we can
work such type of servers

00:00:33.000
00:00:34.200
with your ansible.

00:00:34.200
00:00:36.700
Is there any possibility to work with
your managed nodes

00:00:36.700
00:00:39.200
if manager node is not installed with
python.

00:00:39.900
00:00:40.200
Yes.

00:00:40.200
00:00:43.300
There is a possibility that is using
wrong module.

00:00:44.400
00:00:48.100
But suppose if you have a managed
server with python, then

00:00:48.100
00:00:49.700
writing playbooks is very easy.

00:00:50.800
00:00:55.600
But the manager node without python
for that if you want

00:00:55.600
00:00:57.500
write a play books, you have to write
some.

00:00:57.500
00:01:01.100
Yes, we can write it but you need to
write some complex Play

00:01:01.100
00:01:03.100
Books. Here it is.

00:01:03.100
00:01:04.800
Very easy to write your playbooks
here.

00:01:04.800
00:01:07.400
It is somewhat difficult to write your
playbooks, but finally

00:01:07.400
00:01:08.200
we can write it.
00:01:09.100
00:01:12.500
So if you have python on your
managed nodes that is Advantage

00:01:12.500
00:01:15.700
for us, but if you don't have python on
your managed nodes

00:01:16.000
00:01:18.800
somewhat disadvantaged, even
though we can work with your

00:01:18.800
00:01:22.800
managed nodes using your ansible if
an edge node is not there

00:01:22.800
00:01:24.900
with python, right?

00:01:24.900
00:01:27.900
So for that you have to use raw
module anyway before going

00:01:27.900
00:01:29.300
to work with ROM modules.

00:01:29.300
00:01:32.000
Let me tell you one more information.

00:01:32.800
00:01:35.400
See if you have a managed node.

00:01:35.600
00:01:39.200
Let's say this is manage node with
python and your how your

00:01:39.200
00:01:43.200
ansible server here now from here to
here if I want to transfer

00:01:43.200
00:01:47.700
a file then why can use copy module
and from manager node

00:01:47.700
00:01:51.000
to from your ansible if you want to
download any file then

00:01:51.000
00:01:52.700
I can use fetch module.

00:01:54.900
00:01:58.000
Right, but if you don't have python on
your managed nodes,

00:01:58.000
00:01:59.800
you can't use these modules.
00:02:00.000
00:02:02.900
So for each and every task you have
to use raw module only

00:02:03.500
00:02:07.800
if you want to perform any task with
your manager nodes,

00:02:07.800
00:02:11.900
those who are not having python then
for each and every task

00:02:11.900
00:02:13.400
you have to use ramadhir only.

00:02:14.800
00:02:15.900
Let me show you that.

00:02:17.700
00:02:21.600
Let me open my answer will controller
see first of all how

00:02:21.600
00:02:24.000
this inventory and here suppose.

00:02:24.000
00:02:26.400
This is my web server.

00:02:28.500
00:02:30.500
Let me check the Ping activity.

00:02:32.800
00:02:35.200
Now it is going to work because on
your managed nodes.

00:02:35.200
00:02:38.900
You have a python now see that now I
am going to work with

00:02:38.900
00:02:42.300
my data center servers which are not
having python actually,

00:02:42.900
00:02:45.100
but I am going to check the pin action.

00:02:45.300
00:02:47.300
See that what you are getting your
getting an error.

00:02:47.300
00:02:49.200
No python interpreter found.

00:02:49.200
00:02:50.600
First of all, this is warning for us.

00:02:51.100
00:02:54.100
And if you have the error message is
you probably need to
00:02:54.100
00:02:57.000
set The Interpreter that means there is
no python.

00:02:57.000
00:03:00.000
That's why you are not able to execute
your ping module.

00:03:00.800
00:03:02.100
You can't exclude any module.

00:03:02.100
00:03:06.100
If you don't have python on your
managed nodes, then accept

00:03:06.100
00:03:06.900
a role model.

00:03:07.500
00:03:10.100
You context good any module, but you
can exclude role model.

00:03:10.100
00:03:14.900
If you don't have any python on your
managed nodes see suppose.

00:03:15.500
00:03:20.700
I am going to run a shell module on
my manager server, which

00:03:20.700
00:03:21.700
are having python.

00:03:21.800
00:03:23.800
Let's say I want to find out of time.

00:03:27.000
00:03:31.300
Yes, but if you go with your servers,
which are not having

00:03:31.300
00:03:35.300
with your python, then this module
also not working.

00:03:39.300
00:03:40.000
It's a murder.

00:03:40.300
00:03:41.500
No interpreter.

00:03:42.100
00:03:46.600
That's why whenever if you have any
servers any manage servers

00:03:46.700
00:03:50.700
with without python, then you can
work with them using raw
00:03:50.700
00:03:52.300
module see that.

00:03:53.500
00:03:54.100
It's working.

00:03:54.600
00:03:55.100
That's it.

00:03:55.800
00:03:58.900
So for any type of tasks, you need to
use role model only.

00:03:59.300
00:04:03.200
So now tell me I need to copy a file
from my manager were

00:04:03.200
00:04:06.500
to remote servers then how can I
copy?

00:04:08.900
00:04:11.800
See if you have a python on your
managed nodes we have.

00:04:13.000
00:04:16.500
Copy module, but now we don't have
python on manage servers.

00:04:17.100
00:04:20.700
You have to use role model only now
in wrong module right

00:04:20.700
00:04:23.500
you what you have to do is simply how
to execute SCP command

00:04:23.500
00:04:24.899
of unix-like systems.

00:04:25.000
00:04:25.600
That's it.

00:04:26.500
00:04:29.100
You have to write full Syntax for sap
so that your file will

00:04:29.100
00:04:30.800
be transferred to your managed
nodes.

00:04:32.100
00:04:34.600
But instead of SCP, if you go with copy
that is very easy.

00:04:35.100
00:04:38.600
I mean copy module is very easy to
transfer your file.
00:04:38.800
00:04:41.400
But unfortunately, we don't have
python on my manage servers

00:04:41.700
00:04:44.700
so I can't use copy then I have to work
with raw and then

00:04:44.700
00:04:49.100
I need to write a Linux command to
copy your file from initial

00:04:49.100
00:04:54.400
engine to your manager nodes using
SCP argument as with sap

00:04:54.400
00:04:57.600
and it right complete Command the
same way if I want to download

00:04:57.600
00:05:01.500
file from my manager server again, I
have to use a CPU only.

00:05:02.400
00:05:05.500
But if you if you have python manage
servers I can use simply

00:05:05.500
00:05:06.100
fetch module.

00:05:06.100
00:05:06.900
It is very easy.

00:05:08.400
00:05:08.900
That's it.

00:05:09.900
00:05:10.300
Right.

00:05:11.100
00:05:13.900
So guys simply remember that if you
don't have python on

00:05:13.900
00:05:16.400
your managed nodes for each and
every task you have to take

00:05:16.400
00:05:18.400
remodel only with role model.

00:05:18.400
00:05:21.200
You can work on the you can work on
run your Now commands

00:05:21.200
00:05:22.300
as well as playbooks.
00:05:23.200
00:05:23.600
Okay.

00:05:23.800
00:05:27.500
So while writing our playbooks we will
use our raw module

00:05:27.500
00:05:30.200
and will Implement a playbooks with
wrong model effectively

00:05:30.400
00:05:33.400
if your man is servers or not there with
python.

00:05:34.600
00:05:35.000
Right.

00:05:35.400
00:05:35.800
Okay.

00:05:35.800
00:05:37.500
Thank you for watching this simple
video.
Transcript
00:00:00.000
00:00:02.000
Friends here

00:00:02.000
00:00:05.400
we are going to work with your
manager notes using password.

00:00:05.900
00:00:09.100
See we are having our hands will
engine server here suppose

00:00:09.600
00:00:12.800
and we are managing some number of
managed nodes with your

00:00:12.800
00:00:15.400
ansible. Let's say these three or
managed nodes.

00:00:16.500
00:00:19.800
And we know that ansible will
establish a connection using

00:00:19.800
00:00:23.100
SSH with your manager nodes using
this SSH connection.
00:00:23.100
00:00:25.000
It is going to work with your manager
nodes.

00:00:25.700
00:00:29.500
Now, we know that we can establish a
SSH connection with

00:00:29.500
00:00:34.600
any servers in two ways One is using
SSH keys and second

00:00:34.600
00:00:36.300
one is using SSH password.

00:00:36.800
00:00:39.900
So if you go with SSH key is there is a
password less authentication.

00:00:39.900
00:00:42.700
You don't need to provide password
while connecting with

00:00:42.700
00:00:46.100
your managed nodes using your SSH
or while learning.

00:00:46.300
00:00:48.900
And what about commands, you know
need to provide a password

00:00:48.900
00:00:51.500
if you exchange already your SSH
keys.

00:00:52.400
00:00:57.700
So if you remember in the last classes
in previous all classes,

00:00:58.300
00:01:00.000
we work with SSH keys.

00:01:02.400
00:01:02.600
Right.

00:01:02.600
00:01:05.400
That's why I know where we use
password to run your answer

00:01:05.400
00:01:08.100
a lot of commands or to connect with
your managed nodes,

00:01:09.000
00:01:13.100
but just assume that in case if you did
not exchange your
00:01:13.100
00:01:14.600
keys with your managed nodes.

00:01:15.800
00:01:19.100
And you know your manager node
username and password then

00:01:19.100
00:01:20.500
how you can connect with that.

00:01:22.100
00:01:22.500
Right.

00:01:22.500
00:01:23.900
So that is our concept here.

00:01:24.400
00:01:27.600
So before going to work with that
concept, I mean using password.

00:01:28.800
00:01:30.800
Let me open our existing.

00:01:32.200
00:01:34.100
Manager node, so this is already.

00:01:35.500
00:01:38.600
Our managed node through which we
already shared our assisted

00:01:38.600
00:01:40.400
keys from our aunts admin user.

00:01:41.500
00:01:47.600
So let me take a public IP and let me
open my Ants controller

00:01:48.600
00:01:50.600
and simple controller ansible engine.

00:01:50.900
00:01:57.400
Let me open inventory file and let me
update our node C simply.

00:01:57.400
00:02:01.300
I'm running ansible your manager
node with that.

00:02:01.300
00:02:02.400
I'm checking ping action.

00:02:03.900
00:02:07.100
The red lead is going to work with your
manager node without

00:02:07.100
00:02:08.100
asking a password.
00:02:09.300
00:02:13.199
Because we already exchanged our
keys with this manager node.

00:02:14.300
00:02:14.700
Right.

00:02:14.800
00:02:15.100
Yes.

00:02:15.100
00:02:15.800
It is working.

00:02:16.400
00:02:17.000
Now.

00:02:17.000
00:02:20.800
Let me create a new server so that we
can understand how

00:02:20.800
00:02:24.600
to work with using password with your
managed nodes.

00:02:25.400
00:02:28.000
So let me create one new server.

00:02:29.700
00:02:32.700
Just give me some time so that I will
launch new server.

00:02:32.800
00:02:33.800
So I am selecting.

00:02:34.000
00:02:36.400
My security group has do with the
scripting.

00:02:36.500
00:02:37.800
So I opened all the pores.

00:02:38.200
00:02:38.700
That's it.

00:02:39.700
00:02:42.200
And let me launch Now by selecting.

00:02:42.200
00:02:43.500
Keep are as this one.

00:02:46.500
00:02:49.700
Now our concept is how to work with
your manager nodes without

00:02:49.700
00:02:52.200
exchanging keys or using password.

00:02:53.600
00:02:54.900
So just give me some time.
00:02:55.100
00:03:01.400
So let me take this as let's say node 4
node 4 with password.

00:03:10.000
00:03:14.900
So guys if you want to work with any
managed node using your

00:03:14.900
00:03:17.700
ansible We are following some rules.

00:03:17.700
00:03:20.300
What is the Drool on your managed
node?

00:03:20.300
00:03:24.300
First of all, we are creating one and
submenus ER but it

00:03:24.300
00:03:25.500
not mandatory.

00:03:25.900
00:03:28.600
We will see that without having
answered main user on your

00:03:28.600
00:03:30.200
managed nodes how we can work.

00:03:30.200
00:03:33.600
We will see that but for time being
whenever if you want

00:03:33.600
00:03:36.400
to work with your manager nodes We
are following that on

00:03:36.400
00:03:37.300
your managed node.

00:03:37.300
00:03:42.400
First of all, we are one answered been
user Now let me connect

00:03:42.400
00:03:45.500
with this manager node newly-
launched manager node.

00:03:45.500
00:03:50.800
This is let me connect with this first.

00:03:59.500
00:04:01.500
And let me enter into route.

00:04:02.700
00:04:10.100
And I am going to create user add and
submit because as of
00:04:10.100
00:04:12.200
now, we are following that on all the
manage servers.

00:04:12.200
00:04:15.800
First of all, we are creating and
administering user and

00:04:15.800
00:04:17.500
let me provide password for this.

00:04:18.200
00:04:21.200
Let me take our old password same
password for all servers

00:04:21.200
00:04:25.500
that is answered Min or the red one,
two, three.

00:04:26.500
00:04:29.700
Answered Min or the right one, two
three, that's it.

00:04:30.600
00:04:34.800
And we are providing root privileges
for this user.

00:04:34.900
00:04:37.600
So how we can provide root tillage is
for this created user.

00:04:41.100
00:04:45.100
Simply open v a pseudo file and at the
end simply write ands

00:04:45.300
00:04:49.800
admin user and simply write this all
equals to all our no

00:04:49.800
00:04:52.800
password equals to all so what is the
use of no password

00:04:52.800
00:04:56.600
all whenever if you are running any
command with this user

00:04:57.500
00:05:00.400
with root privileges at that time, it won't
ask password.

00:05:00.700
00:05:01.700
Let me show you that.

00:05:03.000
00:05:04.500
See what I am doing is simply.
00:05:06.400
00:05:09.900
Pseudo s you answered mean and
one more thing guys.

00:05:10.700
00:05:13.400
Yeah, we'll come back to that.

00:05:16.400
00:05:20.800
See what I am saying is suppose if I
try to install httpd

00:05:20.800
00:05:24.500
what it is asking you need to be root to
perform this command.

00:05:24.500
00:05:25.900
So I am providing pseudo.

00:05:26.400
00:05:28.700
So now it is not going to ask any
password simply it will

00:05:28.700
00:05:29.900
install your package.

00:05:32.100
00:05:38.700
That is because In pseudo, I
mentioned no password equals

00:05:38.700
00:05:40.400
to no password now.

00:05:40.400
00:05:42.200
Let me remove this no password.

00:05:44.100
00:05:45.600
Be clear now.

00:05:45.600
00:05:48.300
I remove no password in be a pseudo
file for your answered

00:05:48.300
00:05:51.500
mean that means if you want to
perform any command with root

00:05:51.500
00:05:53.700
privileges or the time you have to
provide your password,

00:05:54.300
00:05:55.900
so let me enter into.

00:05:58.300
00:06:03.800
And admin now I am trying to install
suppose get.
00:06:05.300
00:06:07.400
Anyway, you need to run this with root
privileges now.

00:06:07.400
00:06:08.400
I am providing pseudo.

00:06:09.800
00:06:12.800
Previously while providing pseudo it
was not asking about

00:06:12.800
00:06:14.300
your password now it is asking.

00:06:15.400
00:06:16.800
You are in the pseudo file.

00:06:16.900
00:06:18.700
That's why you are the you are having
root privileges.

00:06:18.700
00:06:21.700
But whenever if you want to run your
commands, you have to

00:06:21.700
00:06:24.800
provide a password because I remove
no password in VI pseudo

00:06:24.800
00:06:27.400
file for your answered Min user line.

00:06:28.200
00:06:28.700
That's it.

00:06:30.000
00:06:30.600
Be clear.

00:06:31.900
00:06:36.000
Now generally in our previous videos,
right?

00:06:36.000
00:06:37.600
We followed by simply.

00:06:40.600
00:06:43.800
Providing no password for your
answered mean user whenever

00:06:43.800
00:06:48.600
if you want to perform root commands
with root privileges

00:06:49.500
00:06:50.600
now, let me save this.

00:06:53.300
00:06:53.800
Okay.
00:06:55.000
00:06:59.700
Now, let me take public IP for This
Server.

00:07:00.200
00:07:02.600
So what is the public eye be this is the
public IP.

00:07:03.100
00:07:03.300
Now.

00:07:03.300
00:07:07.400
Let me login go to my aunt's admin
user and let me remove

00:07:07.400
00:07:11.700
your All IP's, let me provide your newly
launched server

00:07:11.700
00:07:18.200
IP and suppose if I try to ansible check
the connectivity

00:07:18.200
00:07:19.000
with the server.

00:07:20.400
00:07:22.200
See what you are getting see the
result.

00:07:25.200
00:07:32.200
permission denied See, let me run this
SSH and see the result.

00:07:34.400
00:07:38.700
Permission denied the reason is first
of all, if you want

00:07:38.700
00:07:42.300
to work with your managed nodes
using password and your manager

00:07:42.300
00:07:47.300
nodes, you need to enable under your
route EDC sshd config

00:07:47.300
00:07:51.300
file. You need to enable password
authentication as yes.

00:07:51.300
00:07:54.100
Otherwise, you you even though if you
have password for your

00:07:54.100
00:07:57.900
manager server, you can't connect
with that now see that
00:07:57.900
00:08:01.200
somewhere you're having password
authentication by default

00:08:01.200
00:08:05.400
know if it is no you need to Light this
you need to modify

00:08:05.400
00:08:06.000
this as two.

00:08:06.000
00:08:07.900
Yes now I modified.

00:08:09.700
00:08:11.700
After this you need to restart.

00:08:13.100
00:08:17.300
Your sshd otherwise it won't take that
modification won't

00:08:17.300
00:08:18.100
take effect.

00:08:20.600
00:08:24.200
Service sshd restart that's it.

00:08:24.400
00:08:26.000
Now go to your controller.

00:08:26.400
00:08:27.100
See now.

00:08:27.100
00:08:31.600
If I try to run SSH now it is asking
password previously.

00:08:31.600
00:08:35.400
It was not asking simply permission
denied because password

00:08:35.400
00:08:36.799
authentication as know now.

00:08:36.799
00:08:40.000
We modified that it that into password
authentication into

00:08:40.000
00:08:43.000
yes. Now, if you know password of
your manager server, you

00:08:43.000
00:08:47.299
can work with that by providing
password see that now I could

00:08:47.299
00:08:49.200
able to login with your manager
server.
00:08:50.100
00:08:50.700
That's fine.

00:08:50.799
00:08:50.900
Now.

00:08:50.900
00:08:55.200
Let's come back to your ansible
controller now see ansible

00:08:55.500
00:08:57.800
all or will you can provide your pass?

00:08:57.800
00:08:58.100
Sorry.

00:09:00.400
00:09:03.900
What is your controller and Sybil with
this controller?

00:09:04.800
00:09:10.600
I want to check the Ping activity see
this ansible or how

00:09:10.600
00:09:13.500
command will work by default if you
have a password less

00:09:13.500
00:09:18.100
authentication, but let me try with c as
of now we did not

00:09:18.100
00:09:21.000
exchange our keys with this server,
but we know the password.

00:09:22.000
00:09:23.500
Now, let me run this and see the
result.

00:09:23.500
00:09:25.300
First of all what you are getting.

00:09:27.600
00:09:30.000
Permission denied by default.

00:09:30.000
00:09:33.000
You don't have a soul as
authentication by default.

00:09:33.000
00:09:36.200
Your ansible will try to work with your
manage servers using

00:09:36.200
00:09:37.500
password less authentication.
00:09:38.300
00:09:41.200
But whenever if you have a password
if you don't have password-based

00:09:41.200
00:09:43.900
authentication, and if you have a
password in your hand,

00:09:43.900
00:09:47.400
you need to tell it your answer or
command please use this

00:09:47.400
00:09:49.300
password by providing - Kay.

00:09:50.900
00:09:54.100
If you provide - K now your ansible will
ask password for

00:09:54.100
00:09:55.200
your managed node.

00:09:56.900
00:09:57.600
No, see that.

00:10:02.100
00:10:05.300
Now he's going to check ping activity
with your manager node

00:10:05.300
00:10:08.900
using SSH by taking whatever the
password we provided here.

00:10:09.600
00:10:10.600
Yes, it's working.

00:10:11.000
00:10:11.500
That's it.

00:10:12.400
00:10:17.000
So this is the way how we can provide
your SSH command soch

00:10:17.000
00:10:18.800
password in your an salon.com.

00:10:18.800
00:10:24.700
And remember that with - Kay if you
don't provide - K here

00:10:24.700
00:10:28.100
by default your ansible will try to work
with this manager

00:10:28.100
00:10:32.400
node using password less
authentication, but here Did not
00:10:32.400
00:10:34.100
exceed our keys with the server.

00:10:34.100
00:10:36.400
That's why it is showing permission
denied.

00:10:37.400
00:10:39.800
So if you want to work with your
password using your answer

00:10:39.800
00:10:43.300
or command you have to provide a - K
option such that your

00:10:43.300
00:10:46.500
hands will Allah command will ask
password as such password

00:10:46.700
00:10:49.100
now, we provided that we are able to
execute that.

00:10:50.200
00:10:51.700
Right now, let me run.

00:10:52.700
00:10:58.400
I want to first of all, let me remove on
my managed node.

00:11:03.300
00:11:11.200
httpd Sorry, young remove httpd.

00:11:12.800
00:11:16.600
And let me remove em remove simply
get as well.

00:11:18.400
00:11:18.900
Okay.

00:11:18.900
00:11:23.100
Now what I am doing is from my
ansible controller on your

00:11:23.300
00:11:24.500
manager node.

00:11:25.100
00:11:28.500
I am trying to install simply get now.

00:11:28.500
00:11:30.000
See that ansible.

00:11:31.300
00:11:32.500
Your manager node.

00:11:33.300
00:11:34.600
I want to install.
00:11:36.200
00:11:37.700
Get then you have to take modulus.

00:11:37.700
00:11:41.500
Am then arguments us name equals to
get and state equals

00:11:41.500
00:11:43.400
to latest or present.

00:11:44.200
00:11:46.200
Let me give present simply.

00:11:47.700
00:11:50.700
And if I run this it will try to connect
with your manager

00:11:50.700
00:11:53.100
node using password less
authentication, but we don't have

00:11:53.100
00:11:54.200
password-based authentication.

00:11:54.200
00:11:57.200
That's why before running you have to
provide - K as well.

00:11:58.800
00:11:59.100
Right.

00:11:59.300
00:12:02.700
I am trying to run this see that first of
all it is asking

00:12:03.300
00:12:06.000
your SSH password to connect with
your manager node.

00:12:06.300
00:12:12.000
But if I enter it won't exclude your task
the reason is You

00:12:12.000
00:12:14.300
are excluding your task without root
privileges.

00:12:14.400
00:12:16.900
It won't happen know whenever if you
want to execute some

00:12:16.900
00:12:17.600
um command.

00:12:17.600
00:12:20.600
You should tell to your ansible, please
you execute this
00:12:20.600
00:12:23.100
with root privileges as well.

00:12:24.600
00:12:26.500
Right, but we are nowhere we
mentioned this.

00:12:26.500
00:12:28.600
That's why he's asking you need to be
a route to perform

00:12:28.600
00:12:29.400
this command.

00:12:30.000
00:12:31.600
So how to provide route villages.

00:12:31.600
00:12:33.400
We know that - B option.

00:12:34.400
00:12:38.500
If you give - B option then on your
manager node, it is going

00:12:38.500
00:12:43.100
to execute your tasks with root
privileges for this user.

00:12:44.400
00:12:47.200
That's why we created this and certain
user on your managed

00:12:47.200
00:12:47.800
node as well.

00:12:49.200
00:12:50.600
Right now see the result.

00:12:51.700
00:12:54.700
First of all, it is asking your SSH
password.

00:12:54.700
00:12:56.900
Just provide your password.

00:12:59.000
00:13:02.900
And if you remember on our manager
node, we have taken no

00:13:02.900
00:13:03.700
password, right?

00:13:03.900
00:13:07.700
No password in your VA pseudo file
for your answered been

00:13:07.700
00:13:10.800
user. That's why it won't ask sudo
password to exclude your
00:13:10.800
00:13:14.400
task. Just wait some time so that it will
install.

00:13:14.500
00:13:14.800
Yes.

00:13:14.900
00:13:16.000
It has been installed.

00:13:17.200
00:13:20.600
Now what I am doing is on my
manager note.

00:13:22.300
00:13:26.800
I know that I have answered been
user in this sued over file.

00:13:28.000
00:13:32.000
But If You observe in the last line what
we have no password

00:13:32.400
00:13:35.500
for all won't ask it won't ask any
password to exclude you

00:13:35.500
00:13:39.000
recruit privileges commands, but I am
removing this no password

00:13:40.500
00:13:42.200
My user is having root privileges.

00:13:42.300
00:13:45.200
But whenever if you are running any
command with root privileges,

00:13:45.200
00:13:46.600
I need to provide password as well.

00:13:46.700
00:13:50.400
What is that password sudo password
same password, whatever

00:13:50.400
00:13:54.800
the password you have for user that
password only but Now

00:13:55.600
00:13:57.200
I am trying to install.

00:13:58.600
00:14:01.800
See the syntax httpd.

00:14:03.300
00:14:06.300
First of all, I am giving - key option
because I need to
00:14:06.300
00:14:10.000
provide a password - be because I
need to run this command

00:14:10.000
00:14:13.000
with root privileges right now.

00:14:13.000
00:14:16.400
See the result how it is going to
execute it is asking password.

00:14:16.400
00:14:17.600
Let me provide password.

00:14:18.800
00:14:22.400
This is your SSH password to connect
with your manager node.

00:14:22.400
00:14:24.000
You need a password that password.

00:14:24.000
00:14:24.700
We are providing.

00:14:28.300
00:14:30.200
But see that what you are getting.

00:14:33.700
00:14:36.300
Invalid or incorrect password
permission denied.

00:14:36.700
00:14:38.300
Otherwise, let me run once again.

00:14:38.400
00:14:40.900
Maybe I'm not sure whether I provide
correct password or

00:14:40.900
00:14:45.900
not. Let me try it ANS a dmin or the
right one, two, three,

00:14:46.800
00:14:47.600
just wait.

00:14:56.400
00:14:59.900
Just wait and see the result see
missing sudo password.

00:15:00.400
00:15:03.300
You provided your SSH password.

00:15:04.300
00:15:09.100
But see that anywhere manager note
whenever you if you run

00:15:09.200
00:15:11.300
any command with sudo.
00:15:17.300
00:15:19.400
Suppose I am running sudo.

00:15:21.600
00:15:23.800
Yum install httpd.

00:15:24.300
00:15:29.000
It is asking a password write sudo
password because in your

00:15:29.000
00:15:32.300
sued over file, we remove no
password option for your answered

00:15:32.300
00:15:32.900
been user.

00:15:34.000
00:15:36.800
So now how you can provide these
password in your answer

00:15:36.800
00:15:37.800
or not commands.

00:15:39.400
00:15:44.000
- Kay your SSH password - be to
become your easier as to

00:15:44.000
00:15:45.700
provide route Villages for your user.

00:15:46.300
00:15:48.000
Then what about sudo password?

00:15:48.100
00:15:49.500
We need to provide sudo password as
well.

00:15:49.500
00:15:49.800
Right?

00:15:50.000
00:15:51.900
Because it is asking sudo password.

00:15:52.700
00:15:56.900
That's why you have to take - Kay
option - Kay just to provide

00:15:56.900
00:16:00.200
your sudo password first thing to
establish a connection.

00:16:00.300
00:16:03.400
We are using - K and it is asking SSH
password.

00:16:03.400
00:16:07.500
Let me provide SSH password after
that.
00:16:07.500
00:16:12.000
It is asking sudo password because
means pseudo Now, what

00:16:12.000
00:16:13.300
is that same password?

00:16:14.500
00:16:17.200
Because our user is there in the sued
over file.

00:16:17.200
00:16:19.400
That's why our user is having
privileges, but we need to

00:16:19.400
00:16:22.500
provide a password because we
remove no password in your

00:16:22.500
00:16:26.200
VI pseudo file for your answered men
user.

00:16:26.400
00:16:26.900
That's it.

00:16:27.600
00:16:28.700
Now it is going to work.

00:16:34.300
00:16:39.400
So be clear guys with small - K and
small - capital k + -

00:16:39.400
00:16:44.400
B. - K is just to provide your SSH
password.

00:16:45.400
00:16:48.800
No package matching httpd found
install or update.

00:16:48.900
00:16:49.400
What happened?

00:16:54.200
00:16:56.100
No packages matching HTTP.

00:16:56.100
00:16:57.900
Sorry that is httpd right?

00:16:58.600
00:17:00.000
Yeah, let me run it once again.

00:17:01.400
00:17:04.200
And start Min or the red one, two,
three, this is associate
00:17:04.200
00:17:06.200
pastor to establish your SSH
connection.

00:17:06.500
00:17:09.500
So after that, we are running this
command with root privileges

00:17:10.098
00:17:11.098
now for root privileges.

00:17:11.098
00:17:12.500
We need to provide password for that.

00:17:12.500
00:17:16.400
I am taking - K now, let me enter and
now it is asking your

00:17:16.400
00:17:17.700
sudo password.

00:17:18.200
00:17:18.700
That's it.

00:17:20.300
00:17:22.800
I'll just wait so that it will install your
HTTP on your

00:17:22.800
00:17:23.700
manager node.

00:17:24.598
00:17:29.800
So here we use two options - K and -
capital K small k for

00:17:29.800
00:17:34.400
SSH password and - capital K is for
your sudo password.

00:17:34.500
00:17:38.099
That's it change true installed httpd.

00:17:38.099
00:17:38.599
That's it.

00:17:40.200
00:17:44.300
So when you when you are providing -
K you are providing.

00:17:44.900
00:17:47.599
I mean Capital - Kay you're providing
sudo password.

00:17:48.300
00:17:51.300
So if you don't want provide sudo
password then on your manager

00:17:51.300
00:17:54.100
node in your sued over file.
00:17:55.500
00:18:02.000
You need to provide here in the last
field no password:

00:18:02.000
00:18:06.500
all but if you remove no password, you
need to provide sudo

00:18:06.500
00:18:08.900
password while earning your ansible
or commands.

00:18:08.900
00:18:09.500
That's it.

00:18:12.200
00:18:12.600
Right.

00:18:12.900
00:18:16.600
So see if you run simply or ansible it
will use some help

00:18:17.100
00:18:18.300
see connection options.

00:18:19.500
00:18:22.900
- K is the shortcut for actually this - -
ask pass.

00:18:23.400
00:18:26.200
So this is just for connection SSH
connection.

00:18:26.700
00:18:30.400
Now if You observe here somewhere -
capital K is there what

00:18:30.400
00:18:32.400
is that become password?

00:18:32.700
00:18:36.900
What is the password for your user to
provide root privileges?

00:18:37.200
00:18:38.300
Anyway same password.

00:18:39.100
00:18:39.600
That's it.

00:18:42.800
00:18:43.300
Suppose guys.

00:18:43.300
00:18:49.900
Sometimes you need to yeah, we'll
see that in next video.
00:18:50.400
00:18:53.200
I mean actually how to work with
different users on your

00:18:53.200
00:18:57.000
managed nodes using your ansible as
of now by default.

00:18:57.000
00:18:59.400
We are working with ants admin user
on your managed node

00:18:59.400
00:19:00.900
as well next video.

00:19:00.900
00:19:03.600
We will see how to work with the
different users on your

00:19:03.600
00:19:06.200
manager notes while learning your
aunt's blood our commands

00:19:06.700
00:19:08.000
Okay. Okay guys.

00:19:08.000
00:19:09.200
Thank you for watching this video.
Transcript
00:00:00.000
00:00:01.700
Friends here.

00:00:01.700
00:00:05.700
We are going to discuss about how to
execute tasks with default

00:00:05.700
00:00:07.400
user and different users.

00:00:07.800
00:00:10.200
See what is this default user or
different user.

00:00:10.900
00:00:13.300
You will get cloudy just white before
that.

00:00:13.600
00:00:15.800
Let me open my ansible controller.

00:00:18.400
00:00:21.800
See we have as of now a server called
this one and suppose

00:00:21.800
00:00:24.800
if I try to connect with the server is
asking a password
00:00:26.100
00:00:28.800
right and let me take one more server
with password less.

00:00:28.800
00:00:30.200
Anyway, we have all the servers right?

00:00:30.200
00:00:33.100
So with some servers we shared our
SSG keys and with some

00:00:33.100
00:00:35.400
servers we did not share our keys.

00:00:35.900
00:00:39.000
So with node for we are working with
password, but with Node

00:00:39.000
00:00:41.600
1 suppose, we are working with
password less authentication.

00:00:42.000
00:00:45.400
So whatever it may be let me show
you that let me add.

00:00:46.600
00:00:50.700
In our inventory, this has let's say
password.

00:00:52.700
00:00:54.200
And let me create one more group.

00:00:56.500
00:00:59.400
Password unless it's not mandatory
just for our understanding.

00:00:59.400
00:01:05.200
I am creating these two groups see
that in our inventory.

00:01:05.200
00:01:06.900
We have two servers suppose.

00:01:06.900
00:01:10.500
If I try to connect with the server, it
won't ask password

00:01:10.500
00:01:12.300
because already we exchanged our
keys.

00:01:13.600
00:01:15.900
So it is directly going to connect with
your manage node.
00:01:17.500
00:01:22.000
And while connecting with your
managed node where we login

00:01:22.000
00:01:25.500
with what user will again answered
mean let's come back to

00:01:25.500
00:01:26.300
your controller.

00:01:30.600
00:01:33.200
See whenever if you are trying to work
with your managed

00:01:33.200
00:01:36.200
node suppose if I am trying to log in
with my managed node,

00:01:36.700
00:01:39.600
I can also provide the user with what
user I need to log

00:01:39.600
00:01:41.000
in with my managed server.

00:01:44.100
00:01:45.300
Let me take your IP.

00:01:47.100
00:01:51.800
SSH and sat mean with that user I
want to login with my manager

00:01:51.800
00:01:54.900
node. Yes, you can provide your
username at the rate.

00:01:55.000
00:01:55.800
You're a host name.

00:01:58.000
00:02:01.100
No, who am I answered mine user?

00:02:01.800
00:02:06.500
If You observe previously or let me
now once again log in

00:02:06.500
00:02:08.000
without providing any username.

00:02:09.300
00:02:12.600
Then observe the result you are
logging with your manager

00:02:12.600
00:02:14.700
server with what user.
00:02:16.500
00:02:20.000
And submit only whether you are
providing answered mean user

00:02:20.500
00:02:21.500
or not.

00:02:21.500
00:02:21.900
See here.

00:02:21.900
00:02:25.000
We are not providing admin username
and admin username just

00:02:25.000
00:02:28.900
we provide IP but still we are able to
login with your remote

00:02:28.900
00:02:31.300
use remote server with user as
answered mean.

00:02:31.800
00:02:36.800
The reason is on your hands in and
Sinjin ansible engine.

00:02:37.300
00:02:40.000
What is the user you are using
answered been user.

00:02:40.500
00:02:44.200
So if you how this user on your remote
node, then you know

00:02:44.200
00:02:46.100
need to mention this answered me in
it.

00:02:46.300
00:02:49.800
Really provide this IP so that you are
going to login with

00:02:49.800
00:02:51.200
this answer been user only.

00:02:52.600
00:02:58.000
but I want to log in with my manager
node with different

00:02:58.000
00:03:01.000
user then suppose you have XYZ.

00:03:01.100
00:03:03.100
Let's say SSH.

00:03:03.700
00:03:08.900
First of all, let me take once again I be
SSH I don't want
00:03:08.900
00:03:11.800
to log in with my aunt's admin user on
my remote node.

00:03:12.500
00:03:15.100
I want to log in with a different user on
my remote node.

00:03:15.100
00:03:19.000
Then you have to provide your require
username XYZ at the

00:03:19.000
00:03:20.100
rate you are.

00:03:21.700
00:03:25.500
IP but anyway, we don't have XYZ on
on your remote node.

00:03:25.900
00:03:27.900
So let's say x y z are some password.

00:03:29.900
00:03:31.200
See the result what you are getting.

00:03:32.900
00:03:35.300
First of all, we don't know that XYZ on
my remote node.

00:03:35.800
00:03:36.900
That's why you're getting that.

00:03:39.100
00:03:39.600
Right.

00:03:39.700
00:03:40.200
See now.

00:03:40.200
00:03:42.000
Let me take my second server.

00:03:42.800
00:03:46.300
Otherwise, I'm not sure whether I
created user or not.

00:03:46.300
00:03:49.600
Let me log in with your new server.

00:03:57.300
00:03:58.400
What is this server?

00:04:05.000
00:04:06.300
Okay exit from here.

00:04:06.300
00:04:09.800
Let me provide our newly created
server with that.

00:04:09.800
00:04:10.400
I'm logging.
00:04:12.300
00:04:12.800
What happened?

00:04:16.200
00:04:18.899
Where we are, sorry, yeah.

00:04:24.100
00:04:31.500
okay now see here, let me User let me
create a user called.

00:04:33.300
00:04:35.700
XYZ you can create on any server.

00:04:37.700
00:04:39.600
And I am providing password for that.

00:04:39.900
00:04:42.300
If you want to work with password
authentication, if you

00:04:42.300
00:04:44.300
want to work with possible asset
allocation, then you need

00:04:44.300
00:04:47.100
to exchange your keys, but I don't
want to work with password

00:04:47.100
00:04:51.400
less. I need to work with password
then a password for XYZ.

00:04:53.200
00:05:01.700
Sorry password x y z then x y z or the
rate 1 2 3 x y z.

00:05:01.900
00:05:04.800
Sorry x y z at the right one, two three.

00:05:06.400
00:05:11.000
Now, this is your second server This
Server.

00:05:11.600
00:05:14.900
Now, first of all, I am trying to work
with your remote node

00:05:14.900
00:05:18.900
without providing any user then it is
going to use this as

00:05:18.900
00:05:21.400
the default user on your manager
node.

00:05:21.900
00:05:24.400
Actually, we are unanswerable engine,
but if you don't provide
00:05:24.400
00:05:28.300
any username your SSD will take this
as the user on your

00:05:28.300
00:05:31.500
manager, you know, in case if it is not
there you cannot

00:05:31.500
00:05:33.000
connect with that right?

00:05:33.000
00:05:35.900
First of all, I am trying to run without
providing any username.

00:05:37.300
00:05:41.100
See what is asking and sad mean on
my manager node with this

00:05:41.100
00:05:42.600
user. What is the password?

00:05:43.700
00:05:44.900
And submit one two three.

00:05:46.000
00:05:46.200
Yes.

00:05:46.200
00:05:48.400
Now I can able to login with your
remote node.

00:05:48.500
00:05:51.600
See that where why I am where I am
under this user.

00:05:52.100
00:05:52.200
Now.

00:05:52.200
00:05:55.600
What I want to do is I don't want to
work with that user.

00:05:55.600
00:05:59.300
I want to work with some different user
than let's say instead

00:05:59.300
00:06:04.000
of this just provide your username or
the rate your SSH.

00:06:04.000
00:06:09.300
I mean your IP now XYZ provide the
password for your XYZ

00:06:09.300
00:06:13.100
user. Now see that who am I?
00:06:15.600
00:06:21.200
XYZ so before going to work with your
ansible now, you know

00:06:21.200
00:06:26.200
that what is the default user and other
user whenever if

00:06:26.200
00:06:29.100
you want to work with the default user
that is answered mean

00:06:29.300
00:06:32.100
I mean from which user you are
managing your ansible.

00:06:32.600
00:06:34.700
That is the default user on your
managed nodes.

00:06:35.300
00:06:38.600
If you want to work with the different
users, then you are

00:06:38.600
00:06:42.000
providing that username or the red
hostname the same way

00:06:42.000
00:06:44.000
how to work with ansible as well.

00:06:45.900
00:06:50.000
See suppose if I run ansible simply.

00:06:50.000
00:06:53.100
I want to exclude some command on
my managed nodes.

00:06:53.100
00:06:57.700
Let's say If you want to work with
partial as you can work,

00:06:57.700
00:07:02.200
I am working with password and
stable This Server.

00:07:03.300
00:07:05.100
I want to execute shell.

00:07:07.800
00:07:08.600
I will do one thing.

00:07:09.800
00:07:16.000
I will create some file empty file file
arguments path.

00:07:16.900
00:07:18.100
So I'm not providing any path.
00:07:18.100
00:07:18.600
Simply.

00:07:18.600
00:07:24.800
I am writing some x y z dot txt file then
State equals to

00:07:24.800
00:07:28.200
touch. So I know you're providing with
password.

00:07:28.200
00:07:29.100
I mean you're talking with Pastor.

00:07:29.100
00:07:32.100
That's why I'm using - K C be clear.

00:07:32.700
00:07:36.500
I did not provide any path by default
the path on your remote

00:07:36.500
00:07:41.400
node is the current user home first of
all observe this Answered

00:07:41.400
00:07:42.900
Min or the red one, two three.

00:07:47.000
00:07:48.400
Just wait and see the result.

00:07:51.100
00:07:54.400
It's going to create your x y z dot txt
file on your remote

00:07:54.400
00:07:58.300
server s it has been created with a see
that user and group

00:07:58.400
00:08:01.200
answered mean now where it has
been created.

00:08:01.200
00:08:03.000
Let me log in with your remote server.

00:08:09.600
00:08:11.600
And just provide a list and see the
result.

00:08:11.900
00:08:14.600
It has been created x y z dot txt file.

00:08:16.200
00:08:17.100
Now be clear.

00:08:17.100
00:08:23.000
This is the command we run but now I
don't want to log in
00:08:23.000
00:08:26.100
with my remote node by using ants
admin user.

00:08:26.200
00:08:29.800
I want to work with different user on
my remote node.

00:08:31.500
00:08:34.600
This ansible at our Command be clear.

00:08:34.799
00:08:37.900
There is very very important this
ansible at her command.

00:08:38.100
00:08:41.299
I want to run with a different user on
my remote node.

00:08:41.500
00:08:43.700
Not this answered Ben user.

00:08:44.500
00:08:46.799
Just as you know dance admin user is
not there on your remote

00:08:46.799
00:08:50.700
node. Then this won't execute
because by default will try

00:08:50.700
00:08:53.500
to connect with your ants admin user
assume that you don't

00:08:53.500
00:08:54.600
have answered Ben user.

00:08:54.900
00:08:57.400
You newly launched the some server
and in that server, you

00:08:57.400
00:09:00.000
know some user and some password
for that, but you don't

00:09:00.000
00:09:01.000
have an certain user on the tree.

00:09:01.200
00:09:04.100
Node on your manager node, then if
this answer or command

00:09:04.100
00:09:04.700
won't work.

00:09:06.200
00:09:11.100
If you know any other user on your
remote node, then with
00:09:11.100
00:09:14.500
I phone you you can mention that
XYZ.

00:09:15.500
00:09:18.300
Now you are connecting with your
manager node using this

00:09:18.300
00:09:21.800
XYZ. Not with Anne's admin user be
clear.

00:09:22.500
00:09:26.900
It's like XYZ or the rate hostname SSH
XYZ or the rate hostname

00:09:27.800
00:09:30.400
you are going to execute your tasks
on your remote node with

00:09:30.400
00:09:32.100
this user XYZ user.

00:09:32.400
00:09:33.400
Yes, we can work.

00:09:33.600
00:09:36.200
No need to have answered many
other across all the servers.

00:09:36.800
00:09:41.000
If you don't have an certain user on
your managed nodes then

00:09:41.000
00:09:43.000
what is the user you are having on
your remote node.

00:09:43.000
00:09:45.000
And what is the password for that if
you know that?

00:09:45.300
00:09:48.000
And work with your ansible without
creating and submitting

00:09:48.000
00:09:49.600
user on your manager nodes.

00:09:51.100
00:09:55.300
Now by this command you are running
with XYZ user that's

00:09:55.300
00:10:01.500
why this file will create under XYZ at
home let me Create
00:10:01.500
00:10:02.500
some different file.

00:10:03.800
00:10:07.200
New file dot txt now see the result.

00:10:07.500
00:10:10.600
Now this password not for your
answered mean user password

00:10:10.600
00:10:11.800
for this Exquisite password.

00:10:11.800
00:10:13.100
You have to provide a password.

00:10:13.400
00:10:14.500
So XYZ.

00:10:14.600
00:10:16.000
Are there it 123 password?

00:10:16.000
00:10:19.700
I have given Now see that it is going to
execute your task

00:10:19.700
00:10:20.800
with XYZ user.

00:10:20.800
00:10:23.400
You can see that result in you are
output also.

00:10:24.600
00:10:25.300
Just wait.

00:10:28.500
00:10:30.600
See, what is the group x y z.

00:10:30.700
00:10:33.800
What is the owner XYZ only one
remote node with this user

00:10:33.800
00:10:35.500
your task has been executed.

00:10:35.700
00:10:39.200
If this is the user where this file has
been created under

00:10:39.200
00:10:41.900
the home of this XYZ first.

00:10:41.900
00:10:45.900
Let me login with your default user
and see the result whether

00:10:45.900
00:10:48.800
you have this XY new file.
00:10:48.800
00:10:51.600
What is that new file new file dot txt
under your answer

00:10:51.600
00:10:52.300
admin user.

00:10:56.400
00:10:58.600
See that we do now new file here.

00:10:58.900
00:11:02.700
Just come out here and try to login
with your manage node

00:11:02.700
00:11:03.800
with XYZ user.

00:11:06.500
00:11:09.200
Our task has been executed with XYZ
user.

00:11:10.300
00:11:13.100
Let me log in with XYZ user on my
manager node.

00:11:13.700
00:11:16.000
See that new file dot txt has been
created.

00:11:16.600
00:11:20.500
So guys, this is the way how we can
work with your managed

00:11:20.500
00:11:25.000
nodes. Using different user not with
the default user.

00:11:25.800
00:11:28.200
If you don't provide this user, then you
are answerable will

00:11:28.200
00:11:31.700
try to work on your manager node by
considering an certain

00:11:31.700
00:11:33.700
user is present on the managed
nodes.

00:11:35.400
00:11:38.700
Sometimes you may not have
answered main user on your newly

00:11:38.700
00:11:40.800
launched in servers then on that.
00:11:41.200
00:11:43.600
You have some user and some
password for that then how we

00:11:43.600
00:11:45.000
can work with that servers.

00:11:45.200
00:11:46.100
This is the syntax.

00:11:48.300
00:11:51.900
Right see that if you run ansible
somewhere you are having

00:11:51.900
00:11:58.000
I funny - you sorry - you remote user
connect as this user

00:11:58.200
00:11:59.700
by default you are answered mean.

00:12:00.900
00:12:03.300
I mean if you are creating an certain
user by default, that

00:12:03.300
00:12:04.400
is the answered been user.

00:12:05.500
00:12:08.100
Other than that if you want to work in it
use this option.

00:12:09.300
00:12:15.000
And for this user in case if you want to
work with any command

00:12:15.000
00:12:18.100
with root privileges, then same syntax
- K you have to pass.

00:12:18.100
00:12:20.800
I mean - capital K you how to pass
and then you have to execute

00:12:22.300
00:12:23.000
so likewise.

00:12:23.000
00:12:24.800
We have different options here guys.

00:12:24.800
00:12:27.900
If You observe here from top to down
your ansible help you're

00:12:27.900
00:12:29.100
having different options.
00:12:30.000
00:12:35.700
So as of now, we work with only - b - K
and small iPhone

00:12:35.700
00:12:40.100
K and now we work with iPhone you
Now we have different options.

00:12:40.100
00:12:43.200
We will see all these options while
working with your playbooks.

00:12:44.200
00:12:48.500
So by this we have overall idea about
your Ansel or not commands.

00:12:50.700
00:12:54.600
right Okay, so, okay.

00:12:54.600
00:12:55.900
Thank you for watching this video.
Transcript
00:00:00.000
00:00:01.500
Friends here

00:00:01.500
00:00:05.609
we are working with ansible variables
see basically variables

00:00:05.600
00:00:08.310
are useful to store values.

00:00:08.300
00:00:10.600
So before going to work with your
ansible variables, let

00:00:10.600
00:00:14.700
me open my command line of my
ansible controller.

00:00:14.700
00:00:17.400
Anyway, this is UNIX-like systems
right suppose if I write

00:00:17.400
00:00:22.600
x equals 2/3 then you store the value
3 into a variable called
00:00:22.600
00:00:26.200
x then I can display that using a code
echo x.

00:00:26.200
00:00:28.310
[no audio]

00:00:28.300
00:00:30.700
The same way even in our ansible.

00:00:30.700
00:00:34.100
Also, we can define variables and we
can use them whenever

00:00:34.100
00:00:35.910
they need.

00:00:35.900
00:00:38.900
And before going to take a variable
name, you need to follow

00:00:38.900
00:00:42.300
some rules to select a variable name
suppose.

00:00:42.300
00:00:46.500
I can take x as a variable y as a
variable xyz as a variable

00:00:46.500
00:00:52.000
or suppose my name also a variable
and x 1 is also a variable

00:00:52.000
00:00:57.100
named x to y1 by 2 like that, but see
that ansible variable

00:00:57.100
00:01:02.410
name should be letters numbers
underscores and they should

00:01:02.400
00:01:04.108
always start with the letter.

00:01:04.099
00:01:07.200
Don't take 1 x as a variable name you
can take x 1 because

00:01:07.200
00:01:10.410
always you have to start with the
letter. That's it.

00:01:10.400
00:01:13.910
There is a simple rule to select your
variable names.

00:01:13.900
00:01:15.010
Anyway, that's fine.
00:01:15.000
00:01:16.700
Now in your ansible.

00:01:16.700
00:01:20.910
We have different types of variables
like default variables

00:01:20.900
00:01:24.100
inventory variables inventory nothing
but instead of inventory,

00:01:24.100
00:01:28.300
we have some host and groups so for
forced and for group

00:01:28.300
00:01:30.710
you have some variables.

00:01:30.700
00:01:34.400
In fact some local facts, you know
facts already we discussed

00:01:34.400
00:01:38.200
about facts using setup module and
use the custom facts and

00:01:38.200
00:01:40.810
nothing but local facts.

00:01:40.800
00:01:43.500
Right and then some registered
variables likewise you have

00:01:43.500
00:01:45.010
different types of variables.

00:01:45.000
00:01:46.700
And of course, these are the major
variables.

00:01:46.700
00:01:50.600
But anyway while working with
playbooks we will see all the

00:01:50.600
00:01:54.010
type of variables to work with your
playbooks.

00:01:54.000
00:01:57.300
Now let me go with the in this video
deep with the default

00:01:57.300
00:01:58.900
variables and inventory variables.

00:01:58.900
00:02:02.600
Any we already have seen facts and
local facts with setup
00:02:02.600
00:02:06.610
module. But if you want to go and
work with registered variables,

00:02:06.600
00:02:09.800
we how to implement playbooks so
there will discuss in detail

00:02:09.800
00:02:12.609
about remaining variables.

00:02:12.600
00:02:17.500
Now first of all ansible default
variables see ansible defines

00:02:17.500
00:02:21.500
some variables for us and these are
very helpful by default.

00:02:21.500
00:02:23.810
You have some variables with your
ansible.

00:02:23.800
00:02:28.500
Let's say some of them are suppose
inventory, hostname_inventory,

00:02:28.500
00:02:33.500
hostname_short and
groups/groups.keys.

00:02:33.500
00:02:35.609
[no audio]

00:02:35.600
00:02:39.200
See by default you're having these are
the variables without

00:02:39.200
00:02:42.900
defining you can fetch the value for
this inventory hostname

00:02:42.900
00:02:46.800
inventory hostname_short and groups
variable values before

00:02:46.800
00:02:48.109
going to work with this.

00:02:48.100
00:02:52.209
You should know a debug module
from your ansible.

00:02:52.200
00:02:56.800
See let's say we have some inventory
in this way. Now.
00:02:56.800
00:03:03.000
I am running simply ansible all - m
debug module then arguments.

00:03:03.000
00:03:06.410
You can provide two arguments vars
and message.

00:03:06.400
00:03:07.100
Let's say suppose.

00:03:07.100
00:03:12.410
I am going to provide vars simply var.

00:03:12.400
00:03:17.100
suppose, let me take first message
message equals 2 This

00:03:17.100
00:03:18.400
is a debug module.

00:03:18.400
00:03:23.310
[no audio]

00:03:23.300
00:03:26.910
Nothing is that it's like a print
statement or echo statement

00:03:26.900
00:03:31.000
for your other scripting see that this is
a debug module

00:03:31.000
00:03:33.800
and this is a debug module see how
many servers you have

00:03:33.800
00:03:36.700
in your inventory to servers on those
two servers.

00:03:36.700
00:03:38.200
It is executing your debug module.

00:03:38.200
00:03:41.200
But actually it is not executing on your
remote node is executing

00:03:41.200
00:03:45.900
only on your localhost be clear debug
module is not going

00:03:45.900
00:03:49.200
to execute on your remote node is
going to execute only on

00:03:49.200
00:03:52.209
your localhost just to display.
00:03:52.200
00:03:55.200
Some information some message or
some variable value based

00:03:55.200
00:03:57.510
on your requirement.

00:03:57.500
00:04:02.200
See basically if I run ansible all - m
and then ping it

00:04:02.200
00:04:05.010
is going to exclude with your remote
nodes.

00:04:05.000
00:04:07.500
And if you observe here further, we
need to provide a password

00:04:07.500
00:04:08.600
and this is a partial list.

00:04:08.600
00:04:11.800
That's why it is going to work for this
passwordless server.

00:04:11.800
00:04:13.010
I mean ping module.

00:04:13.000
00:04:16.909
It is not working for this server
because permission denied

00:04:16.899
00:04:19.100
but while working with the debug
module is working for two

00:04:19.100
00:04:21.899
servers. That means it is not going to
execute on your remote

00:04:21.899
00:04:25.100
nodes. It is going to execute only on
your localhost but

00:04:25.100
00:04:27.399
for each and every server it will
execute on your localhost

00:04:27.399
00:04:33.409
itself. That's why you don't need any
SSH connectivity or

00:04:33.400
00:04:41.300
password for that be clear fine now so
this is the way how
00:04:41.300
00:04:47.000
you can display some message now
what I am saying is we have

00:04:47.000
00:04:50.300
by default some variables like
inventory hostname inventory

00:04:50.300
00:04:54.100
hostname_shot first let me go with
inventory hostname see

00:04:54.100
00:04:56.700
if you want to display variable or
message always you have

00:04:56.700
00:04:59.900
to use debug module either in your
command line or in your

00:04:59.900
00:05:04.610
playbooks so be clear with the debug
debug is useful to execute

00:05:04.600
00:05:08.700
to display message or to display
variable value and this

00:05:08.700
00:05:12.700
module is not going to on your remote
servers on manage servers

00:05:12.700
00:05:16.710
is going to execute only on your
ansible engine.

00:05:16.700
00:05:20.100
Now suppose I want to display a
variable value.

00:05:20.100
00:05:23.610
Then I can take y equals 2.

00:05:23.600
00:05:28.000
inventory hostname see the result.

00:05:28.000
00:05:30.210
[no audio]

00:05:30.200
00:05:31.000
For this server.

00:05:31.000
00:05:33.500
What is the inventory host name by
default this one for this
00:05:33.500
00:05:37.010
server is the inventory named by
default this one.

00:05:37.000
00:05:39.400
That's what it is fetching automatically
you are able to

00:05:39.400
00:05:42.000
identify inventory hostname if you
remember while working

00:05:42.000
00:05:45.710
with your fetch module I use
somewhere this inventory hostname

00:05:45.700
00:05:49.100
that is a default variable. Variable
name know where we are

00:05:49.100
00:05:50.000
defining directly.

00:05:50.000
00:05:54.110
We are getting that variable value.
Right.

00:05:54.100
00:05:56.700
So if you go with where you need to
display in that way suppose

00:05:56.700
00:05:59.600
if I go with the message, then you
have to write curly braces

00:05:59.600
00:06:02.510
for your variable to display variable
value.

00:06:02.500
00:06:06.600
We have two arguments for your
debug one is message and one

00:06:06.600
00:06:10.010
is var in where directly you can write
your variables.

00:06:10.000
00:06:12.400
But in message you have to write your
variable inside of

00:06:12.400
00:06:16.010
curly braces two curly braces.

00:06:16.000
00:06:21.409
Now the next default variable is
suppose.
00:06:21.400
00:06:26.000
Inventory hostname_short see
sometimes you are going to work

00:06:26.000
00:06:28.210
with FQDN names.

00:06:28.200
00:06:32.100
I mean, you're going to provide FQDN
name in your inventory

00:06:32.100
00:06:37.100
file. Let's say I am taking new
inventory suppose.

00:06:37.100
00:06:38.810
I am going to provide some server
name.

00:06:38.800
00:06:41.300
Actually, I don't have that but I am
providing server one

00:06:41.300
00:06:52.600
.cloud. some vars.com. Now actually
your server name

00:06:52.600
00:06:54.000
is with FQDN.

00:06:54.000
00:06:57.100
This is but actual server name is only
the server one now

00:06:57.100
00:06:58.900
see that if I run ansible.

00:06:58.900
00:07:03.110
[no audio]

00:07:03.100
00:07:07.010
So I want to provide my own inventory
-m in custom inventory

00:07:07.000
00:07:10.500
then with this on all servers.

00:07:10.500
00:07:14.800
I want to exclude this see you're
getting full FQDN name.

00:07:14.800
00:07:18.100
If you go with inventory host name, but
instead of that if

00:07:18.100
00:07:22.810
I go with the inventory hostname short
now see the result.
00:07:22.800
00:07:24.710
We are getting only server one.

00:07:24.700
00:07:27.900
Nothing is there it is doing an
operation called split based

00:07:27.900
00:07:32.510
on dot if you know python you can
easily understand this.

00:07:32.500
00:07:38.909
Split operation based on dot then it is
taking index 0 value. That's it.

00:07:38.900
00:07:41.200
And see that somewhere already.

00:07:41.200
00:07:44.900
We have seen that suppose in our
inventory default inventory.

00:07:44.900
00:07:47.800
How many groups are there two
groups and you know that by

00:07:47.800
00:07:50.510
default all is also a group.

00:07:50.500
00:07:54.100
Now based on group if you want to list
your host suppose.

00:07:54.100
00:07:55.800
I want to work with passwordless.

00:07:55.800
00:07:57.810
[no audio]

00:07:57.800
00:08:02.200
Group, then what I am doing is simply
I am doing - - list

00:08:02.200
00:08:10.700
host. Play but now my requirement is I
want to see the groups

00:08:10.700
00:08:12.710
which are there in your inventory.

00:08:12.700
00:08:13.500
Then in that case.

00:08:13.500
00:08:17.710
This is the syntax be clear here.

00:08:17.700
00:08:20.500
Don't use any server from your
inventory instead of that
00:08:20.500
00:08:23.710
just use localhost then.

00:08:23.700
00:08:26.700
Module is debug then argument.

00:08:26.700
00:08:29.810
I suppose var or message.

00:08:29.800
00:08:33.100
But here you have to write groups now
see the result very

00:08:33.100
00:08:37.409
useful. What happened?

00:08:37.400
00:08:41.110
[corrective speech]

00:08:41.100
00:08:44.700
See that groups how many groups are
there all by default

00:08:44.700
00:08:46.710
then password and passwordless.

00:08:46.700
00:08:50.900
Anyway ungroup you are having that
so these are the groups

00:08:50.900
00:08:52.610
in your inventory.

00:08:52.600
00:08:57.310
So by default you can get your groups
using groups where

00:08:57.300
00:09:00.510
so groups is the variable and this is
the default variable.

00:09:00.500
00:09:03.710
I don't want displaying groups with
server names.

00:09:03.700
00:09:06.710
I want display only group names then.

00:09:06.700
00:09:08.900
You can display simply keys.

00:09:08.900
00:09:11.110
[no audio]

00:09:11.100
00:09:16.700
See if you know python groups is the
one key and this is

00:09:16.700
00:09:19.000
the value for that in that group.
00:09:19.000
00:09:21.700
This is a dictionary and in the
dictionary. If you observe

00:09:21.700
00:09:22.500
this is one key.

00:09:22.500
00:09:25.700
This is one key and this is one key
and this is one key now

00:09:25.700
00:09:28.600
if I do groups.keys now see the result
what you are getting.

00:09:28.600
00:09:31.210
[no audio]

00:09:31.200
00:09:31.800
What happened?

00:09:31.800
00:09:44.810
[corrective speech]

00:09:44.800
00:09:49.310
See the result you're getting all your
group names only.

00:09:49.300
00:09:51.900
So if you run only groups you are
going to get all groups

00:09:51.900
00:09:55.710
from your inventory.keys.

00:09:55.700
00:09:58.700
Groups, sorry, if you run only groups
you are going to get

00:09:58.700
00:10:03.500
your groups with servers, but dot keys
you're going to get

00:10:03.500
00:10:06.710
groups names only. That's it.

00:10:06.700
00:10:09.100
So these are some of the other default
variables which are

00:10:09.100
00:10:13.500
there with your ansible now next thing
is host and group

00:10:13.500
00:10:19.610
variables. See be clear.
00:10:19.600
00:10:24.200
This is our inventory, right see as of
now suppose if I try

00:10:24.200
00:10:29.200
to run ansible all - m ping what you
are getting for one

00:10:29.200
00:10:32.100
server, you're getting permission
denied because for that

00:10:32.100
00:10:35.100
server we are not using partial as
authentication.

00:10:35.100
00:10:36.800
We have to provide a password for
that.

00:10:36.800
00:10:38.810
[no audio]

00:10:38.800
00:10:41.100
Right, but for second server, we have
already passed or less

00:10:41.100
00:10:43.400
of the negation. That is it's working.
Now.

00:10:43.400
00:10:45.800
What I want to do is if you have a
passwordless authentication

00:10:45.800
00:10:47.210
then it's okay.

00:10:47.200
00:10:49.200
If you don't have password as
authentication, actually, I

00:10:49.200
00:10:53.700
need to provide with -k with - small k
need to provide

00:10:53.700
00:10:56.000
a password instead of that.

00:10:56.000
00:11:02.610
I can write here see that ansible SSH
pass.

00:11:02.600
00:11:05.400
So simply ansadmin@123.

00:11:05.400
00:11:07.410
[no audio]
00:11:07.400
00:11:10.300
Now if I run that actually you need to
provide a password

00:11:10.300
00:11:13.300
for first server, but for this survey need
to provide a password

00:11:13.300
00:11:16.100
because we have possible lace-up
indication now instead of

00:11:16.100
00:11:19.800
providing your password on command
line based on host.

00:11:19.800
00:11:22.810
You can mention your required
password for that.

00:11:22.800
00:11:26.910
I already mention my password inside
of your inventory.

00:11:26.900
00:11:32.110
Post twice right now see the result
what you are going to get. Yes.

00:11:32.100
00:11:34.810
Now it is working with your servers.

00:11:34.800
00:11:36.600
It is getting responses pong.

00:11:36.600
00:11:41.810
That means host level y is you can
mention your required

00:11:41.800
00:11:47.300
variables to work with your ansible that
is called host variable.

00:11:47.300
00:11:49.310
[no audio]

00:11:49.300
00:11:52.510
See, I want to work with some different
user for this server.

00:11:52.500
00:11:57.700
Then I can also write see that ansible
SSH user as well and

00:11:57.700
00:12:05.900
ansible SSH user equals to xyz I want
to work then for that
00:12:05.900
00:12:09.910
password is xyz123 if you remember
from our previous videos

00:12:09.900
00:12:14.000
I created this xy that user on the
server and provided password

00:12:14.000
00:12:15.700
for that now see that.

00:12:15.700
00:12:17.360
[no audio]

00:12:17.350
00:12:20.600
Before going to that if I ping you
cannot understand from

00:12:20.600
00:12:22.310
which user is working.

00:12:22.300
00:12:25.200
But if you go with some module, then
you can understand that.

00:12:25.200
00:12:28.900
I will show you that first observe the
result.

00:12:28.900
00:12:29.900
Yes, it's working.

00:12:29.900
00:12:32.710
[no audio]

00:12:32.700
00:12:38.310
Now see that what I am doing is I'm
going to create some.

00:12:38.300
00:12:42.910
File on my manage notes so that you
can see from which user is working.

00:12:42.900
00:12:44.500
Let's say path equals 2.

00:12:44.500
00:12:47.710
[no audio]

00:12:47.700
00:12:51.600
Where's .txt then state equals to
touch.

00:12:51.600
00:12:55.010
[no audio]

00:12:55.000
00:12:56.000
Now see the result.
00:12:56.000
00:12:59.110
[no audio]

00:12:59.100
00:12:59.700
One server.

00:12:59.700
00:13:04.310
We provided remote server username
and password.

00:13:04.300
00:13:06.900
So it is going to execute with that user
only see that very

00:13:06.900
00:13:07.800
first server.

00:13:07.800
00:13:10.010
It is executing with this user.

00:13:10.000
00:13:13.300
That's why on your remote node while
creating your file it

00:13:13.300
00:13:17.400
is giving group as xyz and 1 or xyz
actually this task

00:13:17.400
00:13:21.100
is excluding with xyz user why it is
executing with xyz user

00:13:21.100
00:13:25.910
because inside of our inventory host
wise I mentioned

00:13:25.900
00:13:28.900
SS user and password now it is
executing the task on this

00:13:28.900
00:13:31.310
Server by considering this user.

00:13:31.300
00:13:34.100
But for this server, we did not mention
then what is the

00:13:34.100
00:13:38.510
default user and admin user is going
to take that's it.

00:13:38.500
00:13:42.810
No, this is the way how you can
mention host wise variables

00:13:42.800
00:13:46.010
now. Let me write group wise.
00:13:46.000
00:13:49.700
And compared to group wise variables
host wise variables are

00:13:49.700
00:13:51.410
the highest priority.

00:13:51.400
00:13:53.600
Anyway, we have separate session for
that will discuss in

00:13:53.600
00:14:00.500
detail, but just remember that
compared to group wise hose

00:14:00.500
00:14:03.200
twice variables are having highest
priority now see that

00:14:03.200
00:14:09.000
what I am doing is I can create
variables for group wise suppose.

00:14:09.000
00:14:13.810
I want to create a variable for
passwordless group.

00:14:13.800
00:14:17.200
Where's so password less than: vars.

00:14:17.200
00:14:20.000
Now, whatever the variables you are
going to use here and

00:14:20.000
00:14:22.000
simple SSH user.

00:14:22.000
00:14:27.110
I am taking ansadmin then ansible
SSH pass.

00:14:27.100
00:14:29.800
I am taking ansadmin123 the meaning
for

00:14:29.800
00:14:33.810
this is the servers which are there
under this group.

00:14:33.800
00:14:35.600
They're going to use remote server.

00:14:35.600
00:14:40.210
Remote user has ansadmin and
further. This is the password.
00:14:40.200
00:14:47.100
Right, then. I want to define even for
your password group as well for

00:14:47.100
00:14:47.800
password group.

00:14:47.800
00:14:49.100
I am defining a vars.

00:14:49.100
00:14:51.210
[no audio]

00:14:51.200
00:14:55.910
So now what I am doing is ansible
SSH user.

00:14:55.900
00:15:01.010
I want to take ansadmin then ansible
SSH.

00:15:01.000
00:15:06.000
pass equals to ansadmin123. Right.

00:15:06.000
00:15:09.100
First of all, what I am doing is host
wise we have some variables

00:15:09.100
00:15:10.400
in your password group, right?

00:15:10.400
00:15:11.500
Let me remove them first.

00:15:11.500
00:15:17.810
[no audio]

00:15:17.800
00:15:20.210
Now what I am doing is simply I'm
running ansible.

00:15:20.200
00:15:24.300
Let me run this module only but now I
am creating some other

00:15:24.300
00:15:26.600
file so that you can see the clarity.

00:15:26.600
00:15:28.810
[no audio]

00:15:28.800
00:15:33.400
On all servers it is going to use user
as ansadmin and

00:15:33.400
00:15:37.500
password as and certainly our that
one two three because
00:15:37.500
00:15:40.900
for those two groups, we provided
username as ansadmin

00:15:40.900
00:15:43.700
and password as ansadmin@123.
Now.

00:15:43.700
00:15:46.300
Observe that these executing with
ansadmin on your remote

00:15:46.300
00:15:52.300
node. Now, let me open your inventory
file once but if you

00:15:52.300
00:15:55.610
observe here for these two groups,
you are using same variables.

00:15:55.600
00:15:58.310
So in that case, you do need to write
in these two separate

00:15:58.300
00:16:03.210
group vars directly can write at the
end simply for all

00:16:03.200
00:16:04.000
for all groups.

00:16:04.000
00:16:05.300
I am defining vars.

00:16:05.300
00:16:07.710
[no audio]

00:16:07.700
00:16:10.900
Then simply you can copy and paste
these two lines.

00:16:10.984
00:16:23.910
[corrective speech]

00:16:23.900
00:16:25.000
I am defining vars.

00:16:25.000
00:16:27.510
[no audio]

00:16:27.500
00:16:31.100
So ansible SSH user whatever the
user you want to exclude

00:16:31.100
00:16:33.500
on your remote nodes that user if you
have multiple users
00:16:33.500
00:16:36.300
you can provide that username and
then further user.

00:16:36.300
00:16:38.700
What is the password instead of
providing your password and

00:16:38.700
00:16:41.900
username on your command line on
your ad-hoc commands.

00:16:41.900
00:16:44.600
You can also mention your username
and password in your host

00:16:44.600
00:16:45.600
inventory itself.

00:16:45.600
00:16:48.010
[no audio]

00:16:48.000
00:16:50.510
This is one of the advantage.

00:16:50.500
00:16:53.400
So no need to provide each and every
time your password and

00:16:53.400
00:16:56.210
username to work with your manage
nodes.

00:16:56.200
00:16:59.000
So instead of that you can mention
your information in your

00:16:59.000
00:17:04.010
inventory file under groups are based
on host device as well.

00:17:04.000
00:17:05.098
Now, let me remove this.

00:17:05.098
00:17:09.410
[no audio]

00:17:09.400
00:17:12.910
And this also I am going to remove
even though if you keep

00:17:12.900
00:17:17.598
compared to this all this is the highest
priority compared

00:17:17.598
00:17:20.200
to this if you have any variables here
host why is there
00:17:20.200
00:17:22.710
is having highest priority.

00:17:22.700
00:17:25.700
So this is just overall idea guys while
working with your playbooks

00:17:25.700
00:17:28.500
you will get good idea how to use this
vars for different

00:17:28.500
00:17:30.310
groups and host wise.

00:17:30.300
00:17:44.200
Okay, just to try to observe this as of
now all -m ping. Just wait and see the result.

00:17:44.200
00:17:48.710
[no audio]

00:17:48.700
00:17:57.900
working right now see that actually if I
go with xyz I need

00:17:57.900
00:18:01.600
to remember only for password
authentication server.

00:18:01.600
00:18:03.900
We have xyz user for further.

00:18:03.900
00:18:09.200
I'm not sure whether you have or not
but let me so let me

00:18:09.200
00:18:10.000
remove this.

00:18:10.000
00:18:13.810
[no audio]

00:18:13.800
00:18:15.500
Now, let me run that and see the
result.

00:18:15.500
00:18:24.810
[no audio]

00:18:24.800
00:18:26.700
See for this 167 server.

00:18:26.700
00:18:29.400
It's not working with xyz user because
actually you don't

00:18:29.400
00:18:31.910
have expired user on this server.
00:18:31.900
00:18:33.700
If you how I want to use that.

00:18:33.700
00:18:38.810
If you don't have then host wise I will
mention my ansible

00:18:38.800
00:18:39.700
SSH user.

00:18:39.700
00:18:45.610
[no audio]

00:18:45.600
00:18:50.410
Equals 2 then ansadmin@123.

00:18:50.400
00:18:54.710
See I mentioned for all servers this sh
user and password.

00:18:54.700
00:18:58.100
But if at the same time if I mention
host wise as well

00:18:58.100
00:19:01.500
then compared to group variables host
wise variables are

00:19:01.500
00:19:05.400
having highest priority. Now whenever
if I run any ansible

00:19:05.400
00:19:09.800
ad-hoc command now, your ansible
will take this as the your

00:19:09.800
00:19:13.100
remote user and for that password
this. Een though if you

00:19:13.100
00:19:16.100
mention for all it won't take this. But for
second server

00:19:16.100
00:19:18.400
will take from here because here we
don't have right that's

00:19:18.400
00:19:22.100
why it will take this. So compared to
group variables host

00:19:22.100
00:19:29.110
variables are having highest priority
now see the result.
00:19:29.100
00:19:33.000
Now it's working for two servers but for
first server it

00:19:33.000
00:19:35.300
is taking suppose answered mean for
second server is taking

00:19:35.300
00:19:39.900
xyz if you don't have host level
variables you will fetch

00:19:39.900
00:19:43.800
from groups. But if you have host level
groups sorry if you

00:19:43.800
00:19:46.400
have host level variables then we'll
take first level variables

00:19:46.400
00:19:49.900
only even though if you have group
level variables. That's

00:19:49.900
00:19:54.600
it. So guys this is a simple way to
understand your default

00:19:54.600
00:19:57.510
variables and host group variables.

00:19:57.500
00:20:02.400
So we have some other variables as
well like facts or local

00:20:02.400
00:20:03.500
facts already.

00:20:03.500
00:20:08.800
We work with facts, right if you
remember ansible all - m

00:20:08.800
00:20:13.600
setup module it is going to fetch some
variables some information

00:20:13.600
00:20:15.210
about your manage nodes.

00:20:15.200
00:20:18.800
Those are nothing but facts, they are
also a variables and

00:20:18.800
00:20:22.300
local facts are nothing but we can
define our own variables
00:20:22.300
00:20:25.710
our own facts on manage nodes with
some procedure.

00:20:25.700
00:20:29.600
If you remember root it is easy and
simple facts.d inside

00:20:29.600
00:20:32.610
that we are defining a file.facts.

00:20:32.600
00:20:34.700
So from that, we are fetching some
variable values.

00:20:34.700
00:20:38.610
They are called local variables. That's
it.

00:20:38.600
00:20:41.010
Then the next part is.

00:20:41.000
00:20:42.410
Registered variables. Right.

00:20:42.400
00:20:46.210
So those will work with while working
playbooks.

00:20:46.200
00:20:47.510
Okay.

00:20:47.500
00:20:49.810
There is this is just to give some idea.

00:20:49.800
00:20:54.010
Don't worry about this in details of
your variables.

00:20:54.000
00:20:56.410
Just try to observe as of now.

00:20:56.400
00:20:57.210
Okay?

00:20:57.200
00:20:57.600
Okay guys.

00:20:57.600
00:20:58.600
Thank you for watching this.
Transcript
00:00:00.000
00:00:01.300
Friends here

00:00:01.300
00:00:04.300
we are discussing about Ansible
Playbooks.

00:00:04.300
00:00:07.400
See we know that we are having two
ways to execute a task

00:00:07.400
00:00:09.200
on managed nodes.

00:00:09.200
00:00:13.800
So what are the two ways? One is
using Ad-hoc commands and the

00:00:13.800
00:00:19.200
other is using playbooks. To execute
our task on your Manager Nodes,

00:00:19.200
00:00:24.800
we have Ad-hoc commands. Then
why we need to go with playbooks?
00:00:24.800
00:00:28.500
Let me explain this with an example.
[no audio]

00:00:28.500
00:00:34.000
See suppose I have a number of
servers. [no audio]

00:00:34.000
00:00:42.000
Let me open my inventory. Suppose
that I have 3 servers.

00:00:42.000
00:00:47.800
Now I have a requirement that I need
to install in all the servers, some packages.

00:00:47.800
00:00:55.300
Let's say I want to install httpd, nginx,
and wget and vim package.

00:00:55.300
00:00:56.800
For now, we don't know playbooks.

00:00:57.000
00:00:58.600
Actually, we know

00:00:58.800
00:01:02.700
Now if I want to install httpd, what is
the order command

00:01:02.700
00:01:05.400
and it's simple, because we are going
to work with all servers.

00:01:05.400
00:01:08.400
That's why I given all group name.
ansible all -m yum

00:01:08.400
00:01:16.500
you are required module then
"name=httpd state=present"

00:01:16.500
00:01:17.800
Now, this is the other command

00:01:17.800
00:01:20.700
we are running to install httpd, but at
the same time, I

00:01:20.700
00:01:25.200
need to install my nginx as well, then
you have to run once again.

00:01:25.200
00:01:28.700
Different at Command in this way
"name=nginx state=present"
00:01:28.700
00:01:31.900
Command "name=wget
state=present"

00:01:31.900
00:01:40.100
one more "name=vim state=present"
all 4 packages.

00:01:40.100
00:01:41.800
We are running for 4 commands.

00:01:42.300
00:01:44.600
So first we have to run faster
command and then we have to

00:01:44.600
00:01:46.000
wait after completion of that.

00:01:46.000
00:01:48.800
Then we have to run second after
completion of that then

00:01:48.800
00:01:51.900
again, we have to run third one then
after that we have to

00:01:51.900
00:01:53.500
run fourth one.

00:01:53.500
00:01:56.300
So we need 4 steps to execute these
tasks.

00:01:56.300
00:02:01.500
I mean to install your httpd, nginx and
Wget, vim packages.

00:02:01.500
00:02:05.000
Right, but using your Ad-hoc
commands, you cannot install

00:02:05.000
00:02:07.300
all the packages at a time.

00:02:07.300
00:02:11.199
You don't have any possibility to install
your

00:02:11.800
00:02:13.900
packages at a time with Ad-hoc
Commands.

00:02:13.900
00:02:17.500
That means Ad-hoc commands are
not helpful when dealing with
00:02:17.500
00:02:20.700
multiple tasks. If you want to work with
one task.

00:02:20.700
00:02:26.200
Yes, we can go with Ad-hoc
Command, but if you want to execute

00:02:26.200
00:02:29.600
multiple tasks, then Ad-hoc
commands are not suitable,

00:02:29.600
00:02:36.500
then Ansible Playbook is the solution
for such scenario.

00:02:36.500
00:02:40.500
Then how you can do that? Just
assume that as of now.

00:02:40.500
00:02:42.500
These are the 4 Ad-hoc commands.

00:02:42.500
00:02:48.000
What I will do is, I will write in one file
and I will save

00:02:48.000
00:02:49.100
it as a suppose.

00:02:49.100
00:02:52.400
[no audio]

00:02:52.400
00:02:53.300
Some demo.yml

00:02:53.300
00:02:58.800
Now instead of running 4 tasks
separately to install vim,

00:02:58.800
00:03:02.300
wget, nginx, httpd

00:03:02.300
00:03:06.000
What I did is I placed all this in one
file. Now

00:03:06.000
00:03:09.300
I will run this file in one step.
Previously to install your

00:03:09.300
00:03:13.400
packages, we needed to run 4 steps.

00:03:13.400
00:03:16.400
Because for each outcome and you
ought to run once. Four steps,
00:03:16.400
00:03:20.100
we followed, but now I will run only in
one step this file

00:03:20.100
00:03:24.400
demo.yml file. That file will go under
xcode

00:03:24.400
00:03:29.400
commands one by one. We then do
three steps, right?

00:03:29.400
00:03:32.400
Anyway, we have to write file that is
one step.

00:03:32.400
00:03:35.900
Then we reduce the were steps to
execute your tasks on your

00:03:35.900
00:03:39.500
managed nodes to install all these
packages.

00:03:39.500
00:03:46.600
That means Playbook is helpful to
execute multiple tasks

00:03:46.600
00:03:53.200
and eliminated the limitation of Ad-hoc
Commands. By using Ad-hoc

00:03:53.200
00:03:55.800
commands, you can execute only one
task but instead of that

00:03:55.800
00:04:01.000
if you go Playbook, you can execute
multiple tasks. That's it.

00:04:01.000
00:04:04.700
And basically this Playbook is a YAML
file and it consists

00:04:04.700
00:04:07.900
of tasks or number of tasks suppose.

00:04:07.900
00:04:09.600
I want to install only httpd.

00:04:09.600
00:04:11.500
Yes, we can write only one task in your
playbook.

00:04:11.500
00:04:13.300
[no audio]
00:04:13.300
00:04:16.000
Suppose if I want to install some
number of packages you

00:04:16.000
00:04:17.800
can get multiple tasks also, no
problem.

00:04:17.800
00:04:19.600
[no audio]

00:04:19.600
00:04:20.600
Along with your tasks,

00:04:20.600
00:04:23.700
you can also use some different
concept like variables, files

00:04:23.700
00:04:25.600
templates, some other concepts as
well.

00:04:26.500
00:04:29.000
Anyway, we'll go with the all these
Concepts step by step

00:04:29.000
00:04:31.100
as of now. We don't worry.

00:04:31.100
00:04:34.200
If you go with all these things you can
add some effect too.

00:04:34.200
00:04:36.500
We can work with your managed
nodes in an effective way.

00:04:36.500
00:04:38.400
[no audio]

00:04:38.400
00:04:43.200
Right and writing your Playbook or
YAML file is very easy.

00:04:43.200
00:04:45.800
You can easily understand how to
write a YAML file or your

00:04:45.800
00:04:52.000
playbook. Finally Playbooks are the
configuration, deployment

00:04:52.000
00:04:56.000
and orchestration language of Ansible
and it is expressed

00:04:56.000
00:04:57.800
in YAML format.
00:04:57.800
00:05:00.300
We know that using Playbook we can
configure our servers

00:05:00.300
00:05:03.400
we can deploy this on your servers
and we can orchestrate

00:05:03.400
00:05:06.900
the servers. So all those things we can
achieve with playbooks

00:05:06.900
00:05:07.800
very effectively.

00:05:07.800
00:05:10.700
[no audio]

00:05:10.700
00:05:14.500
Right , So to do any one of these
tasks either configuration, management

00:05:14.500
00:05:16.300
or deployment or orchestration?

00:05:16.300
00:05:18.700
We can write a Playbook.

00:05:18.700
00:05:23.800
But how to write, we will discuss and
we will learn step by step.

00:05:23.800
00:05:27.200
Now, before going to work with your
playbooks.

00:05:27.200
00:05:29.300
First of all, you have to know what is
the structure of a

00:05:29.300
00:05:35.600
Playbook. Basically your playbook
having some Concepts.

00:05:35.600
00:05:39.900
They are like Task, Play and
Playbook.

00:05:39.900
00:05:44.900
First let me explain with a diagram.
Assume that this is 1 YAML

00:05:44.900
00:05:46.500
file or even Playbook.

00:05:46.500
00:05:48.500
[no audio]
00:05:48.800
00:05:51.800
It consists of number of place.

00:05:51.800
00:05:55.100
You may have any number of plays in
your playbook. Suppose

00:05:55.100
00:05:59.000
play 1, just assume that I am writing
hyphens to be clear.

00:05:59.000
00:06:04.100
That is our practice as well P2, Play
and your player 3

00:06:04.100
00:06:08.500
likewise, you can add any number of
place in a Playbook.

00:06:08.500
00:06:09.500
Now what is a play? Play is the
combination of tasks less targets.

00:06:09.500
00:06:11.500
[no audio]

00:06:17.700
00:06:23.000
Tasks plus targets, see how some
tasks on which servers unit

00:06:23.000
00:06:26.200
executes that is your target your
manage servers or targets,

00:06:26.200
00:06:30.600
right? So tasks with Target is called a
play.

00:06:30.600
00:06:33.400
[no audio]

00:06:33.400
00:06:37.800
Now why do we need to write number
of place in a Playbook?

00:06:37.800
00:06:43.000
Sometimes just assume that in our
inventory.

00:06:43.000
00:06:46.400
We have DB servers as well as web
servers. Suppose.

00:06:46.400
00:06:51.300
I want to install httpd on the servers.
Now for this target,
00:06:51.300
00:06:54.100
task is different, and on these servers,
I want to install MySQL server.

00:06:54.100
00:06:56.900
[no audio]

00:06:56.900
00:07:00.400
Now the task is different for this group
and task is different

00:07:00.400
00:07:01.500
for this group.

00:07:01.500
00:07:05.100
That's why what we will do is, this task
will exclude on this

00:07:05.100
00:07:09.400
group. That's why I am going to write
one play for this and

00:07:09.400
00:07:14.300
for this servers, I will write to install
MySQL task and

00:07:14.300
00:07:16.400
this is one other play.

00:07:16.400
00:07:19.800
In case if we have same task for all
servers, you can write

00:07:19.800
00:07:21.400
only one play in your playbook.

00:07:21.400
00:07:23.700
[no audio]

00:07:23.700
00:07:29.100
But sometimes you may need to
perform different tasks on different targets.

00:07:29.100
00:07:32.000
[no audio]

00:07:32.000
00:07:34.700
So for different tasks for different
targets, you need to

00:07:34.700
00:07:37.100
write different place in your playbook.

00:07:37.100
00:07:39.050
[no audio]

00:07:39.050
00:07:44.300
Right simply guys task is anything
installing like HTTPD server,
00:07:44.300
00:07:47.600
or installing Java or installing Wget.

00:07:47.600
00:07:51.600
Or installing nginx server. Whatever
maybe a task.

00:07:51.600
00:07:54.300
Now play is nothing, but along with
your task.

00:07:54.300
00:07:56.800
If you mention your Target on which
Target you are going

00:07:56.800
00:07:57.800
to perform your tasks, that is a play.

00:07:57.800
00:08:00.500
[no audio]

00:08:00.500
00:08:03.700
Right now Playbook is the collection of
plays.

00:08:03.700
00:08:06.900
So when you write number of plays in
your playbook, be

00:08:06.900
00:08:10.200
clear when you are going to write
number of place in your

00:08:10.200
00:08:14.500
playbook. We will write number of
plays in your playbook

00:08:14.500
00:08:18.800
whenever you have a different tasks
for different targets.

00:08:18.800
00:08:20.550
[no audio]

00:08:20.550
00:08:23.200
If on all servers, if you want to perform
the same task,

00:08:23.200
00:08:24.600
you can add only one Playbook.

00:08:25.900
00:08:28.600
Whenever if you want to perform
different tasks with the

00:08:28.600
00:08:32.400
different targets, then we will write
number of plays.
00:08:32.400
00:08:36.200
So we will discuss about how to write
a number of plays later.

00:08:36.200
00:08:37.000
For the being,

00:08:37.000
00:08:40.900
I am going to show you a very simple
Playbook with one play,

00:08:40.900
00:08:43.700
and initially we will practice with only
one play. Once, if

00:08:43.700
00:08:47.600
you get some idea, then we will go
and execute number of place

00:08:47.600
00:08:48.600
with your playbooks.

00:08:48.600
00:08:51.400
[no audio]

00:08:51.400
00:08:52.200
Let me open. And I hope this has an
inventory.

00:08:52.200
00:08:56.700
[no audio]

00:08:56.700
00:09:01.300
Right suppose my requirement is, I
need to install on all

00:09:01.300
00:09:05.500
the server's suppose simply Wget
package on all the server's

00:09:05.500
00:09:07.700
I want to install Wget package.

00:09:07.700
00:09:12.500
So now observe that installing Wget
package is the task.

00:09:12.500
00:09:19.000
This is a task and on all the servers
now tasked with your

00:09:19.000
00:09:21.700
target is a, play. That's it.

00:09:21.700
00:09:25.700
Now this play you're writing in one file.
That is a Playbook.
00:09:25.700
00:09:27.900
Actually, you can write number of
place also, no problem.

00:09:27.900
00:09:30.700
But for time being, we are going to
discuss a Playbook with one play.

00:09:30.700
00:09:35.600
Be clear, we can write any number of
plays in your playbook for

00:09:35.600
00:09:40.300
time being. We are going to write only
one play in your playbook.

00:09:40.300
00:09:44.800
See Playbook is a file. Playbook is a
YAML file.

00:09:44.800
00:09:46.650
[no audio]

00:09:46.600
00:09:50.500
You have to start the Playbook with
three hyphens.

00:09:50.500
00:09:53.300
Then inside of Playbook, now I am
going to write only

00:09:53.300
00:09:57.300
one play, assume that you have only
one play in your playbook.

00:09:57.300
00:10:04.900
So play consists of targets. Targets as
well as tasks.

00:10:04.900
00:10:07.700
The task on which you are going to
perform that is a target.

00:10:07.700
00:10:10.600
Target with the task is a play, right?
That play is a Playbook here.

00:10:10.600
00:10:12.600
[no audio]

00:10:12.900
00:10:13.400
That's it.

00:10:13.400
00:10:17.400
[no audio]
00:10:17.400
00:10:21.900
Let me first write one simple Playbook.
See on all my servers.

00:10:21.900
00:10:24.100
I need to install simply Wget package.

00:10:24.100
00:10:28.400
Then I am writing a Playbook called
install_wget.yml

00:10:28.400
00:10:31.500
extension is yml or yaml? Okay, we'll
discuss about that in detail.

00:10:34.500
00:10:37.000
What happened? Yeah vim is not
there.

00:10:37.000
00:10:39.600
No problem install_wget.yml
[correction]

00:10:39.600
00:10:45.000
[no audio]

00:10:45.000
00:10:46.500
Now, see that what I am writing first.

00:10:46.500
00:10:50.500
I am writing three hyphens, which
represent that is a Playbook

00:10:50.500
00:10:52.500
then under that.

00:10:52.500
00:10:56.700
You have to write one space first then
hyphen, then this is a play

00:10:56.700
00:11:05.300
you write a code for your play.
Hyphen, we clear, space hyphen space.

00:11:05.300
00:11:08.200
You have to write a play. Play nothing
but targets play hosts.

00:11:08.200
00:11:11.800
So first you need to mention your
targets, hosts: all

00:11:11.800
00:11:18.900
targets then, play may consist of one
task or more than one.
00:11:18.900
00:11:23.500
So you have it tasks section inside the
task. You can write any

00:11:23.500
00:11:26.800
number of tasks, maybe one task or
number of tasks. See that

00:11:26.800
00:11:31.300
I am writing yum because we need to
install

00:11:31.300
00:11:33.900
Wget package. We have to work with
yum write.

00:11:33.900
00:11:40.100
Yum: name=wget State=present it's
the same

00:11:40.100
00:11:44.900
type of Ad-hoc command syntax, but
you know, this is you have

00:11:44.900
00:11:46.400
to exclude with root privileges.

00:11:46.400
00:11:49.500
That's why on our Ad-hoc commands.

00:11:49.500
00:11:52.800
We are writing hyphen be option. Now
here we have to mention that

00:11:52.800
00:11:57.300
as a become: yes But don't worry.
We'll discuss in detail.

00:11:57.300
00:12:00.600
Now this is a simple Playbook to install
Wget package and

00:12:00.600
00:12:02.200
all your servers.

00:12:02.200
00:12:06.700
Now, let me run simply that ansible
Playbook install Wget.

00:12:06.700
00:12:10.000
Here I'm using a password less
authentication.

00:12:10.000
00:12:12.900
I already exchanged my keys with all
my manage servers, now
00:12:12.900
00:12:13.800
see the result.

00:12:13.800
00:12:19.600
[no audio]

00:12:19.600
00:12:22.700
Yes. Changed zero means already.
Actually, we have that.

00:12:22.700
00:12:24.900
Let me remove instead of install.

00:12:24.900
00:12:26.600
Let me remove so that we can see
that.

00:12:26.600
00:12:34.100
[no audio]

00:12:34.100
00:12:37.000
So in detail, I will explain the output as
well with your playbooks.

00:12:37.000
00:12:40.000
[no audio]

00:12:40.000
00:12:42.800
See now changed one.

00:12:42.800
00:12:46.900
Just now we removed that. Our task is
changed means removed.

00:12:46.900
00:12:50.100
Changed=1 means your task has
been executed.

00:12:50.100
00:12:54.400
Okay, and if you remember, I told you
somewhere set up module

00:12:54.400
00:12:56.600
by default will execute with your
playbooks.

00:12:56.600
00:13:00.600
But on our Ad-hoc commands, you
need to run with hyphen setup module,

00:13:00.600
00:13:03.200
but Playbook by default will run your
setup module.

00:13:03.200
00:13:06.900
There is nothing but Gathering facts.
00:13:06.900
00:13:08.500
Okay, once again we'll discuss that.
Now see.

00:13:08.500
00:13:11.400
[no audio]

00:13:11.400
00:13:19.500
now what I am doing is, install your
package now let instead of absent

00:13:19.500
00:13:21.900
Let me write present or latest.

00:13:21.900
00:13:27.200
[no audio]

00:13:27.200
00:13:30.000
Now if I run this it is going to install
your Wget package on all servers.

00:13:30.000
00:13:32.000
[no audio]

00:13:32.000
00:13:37.900
Along with Wget suppose, I want to
install let's say some Vim.

00:13:37.900
00:13:41.900
Then it's very easy. Add one more
task on the other tasks section.

00:13:41.900
00:13:54.100
Simply write - yum: name=vim
state=latest to present or latest.

00:13:54.100
00:13:56.800
That's it. So now we are executing
multiple tasks.

00:13:56.800
00:13:59.200
So if already Wget is not installed,
then it we'll install.

00:13:59.200
00:14:03.000
If it is there it won't install because
ansible is idempotent.

00:14:03.000
00:14:05.500
If it is already state is reached it won't
stop, if it

00:14:05.500
00:14:07.900
is not reached, then only it will try to
reach the required
00:14:07.900
00:14:12.100
state by using your playbooks.
Change one.

00:14:12.100
00:14:17.600
See what that first yum is for? Install
wget, second yum is just to install vim

00:14:17.600
00:14:21.000
Vim is already there that's why it is not
installing.

00:14:21.000
00:14:22.500
[no audio]

00:14:22.500
00:14:25.600
Right now see that as of now we did
that. I mean to install your Wget and vim.

00:14:28.000
00:14:30.900
Let's say we have web servers now on
all servers.

00:14:30.900
00:14:35.400
We are installing Wget and vim but on
web servers, I want to install,

00:14:35.400
00:14:39.100
let's say httpd, then I am going to write
one more playbook

00:14:39.100
00:14:43.100
That is install_httpd.yml

00:14:43.100
00:14:49.800
[no audio]

00:14:49.800
00:14:50.600
See the result.

00:14:50.600
00:14:53.000
I mean, see the way how I am going to
write a playbook,

00:14:53.000
00:14:58.400
3 hyphens, then - space - space
hosts:

00:14:58.400
00:15:01.600
Now I want to work with only web
servers right?

00:15:01.600
00:15:03.900
And if you want to install your
package, you need to have
00:15:03.900
00:15:07.000
a hyphen b option on your own or
commands but here in playbooks

00:15:07.000
00:15:13.000
you all right become: yes then tasks
then what is your

00:15:13.000
00:15:14.700
task? You have to write with hyphens

00:15:14.700
00:15:19.600
So we'll discuss each and every rule
don't worry.

00:15:19.600
00:15:28.200
yum: name=httpd State=present if it is
not there then only it will install.

00:15:28.200
00:15:31.700
Now see that guys this is just to give
some idea.

00:15:31.700
00:15:34.100
Don't worry how to write a playbook
we will discuss that.

00:15:34.100
00:15:39.600
[no audio]

00:15:39.600
00:15:41.500
So already we have HTTP and all
servers.

00:15:41.500
00:15:45.600
That's why it is not installing. Now
guys, if you observe

00:15:45.600
00:15:50.700
if how to playbooks install

00:15:50.700
00:15:56.200
Wget packaged as one Playbook and
one more is install

00:15:56.200
00:16:00.100
HTTPD as a one more playbook. Now
here Target is different

00:16:00.100
00:16:04.200
all but here Target is different web.
Now if I want to Club these two.

00:16:04.200
00:16:05.800
Yes, we can Club simply.
00:16:05.800
00:16:08.500
What I am doing is, I am going to Club
this in your previous

00:16:08.500
00:16:13.200
Playbook, install Wget now see the
result.

00:16:13.200
00:16:18.200
[no audio]

00:16:18.200
00:16:22.800
See, this is one play. Target is different
and action are

00:16:22.800
00:16:25.000
also different supposed to tasks.

00:16:25.000
00:16:30.100
And this is second play. Target is
different, your task is also different.

00:16:30.100
00:16:32.800
So now this is a complete Playbook.
Playbook with

00:16:32.800
00:16:36.600
the different place multiple place.

00:16:36.600
00:16:40.000
Now what I am doing is I want to
remove and all my servers

00:16:40.000
00:16:43.200
your Wget and vim package.

00:16:43.200
00:16:47.100
And HTTPD servers on your web
servers. Then just let me write

00:16:47.100
00:16:51.000
absent and so that you can
understand how it is working.

00:16:51.000
00:16:52.900
Now, I am removing, so instead of
installing.

00:16:52.900
00:16:57.300
I want to remove on all servers vim
and Wget and on web servers,

00:16:57.300
00:16:59.900
I want to remove httpd. That's it.

00:16:59.900
00:17:05.500
[no audio]
00:17:05.500
00:17:08.598
So you guys now we have a Playbook
with multiple plays.

00:17:08.598
00:17:10.550
[no audio]

00:17:10.500
00:17:14.500
This is a Playbook that Playbook with
2 plays.

00:17:14.500
00:17:19.400
This play is organized with all these
servers. This play is your web servers.

00:17:19.400
00:17:25.800
That's it ansible-playbook install. This
is the Playbook name.

00:17:25.800
00:17:29.099
I'm removing actually now see that it is
executing.

00:17:29.099
00:17:32.200
First play first in sequence will execute
first will exclude

00:17:32.200
00:17:35.900
this one then it will execute second
one.

00:17:35.900
00:17:41.500
So in first to play first task is removing
the wget and vim done.

00:17:41.500
00:17:43.200
Sorry first task is removing

00:17:43.200
00:17:45.700
the obligate second task is removing
Vim

00:17:45.700
00:17:48.599
Now in second place a task,

00:17:48.599
00:17:52.000
we have only one task and removing
HTTPD right, then that's it

00:17:52.000
00:17:59.300
[no audio]

00:17:59.300
00:18:03.600
So finally how to understand that this
is a playbook.

00:18:03.600
00:18:05.400
[no audio]
00:18:05.400
00:18:08.700
Which consists of two plays.

00:18:08.700
00:18:11.400
Why we need to write a to plays
means whenever you have a

00:18:11.400
00:18:17.500
requirement to execute different tasks
on different targets.

00:18:17.500
00:18:19.600
Then we have to write different plays.

00:18:19.600
00:18:22.400
So guys while practicing, initially we'll
go with only one

00:18:22.400
00:18:27.800
play in your playbook, then once if you
are good with your

00:18:27.800
00:18:31.300
writing playbooks, then we'll go with
and do work with multiple

00:18:31.300
00:18:33.800
plays in your playbook.

00:18:33.800
00:18:34.400
Okay guys. Thank you for watching
this video.

00:18:34.400
00:18:40.300
[no audio]
Transcript
00:00:00.000
00:00:01.900
Friends here.

00:00:01.900
00:00:03.900
We are writing some simple
playbooks.

00:00:04.200
00:00:08.100
And these Play books are based on
the order of commands what

00:00:08.100
00:00:08.500
we know.

00:00:09.900
00:00:10.500
See already.

00:00:10.500
00:00:13.100
We know someone Rock commands
with some modules.

00:00:13.500
00:00:17.800
So now I am trying to convert our
aunts bulrog commands into

00:00:18.400
00:00:21.400
play books so that you will get some
idea how to write a
00:00:21.400
00:00:24.000
play book and also you will get some
confidence to write

00:00:24.000
00:00:25.200
your symbol playbooks.

00:00:25.800
00:00:30.100
Now, let me open my ansible
controller and see that here.

00:00:30.200
00:00:33.800
I have a inventory called host in that I
have three servers

00:00:33.800
00:00:38.400
with two groups one is web group
second one is DB group now

00:00:38.400
00:00:39.100
along with that.

00:00:39.100
00:00:42.500
I have a Will called Web dot XML on
this location.

00:00:43.200
00:00:43.400
Now.

00:00:43.400
00:00:47.500
My requirement is I need to transfer
this file to my web

00:00:47.500
00:00:50.400
groups are words for these two
servers and it would transfer

00:00:50.400
00:00:51.100
this file.

00:00:51.800
00:00:55.100
So using your ansible or how
commands how we can transfer

00:00:55.900
00:00:57.900
simply ansible your group name.

00:00:58.000
00:00:59.000
Then you are module.

00:00:59.000
00:01:00.000
That is copy.

00:01:00.000
00:01:03.000
We already discussed about this then
source.
00:01:03.300
00:01:05.800
So anyway, my file is there in the
current location directly.

00:01:05.800
00:01:08.300
I am giving the destination on your
manager node.

00:01:08.300
00:01:09.500
What is the location?

00:01:09.600
00:01:12.700
Ian to copy these if you don't mention
any location by default

00:01:12.700
00:01:14.800
user home on your managed nodes.

00:01:16.300
00:01:19.700
Now if you run this it is going to
transfer your file to

00:01:19.700
00:01:22.400
your managed nodes, but I want to
exclude this in terms of

00:01:22.400
00:01:23.200
a Playbook.

00:01:23.900
00:01:26.300
I want to convert this into a Playbook.

00:01:27.200
00:01:31.600
Now see that let me create a play
book called copy file dot.

00:01:31.600
00:01:37.700
Yml yaml or yaml Okay, then if you
want to write a play both

00:01:37.800
00:01:40.300
you have to start with three hyphens
then.

00:01:42.200
00:01:45.500
As of now we have only one target
right on this target.

00:01:45.500
00:01:47.000
We're excluding this task.

00:01:47.800
00:01:51.400
So one target with one task whenever
if you have multiple

00:01:51.400
00:01:53.900
targets with the different tasks, then
only have the right
00:01:53.900
00:01:54.800
number of plays.

00:01:55.600
00:01:58.500
So for time being we are going to work
with only one play

00:01:58.600
00:01:59.500
in your playbooks.

00:02:00.100
00:02:03.100
So if you want to write a play first of all
after three,

00:02:03.100
00:02:07.800
hyphens in the next line first to provide
one space then

00:02:07.800
00:02:13.400
- then space So this is the first step to
write your playbooks

00:02:13.699
00:02:15.900
then now you have to write a play.

00:02:16.000
00:02:20.400
What is your play your task with
targets?

00:02:21.500
00:02:25.700
So any more play to mention your
targets, you have to take

00:02:25.700
00:02:27.300
a key called host.

00:02:27.600
00:02:30.000
So our Target is web on web servers.

00:02:30.000
00:02:31.400
We need to execute our tasks.

00:02:32.400
00:02:33.000
Now.

00:02:33.100
00:02:35.900
We completed our play with the target
section.

00:02:36.100
00:02:39.300
Then you need to write your tasks as
well.

00:02:39.400
00:02:42.400
Not to write you what tasks you have a
task section.

00:02:42.400
00:02:45.500
You never play under your task.
00:02:45.500
00:02:48.000
You have to write the number of tasks.

00:02:48.100
00:02:52.600
Anyway, as of now you have only one
task so - Pace see that

00:02:52.600
00:02:56.700
this - and T should have equal space.

00:02:57.500
00:03:00.400
First of all, this is play underplay you
are going to write

00:03:00.400
00:03:04.000
all the keys all keys should have same
space before writing

00:03:04.000
00:03:06.600
your key under tasks.

00:03:06.600
00:03:07.700
I am writing tasks.

00:03:07.700
00:03:11.000
So first task - space.

00:03:11.100
00:03:13.000
What is your task copy?

00:03:13.200
00:03:16.500
What is the model for that copy copy:

00:03:16.600
00:03:20.300
your source and destination Source
equals to destination

00:03:20.300
00:03:20.600
equals 2.

00:03:20.700
00:03:21.100
That's it.

00:03:22.500
00:03:25.600
Now this is the simple Playbook to
copy your file.

00:03:25.700
00:03:33.300
Let me copy this and create on my
Controller copy file dot

00:03:34.000
00:03:38.600
ml simply copy to hear three.

00:03:38.600
00:03:44.200
Hyphens be clear First - foreplay If
You observe here, this

00:03:44.200
00:03:45.000
is your play.
00:03:47.700
00:03:49.800
Under this - this entire code is there.

00:03:51.200
00:03:53.900
Place nothing but targets with the
tasks.

00:03:54.100
00:03:58.000
So to represent it targets you have a
key called hose to

00:03:58.000
00:03:59.400
right number of tasks.

00:03:59.400
00:04:03.500
We have a key called tasks under that
you have to write any

00:04:03.500
00:04:06.100
number of tasks you can write but as
of now we are taking

00:04:06.100
00:04:07.100
only one task.

00:04:07.400
00:04:10.500
We will write some more tasks as well
in this session only

00:04:10.700
00:04:14.900
just wait now to exclude each and
every each and every task

00:04:14.900
00:04:15.800
you need a module.

00:04:16.500
00:04:17.800
We know already to transfer a file.

00:04:17.800
00:04:20.399
We are taking copy module source
and destination.

00:04:20.399
00:04:20.800
That's it.

00:04:21.200
00:04:25.300
Now, let me save this and run this now
to run your Aloha

00:04:25.300
00:04:28.200
commands. We are using ansible now
to run your playbook.

00:04:28.399
00:04:31.200
You have to run with ansible Playbook
then your playbook
00:04:31.200
00:04:33.000
name now see the result first.

00:04:42.300
00:04:43.300
Let me do one thing already.

00:04:43.300
00:04:45.700
Maybe that same file is there are my
managed nodes.

00:04:45.700
00:04:49.100
I will do one thing move web dot XML.

00:04:49.100
00:04:51.800
Sorry, I will modify some content into
that so that it is

00:04:51.800
00:04:55.200
easy. These are file for web servers.

00:04:59.100
00:05:05.700
for web group Let me rerun guys solid
actually previously

00:05:05.700
00:05:08.100
while practicing I copied that file.

00:05:08.100
00:05:11.100
That's why it is not showing any
modification now, let me

00:05:11.300
00:05:13.000
ask you not you are going to run very
first time.

00:05:14.600
00:05:15.900
Now see the result first.

00:05:17.900
00:05:21.800
Let me open your playbook as well
once senior Playbook.

00:05:23.500
00:05:24.400
This is web.

00:05:24.500
00:05:27.600
This is your Target and this is your
task.

00:05:27.600
00:05:30.700
So how many tasks we are having in
our tasks section only

00:05:30.700
00:05:34.200
one task But If You observe in your
playbook output, it has

00:05:34.200
00:05:35.800
been executed two tasks.
00:05:35.800
00:05:38.800
This is one task and this is one task,
but this is your given

00:05:38.800
00:05:41.300
task but not about this task.

00:05:42.200
00:05:47.000
So this is like Gathering facts see to
collect or gather

00:05:47.000
00:05:50.500
your facts of your managed nodes on
your ansible or commands.

00:05:50.500
00:05:51.800
We are running set up module.

00:05:52.500
00:05:56.800
But Playbook by default will run that if
you don't want to

00:05:57.400
00:06:00.500
take that if you don't want to collect
your facts we can

00:06:00.500
00:06:02.600
disable it with the key called.

00:06:03.700
00:06:05.900
Gather facts no or false.

00:06:06.000
00:06:09.200
So for time being I'm not going to work
with your gather

00:06:09.200
00:06:12.900
facts. So as of now you just try to
practice in the way in

00:06:12.900
00:06:13.400
this way.

00:06:14.600
00:06:17.900
Gather facts false or know, both are
same.

00:06:19.500
00:06:21.300
Now just to execute your tasks.

00:06:21.300
00:06:23.000
Let me modify once again.

00:06:23.000
00:06:24.100
You are file.

00:06:30.200
00:06:32.100
Guys be clear.
00:06:32.100
00:06:38.000
I disable collecting or gathering facts
by writing a key

00:06:38.000
00:06:40.600
called gather facts as false.

00:06:40.600
00:06:43.100
See that host:

00:06:43.100
00:06:47.500
space web gather facts colon space
false, right?

00:06:47.500
00:06:50.800
You need to provide this space
Observer here copy colon space

00:06:50.800
00:06:55.800
then Source equals to disk space
destination equals 2.

00:06:56.900
00:06:59.700
Fine now, let me run it once again
your playbook and see

00:06:59.700
00:07:00.500
the result.

00:07:08.500
00:07:10.500
How many players you are having in
your playbook?

00:07:10.700
00:07:15.200
We have only one play because this is
the - so for this -

00:07:15.200
00:07:16.600
exactly in the below somewhere.

00:07:16.600
00:07:19.700
If you have one more iPhone, then
you have one more play

00:07:19.700
00:07:20.200
as of now.

00:07:20.200
00:07:23.100
You have only one play so that's why
this is a play.

00:07:23.900
00:07:27.100
No, very have one more play like this
is play recap final

00:07:27.100
00:07:29.100
result this type of key.
00:07:29.100
00:07:31.800
You are not having in your output in
other places.

00:07:31.800
00:07:36.300
We are having only here so your play
on which Target you

00:07:36.300
00:07:40.900
are running this play web see the AB
then what is your first

00:07:40.900
00:07:41.800
task copy?

00:07:43.700
00:07:48.100
Changed on two servers changed
means it has been modified

00:07:48.100
00:07:49.600
on your targets are words.

00:07:50.600
00:07:53.500
Okay means how many tasks you
have been executed.

00:07:53.900
00:07:57.200
So only one task right that has been
executed and there has

00:07:57.200
00:07:58.100
been changed.

00:07:58.700
00:08:01.900
This is just to count how many tasks
we ran successfully

00:08:02.500
00:08:06.900
and this is change request one means
how many tasks whatever

00:08:06.900
00:08:08.500
the task you are running on this
server.

00:08:09.800
00:08:13.000
That has been changed only one task
we executed and that

00:08:13.000
00:08:15.900
is changed that I changed equals to 1
now.

00:08:15.900
00:08:18.900
If I rerun with the same content, we
are running.
00:08:19.000
00:08:21.800
I mean with web dot XML file we have
same content and if

00:08:21.800
00:08:25.500
you rerun there will be no change see
that.

00:08:25.500
00:08:29.300
Okay equals to 1 you are task has
been executed but because

00:08:29.300
00:08:32.900
of same information it did not change
it on your manager

00:08:32.900
00:08:35.000
node. That's it.

00:08:35.900
00:08:38.500
Likewise unreachable, you will get in
case if there are any

00:08:38.500
00:08:40.600
unreachable servers or failure task.

00:08:40.600
00:08:41.200
You will get here.

00:08:41.200
00:08:42.600
Skip we will get here likewise.

00:08:42.600
00:08:46.200
You will get your ignored and this
rescued we will see all

00:08:46.200
00:08:46.900
those things.

00:08:48.799
00:08:49.799
Right fine.

00:08:50.500
00:08:56.700
Now as of now your simple Playbook
is simply to copy a file.

00:08:56.799
00:08:57.200
Now.

00:08:57.200
00:09:00.200
I have one more task on this web
servers group.

00:09:00.200
00:09:02.700
That is I want to create.

00:09:04.900
00:09:05.700
Empty file.
00:09:06.000
00:09:07.000
Let's say file.

00:09:09.400
00:09:12.900
So for your file module if you want to
create an empty file,

00:09:13.100
00:09:16.700
you have to use file module file with
arguments are path

00:09:17.100
00:09:23.600
path Eco selects a demo dot demo
new DOT txt file.

00:09:24.000
00:09:26.400
And what is the state touch?

00:09:26.400
00:09:28.800
If you go with the touch State then
we'll create a file.

00:09:29.300
00:09:31.000
We are discuss about file module.

00:09:32.200
00:09:35.200
In you are or how commands you how
to run in this way?

00:09:36.800
00:09:44.000
Ansible web servers group module file
arguments or path equals

00:09:44.000
00:09:49.800
to any path then State equals to touch
steady course directory.

00:09:49.800
00:09:50.900
It will create a directory.

00:09:51.700
00:09:54.400
Now this we are converting into a
Playbook but already we

00:09:54.400
00:09:55.200
have a Playbook.

00:09:55.200
00:09:56.400
That's why directly.

00:09:56.400
00:09:58.900
I'm adding this task here.

00:09:59.500
00:10:00.000
That's it.

00:10:00.400
00:10:02.800
Now your playbook is having two
tasks.
00:10:03.800
00:10:07.400
Right now let me do one thing.

00:10:07.500
00:10:09.500
I am going to modify this information.

00:10:11.100
00:10:12.200
Just for our understanding.

00:10:13.700
00:10:15.400
Now, let me rerun before running.

00:10:15.800
00:10:17.100
Just observe your playbook.

00:10:22.300
00:10:24.900
You're having a Playbook with one
play.

00:10:24.900
00:10:29.700
And in that play we have tasks or to
see that this task -

00:10:29.700
00:10:32.700
and this task - or in the same space
that is important.

00:10:32.700
00:10:36.000
And this is C and this EF starting with
the same space that

00:10:36.000
00:10:36.700
is important.

00:10:36.700
00:10:37.900
Then this:

00:10:37.900
00:10:41.200
no need to I mean may or may not be
in the same space because

00:10:41.200
00:10:45.700
copy may have suppose copy and file
are having same characters.

00:10:45.700
00:10:46.300
That's why:

00:10:46.300
00:10:47.900
is coming up in the same place.

00:10:47.900
00:10:51.300
But if you have some other module
shell then this:

00:10:51.300
00:10:52.100
will come somewhere here.

00:10:52.900
00:10:53.900
But that is not a problem.
00:10:53.900
00:10:55.500
Only starting point is a problem.

00:10:57.100
00:10:59.800
Only you have to consider you have to
observe on left side.

00:11:01.100
00:11:05.000
Okay now if I run this Playbook See
the result.

00:11:07.500
00:11:11.300
Play you are running play on web
servers group tasks.

00:11:11.400
00:11:15.500
First task is copy know that is
executing executed and changed

00:11:15.500
00:11:19.500
as well and second task file and are
excluded and change

00:11:19.500
00:11:23.800
on those two servers now play recap
nothing but on which

00:11:23.800
00:11:28.400
servers you executed your clay onto
servers you executed

00:11:28.400
00:11:29.200
your tasks.

00:11:29.500
00:11:33.800
So now server wise you have your
result okay to means two

00:11:33.800
00:11:37.200
tasks performed successfully, but
change it to me.

00:11:37.800
00:11:40.600
On those two tasks in on your
managed server.

00:11:40.600
00:11:42.400
You have been changed over data.

00:11:42.500
00:11:43.000
That's it.

00:11:45.400
00:11:46.600
Right fine.

00:11:47.400
00:11:50.400
And if You observe in this output
simply are getting play
00:11:50.400
00:11:55.700
as web and a task as copy and here
task as file, but I want

00:11:55.700
00:11:58.500
to get some other information instead
of this see that what

00:11:58.500
00:11:58.900
I am doing.

00:12:01.600
00:12:03.500
Instead of Simply host.

00:12:03.600
00:12:07.100
I'm adding one argument one key
called name.

00:12:08.100
00:12:09.900
This is a simple.

00:12:12.000
00:12:18.900
play that's it on web web servers.

00:12:20.700
00:12:23.600
Previously, we don't have this name
name is optional for

00:12:23.600
00:12:26.300
your play as well as for your tasks
also.

00:12:28.100
00:12:31.000
Right first of these because of this
name what will happen.

00:12:32.500
00:12:35.700
Let me run and see the result
previously simply or getting

00:12:35.700
00:12:37.200
task as web.

00:12:37.400
00:12:40.500
Sorry play on web now for play.

00:12:40.500
00:12:42.900
I have given a name now see the
result.

00:12:45.700
00:12:48.400
This is a simple play on web server
words.

00:12:48.800
00:12:52.200
If you don't provide name by default
simply in the output
00:12:52.200
00:12:54.300
will display play with your group name.

00:12:54.900
00:12:56.300
I mean your target.

00:12:57.400
00:13:00.700
But if you write a name somewhat
decorating your playbook

00:13:00.700
00:13:05.700
output, this is a simple play on web
servers the same way

00:13:05.700
00:13:06.600
for tasks.

00:13:06.600
00:13:11.000
Also, you can write a name that is also
optional see that.

00:13:12.500
00:13:19.600
now if you want to write for your copy
task see that See

00:13:19.600
00:13:22.200
how I'm writing the spaces and they
are very very important

00:13:22.200
00:13:28.200
name. This is a task to copy a file to
remote or managed

00:13:28.200
00:13:33.500
nodes the same way for your second
task.

00:13:33.500
00:13:38.700
Also, you can write name option name
key name.

00:13:39.800
00:13:41.200
This is creating.

00:13:45.800
00:13:50.300
an empty file That's it.

00:13:51.500
00:13:53.800
See guys this entire thing is one task.

00:13:55.300
00:13:55.900
Don't right here.

00:13:55.900
00:13:58.900
Once again - if you write once again -
this is separate tasks.

00:13:58.900
00:14:01.800
And this is separate task suppose.
00:14:01.800
00:14:04.900
If I write here - this is toss.

00:14:04.900
00:14:06.600
This is Task, but this is not a task.

00:14:06.600
00:14:09.200
They just to display some information
while running your

00:14:09.200
00:14:10.500
playbook on your command line.

00:14:11.800
00:14:14.700
That's why this entire thing is a one
task.

00:14:17.200
00:14:23.500
right now Let's just try to practice as it
is.

00:14:24.500
00:14:25.700
We'll get good idea.

00:14:25.700
00:14:29.200
Good Clarity while going forward now.

00:14:29.200
00:14:32.800
Let me rerun your playbook and see
the result.

00:14:35.400
00:14:36.600
You're getting plane a mass.

00:14:36.600
00:14:40.500
This is a simple play on web servers
and task name previously.

00:14:40.500
00:14:43.100
You got here simply copy, but we have
given some name for

00:14:43.100
00:14:44.000
your task.

00:14:44.400
00:14:48.200
This is a task to copy file to manage
nodes and previously

00:14:48.200
00:14:52.300
you got here task name as simply file
module name, but now

00:14:52.300
00:14:54.700
we are getting this is creating an
empty file on your manager

00:14:54.700
00:14:55.800
nodes. That's it.
00:15:00.700
00:15:06.400
So observe your playbook name is
optional if you want to

00:15:06.400
00:15:09.100
write name for your play as well as
tasks.

00:15:09.100
00:15:11.800
You can write if you write it will display
that otherwise

00:15:12.400
00:15:17.000
your play will display by default Target
name and your task

00:15:17.000
00:15:19.000
will display by default the module
name.

00:15:19.500
00:15:22.100
Other than that if you want to display if
you want to showcase

00:15:22.100
00:15:22.800
your playbooks.

00:15:22.800
00:15:26.300
Yes, you can write your required name
option here.

00:15:28.200
00:15:28.600
Fine.

00:15:29.200
00:15:34.100
Now, the next thing is I want to install
suppose httpd on

00:15:34.100
00:15:35.600
all my web servers.

00:15:36.600
00:15:40.400
I want to install httpd on all my web
servers see on your

00:15:40.400
00:15:40.900
command line.

00:15:40.900
00:15:46.200
If you want to install and simple web
server group module

00:15:46.200
00:15:47.000
called M.

00:15:47.500
00:15:49.100
Then options.
00:15:49.200
00:15:53.000
I mean arguments name equals to
httpd.

00:15:53.000
00:15:56.600
Let me first run State as absent
because if I have already

00:15:56.700
00:15:57.700
D then it will remove.

00:15:59.700
00:16:02.800
If I run in this way, is it going to
execute?

00:16:05.100
00:16:06.200
Acrobat is not installed.

00:16:06.200
00:16:06.900
No problem.

00:16:08.500
00:16:13.200
Now let me install suppose if you want
to install latest

00:16:13.200
00:16:13.800
or present.

00:16:13.800
00:16:17.200
You can write then if I run this is it
going to execute?

00:16:17.400
00:16:20.000
No, we already know that what is the
reason for that?

00:16:21.100
00:16:25.800
You need to be route to perform this
command that means -

00:16:25.800
00:16:27.200
be hot to provide here.

00:16:27.700
00:16:32.900
So this is the ansible or how command
to run to install any

00:16:32.900
00:16:37.300
package with root privileges - be so
suppose if I try to

00:16:37.300
00:16:39.900
convert this into your Playbook let me
right.

00:16:41.400
00:16:45.000
So I want to install httpd as well as
some.
00:16:46.500
00:16:49.500
I want write a play book with I mean
play with the two tasks

00:16:50.100
00:16:55.100
httpd as well as W get let me check
with W gate is there

00:16:55.100
00:17:00.200
are not let me remove if I have so
before running out playbooks.

00:17:00.900
00:17:01.900
I am removing that.

00:17:05.200
00:17:06.598
If I have I will remove that.

00:17:09.000
00:17:10.400
Okay in not installed.

00:17:10.400
00:17:11.000
No problem.

00:17:11.098
00:17:14.400
Now see here for two tasks.

00:17:14.800
00:17:21.000
I want to write a play book ansible web
- em em command arguments

00:17:21.000
00:17:23.598
name equals to W get and state
equals 2.

00:17:25.200
00:17:30.500
present with root privileges so
previous your playbook without

00:17:30.500
00:17:31.300
root privileges.

00:17:31.599
00:17:33.900
No need of fruit privilege for this copy
module because we

00:17:33.900
00:17:37.900
are going to copy to the current user
home only in that case.

00:17:37.900
00:17:40.900
You do need to have any root
privileges, but for em command,

00:17:40.900
00:17:43.000
you know that you should have a root
Villages then how to
00:17:43.000
00:17:44.800
write now see the result.

00:17:45.200
00:17:50.700
First of all, I am writing install package
dot yml Playbook.

00:17:51.000
00:17:53.700
So if this is a Playbook you have to
start with three hyphens

00:17:53.800
00:18:01.500
then - Sorry space - space host.

00:18:02.100
00:18:05.200
But before that you can also provide
some name for your playbook.

00:18:05.200
00:18:08.100
Sorry for your play inside of Playbook.

00:18:08.100
00:18:09.200
We are writing number of places.

00:18:09.200
00:18:10.500
We are writing very first play.

00:18:10.700
00:18:13.700
Anyway, we are writing as of now only
one play but for play

00:18:13.700
00:18:15.000
you can provide some name.

00:18:15.700
00:18:24.400
So this is a play to install httpd and W
get packages on

00:18:24.500
00:18:25.800
web servers.

00:18:26.700
00:18:32.100
Group, that's it, then space Target on
which servers you

00:18:32.100
00:18:36.900
want to install then we are writing by
default gather facts

00:18:36.900
00:18:37.800
as false.

00:18:37.900
00:18:39.900
I don't want to execute this task.

00:18:41.000
00:18:43.900
False or both are same you can write
false or no?
00:18:44.800
00:18:47.500
Okay, guys, don't worry about this line.

00:18:47.500
00:18:50.000
Just try to write as of now gather facts:

00:18:50.100
00:18:50.400
no.

00:18:50.500
00:18:53.900
Okay, we'll discuss that then.

00:18:55.200
00:18:57.400
Next thing is tasks section.

00:18:57.400
00:19:00.200
So under tasks you have to write two
tasks.

00:19:00.200
00:19:03.300
That's why I first of all I have given two
hyphens one task

00:19:03.300
00:19:06.900
is install httpd and one more task is to
install web.

00:19:07.000
00:19:08.700
I mean w get package.

00:19:08.700
00:19:13.700
So here I can write directly em
module:

00:19:13.800
00:19:18.600
then, Name guys, this name is
different.

00:19:19.100
00:19:20.200
This is for your M.

00:19:20.500
00:19:21.500
What is the package name?

00:19:21.500
00:19:23.900
You want to install httpd?

00:19:24.100
00:19:28.400
Then State present or latest the same
way.

00:19:28.400
00:19:33.700
I want to install W get package then
State equals to present.

00:19:34.400
00:19:37.600
But if you remember we can also
provide some name for your
00:19:37.600
00:19:41.000
tasks. So that while running your task
it will display on

00:19:41.000
00:19:43.700
your command line name, so
installing.

00:19:45.400
00:19:50.700
Httpd package the same way I can
write for your second task

00:19:51.300
00:19:51.900
be clear.

00:19:51.900
00:19:58.600
I am providing same space name and
your gem named installing

00:19:59.100
00:20:00.500
W get package.

00:20:01.900
00:20:02.400
That's it.

00:20:03.300
00:20:07.500
But you know that while running this
these two tasks because

00:20:07.500
00:20:08.500
it is Yum command.

00:20:08.500
00:20:11.500
You should have a root privileges on
your animal or a command

00:20:11.500
00:20:13.900
line. You are providing - b-but in your
playbooks.

00:20:14.100
00:20:16.500
If you want to run your task with root
privileges.

00:20:16.500
00:20:20.200
You have to write become Yes means
run with route to leitch

00:20:20.800
00:20:22.400
become. Yes.

00:20:22.600
00:20:23.100
That's it.

00:20:23.800
00:20:23.900
Now.

00:20:23.900
00:20:25.100
Let me copy this.
00:20:26.500
00:20:34.800
And go to command line VI install
packages dot yml copy and

00:20:34.800
00:20:35.400
paste it.

00:20:36.100
00:20:36.700
That's it.

00:20:43.200
00:20:44.700
It has provided some space.

00:20:44.700
00:20:46.300
Let me Rectify that.

00:20:53.000
00:20:56.200
So you guys indentation or space is
very very important If

00:20:56.200
00:20:59.800
You observe these two are the tasks,
that's why these two

00:20:59.800
00:21:03.800
iPhones are in the same space same
space level, right?

00:21:04.100
00:21:07.200
So then remaining all are in the same
space that is important.

00:21:08.800
00:21:11.200
Fine now, let me save it run run it.

00:21:14.600
00:21:20.200
ansible Playbook install now see the
result.

00:21:21.900
00:21:24.700
See, this is a play to install extra band
obligate packages

00:21:24.900
00:21:28.100
and it is installing HTTP package first,
then it is installing

00:21:28.100
00:21:28.600
the obligate.

00:21:29.400
00:21:31.700
So finally how many tasks to tasks.

00:21:31.700
00:21:36.000
Okay to both two are okay and change
means yes, what are
00:21:36.000
00:21:39.100
the tasks you perform that modified on
your manager node

00:21:39.400
00:21:40.300
and no unreachable.

00:21:40.300
00:21:41.400
No fail, right?

00:21:41.400
00:21:41.900
No script.

00:21:41.900
00:21:42.700
No ignored.

00:21:45.100
00:21:50.100
Right, and if You observe in your
playbook you are play high

00:21:50.100
00:21:54.800
is having two tasks, right and these
two tasks or running

00:21:54.800
00:21:57.100
with root privileges.

00:21:57.500
00:22:00.400
You are having only two tasks and
those two stars are running

00:22:00.400
00:22:04.000
with root privileges in that case
instead of providing become

00:22:04.000
00:22:07.900
s individually for each and every task
in play level.

00:22:07.900
00:22:11.300
Also you can write that simply here
before tasks.

00:22:12.100
00:22:15.900
Become yes, you can write and you
can remove here.

00:22:16.200
00:22:18.600
So I am writing here hash symbol so
that the meaning for

00:22:18.600
00:22:21.700
hash is commented that line is not
there simply.

00:22:22.700
00:22:26.900
I commented that right as of now you
are installing now.
00:22:26.900
00:22:30.900
I am trying to provide absent so that it
will remove even

00:22:30.900
00:22:33.200
if you want to remove you should have
a root privileges right

00:22:33.500
00:22:35.900
instead of providing in the tasks level.

00:22:37.700
00:22:41.100
I provided in the play level this entire
thing is a playwright

00:22:41.100
00:22:41.600
for player.

00:22:41.600
00:22:43.600
I have given yes for each and every
task.

00:22:43.600
00:22:45.300
I want to exclude with root privileges.

00:22:45.300
00:22:46.000
That is the meaning.

00:22:47.000
00:22:50.400
Task level you can right here play level
for all tasks.

00:22:50.400
00:22:51.300
You can write here become.

00:22:51.300
00:22:51.800
Yes.

00:22:53.300
00:22:59.900
right now see instead of installing.

00:22:59.900
00:23:01.200
Let me write uninstalling.

00:23:05.200
00:23:06.200
Now here also.

00:23:08.300
00:23:13.400
Uninstalling the obligate package now
see the result my observation.

00:23:15.000
00:23:16.200
Become yes become yes.

00:23:16.200
00:23:20.000
I removed here because of with the
hash you removed and for
00:23:20.000
00:23:23.700
entire tasks if you have some any
number of tasks, whether

00:23:23.700
00:23:26.600
they are whether they need root two
edges are not if you

00:23:26.600
00:23:29.100
provide here become yes all are going
to exclude with root

00:23:29.100
00:23:31.900
privileges. Now see the result.

00:23:32.500
00:23:33.700
I am removing actually.

00:23:38.400
00:23:40.300
Change change uninstalling.

00:23:41.000
00:23:44.500
Yes, it has been uninstalled on the
server's you can change

00:23:44.500
00:23:45.800
the name for play as well.

00:23:46.200
00:23:48.700
This is a play to uninstall HTTP and
WL packages.

00:23:48.700
00:23:51.600
You can change your name also
based on your required tasks.

00:23:53.500
00:23:54.000
That's it.

00:23:54.400
00:23:55.000
So guys.

00:23:55.100
00:24:00.600
So these are the simple Play books to
understand about your

00:24:00.600
00:24:02.800
playbooks with place and number of
tasks.

00:24:03.000
00:24:08.700
And these flags gather facts no
become yes, you can provide

00:24:08.700
00:24:12.300
in the task level or in the play level
play level means for
00:24:12.300
00:24:13.100
all tasks.

00:24:13.900
00:24:14.300
That's it.

00:24:14.600
00:24:19.700
Okay, so guys just try to practice
whatever we done here.

00:24:20.200
00:24:23.400
Okay, but while going forward and we
will write number of

00:24:23.400
00:24:26.500
playbooks and you will get good
practice and you can understand

00:24:27.400
00:24:28.900
this is just to get some idea.

00:24:29.400
00:24:29.700
Okay?

00:24:30.100
00:24:30.500
Okay guys.

00:24:30.500
00:24:31.700
Thank you for watching this video.
Transcript
00:00:00.000
00:00:04.500
Friends here, we are discussing
simple key points to work

00:00:04.500
00:00:05.900
with playbooks.

00:00:05.900
00:00:09.100
So before entering into this concept,
let me write a simple

00:00:09.100
00:00:11.300
playbook first.

00:00:11.300
00:00:13.000
So, this is my ansible engine.

00:00:13.000
00:00:15.700
[no audio]

00:00:15.700
00:00:20.600
So here I have an inventory, so I am in
this location actually,

00:00:20.600
00:00:24.100
and if you agree here, I have two
nodes.
00:00:24.100
00:00:28.200
I am considering my ansible engine is
also one of the node

00:00:28.500
00:00:32.400
table we can consider right. See that
first, I am checking

00:00:32.500
00:00:34.300
ansible. One more thing.

00:00:35.000
00:00:37.700
If you observe in my ansible.cfg file.

00:00:38.300
00:00:41.700
I already modified the default
inventory.

00:00:41.700
00:00:43.350
[no audio]

00:00:43.350
00:00:47.600
With the inventory see that default
inventory name is host.

00:00:47.600
00:00:47.800
Now.

00:00:47.800
00:00:51.000
I modified that in the current location,
see how given the

00:00:51.000
00:00:53.200
location in the current location
inventory.

00:00:54.300
00:00:58.100
So, because why I have given that,
this is my inventory, that's it.

00:00:58.100
00:01:04.500
Now fine first. Let me check ansible
with the localhost.

00:01:04.500
00:01:06.250
[no audio]

00:01:06.250
00:01:06.700
Ping command. Yes.

00:01:08.000
00:01:12.400
I am able to work with my localhost
using my ansible.

00:01:13.100
00:01:13.700
That's fine.
00:01:14.300
00:01:19.000
Now guys suppose, I want to install
any package on your host.

00:01:19.200
00:01:23.000
Let's say I want to install Nano editor
then suppose if I

00:01:23.000
00:01:24.700
run yum install Nano.

00:01:24.700
00:01:25.700
It won't work.

00:01:26.300
00:01:29.800
It's saying that you need to be root to
perform this command.

00:01:30.500
00:01:34.000
So then so we know that for ansadmin
user we have root

00:01:34.000
00:01:36.900
privileges. That's why we are running
the same command with

00:01:37.600
00:01:40.800
sudo privileges. Now it will install and
it will ask confirmation

00:01:40.800
00:01:43.800
yes or no. As of now I'm not installing
because, I want to

00:01:43.800
00:01:50.300
install this with my playbook. So if you
observe sudo

00:01:50.300
00:01:57.300
yum install nano. Now I am going to
install suppose

00:01:57.300
00:02:03.300
some yum packages with Playbook.
Now let me write a playbook

00:02:03.300
00:02:06.300
so you know that if you want to write a
playbook you

00:02:06.300
00:02:11.000
have to start with three hyphens, then
in the next line one

00:02:11.000
00:02:17.000
space then hypen space. So this is the
first thing you have to follow
00:02:17.000
00:02:19.100
[no audio]

00:02:19.100
00:02:23.500
So Playbook consists of number of
plays,

00:02:23.500
00:02:25.200
but as of now, we are considering only
one play.

00:02:25.200
00:02:28.600
So, for each play, you should have a
Target. Target means host

00:02:29.200
00:02:32.200
on which hosts you are going to
execute your play or play

00:02:32.200
00:02:37.300
book so hosts: that is the key to
represent your target now

00:02:37.300
00:02:40.900
hosts. So as of now, I am going to
exclude this on one my

00:02:40.900
00:02:42.200
localhost itself.

00:02:43.100
00:02:45.400
Then see that spaces.

00:02:46.600
00:02:51.500
Then what you need tasks on
localhost what you want to exclude.

00:02:52.900
00:02:56.400
You ought to write some number of
tasks or single task, right?

00:02:56.800
00:02:57.400
See now.

00:02:57.400
00:03:03.100
This is the localhost now tasks now
under tasks section.

00:03:03.100
00:03:05.200
You can write any number of tasks
suppose.

00:03:05.200
00:03:12.300
I want to install Nano some httpd, right
then Task 1 - be
00:03:12.300
00:03:16.100
clear where I have written this -
exactly under t in the

00:03:16.100
00:03:18.300
task. You have t character right exactly
under t.

00:03:18.300
00:03:20.100
I have written - then space.

00:03:21.100
00:03:25.600
C to install your Nano you must use
yum module.

00:03:25.600
00:03:27.300
[no audio]

00:03:27.300
00:03:28.200
Right see yum.

00:03:28.300
00:03:32.700
What is the name for that name
equals to simply nano then

00:03:32.700
00:03:37.400
state=present or latest. That is one
task again.

00:03:37.400
00:03:38.600
I want to write one more task.

00:03:38.600
00:03:43.000
Then exactly under this hyphen, this
hyphen is for first task guys.

00:03:43.000
00:03:44.900
[no audio]

00:03:45.100
00:03:48.500
Now exactly under that hyphen, I'm
writing one more

00:03:48.500
00:03:52.700
hyphen, means I am writing one more
task then space then again.

00:03:52.700
00:04:01.100
yum, then name= to httpd then state=

00:04:01.100
00:04:03.800
to latest or present whatever it may
be.

00:04:04.900
00:04:05.400
That's it.
00:04:05.400
00:04:10.200
This is the simple playbook to install
your Nano and httpd

00:04:10.500
00:04:12.200
if you are the root user.

00:04:12.900
00:04:15.600
So as of now, you are not the root
user right, you are the

00:04:15.600
00:04:19.300
ansadmin user. I you observe here
and submit a user from

00:04:19.300
00:04:20.000
ansadmin user.

00:04:20.000
00:04:21.700
We are running our Playbook first.

00:04:21.700
00:04:32.200
Let me run it and ansible Playbook,
just observe the output

00:04:32.600
00:04:36.900
task is yum right while running with the
yum.

00:04:36.900
00:04:37.600
What will happen.

00:04:37.600
00:04:42.200
[no audio]

00:04:42.200
00:04:46.500
See that you need to be root to
perform this command.

00:04:46.600
00:04:54.300
We know that whenever if you run
error yum install httpd,

00:04:54.600
00:04:57.200
it's saying that you need to be root to
perform this command

00:04:57.200
00:04:57.800
same thing.

00:04:58.500
00:05:01.700
So, to overcome this, we are providing
sudo because our user

00:05:01.700
00:05:05.400
is having sudo privileges. Now how
can you provide this sudo
00:05:05.700
00:05:06.800
in your playbook?

00:05:07.800
00:05:18.100
Simple. Just enter so guys now
exactly under y yum become yes

00:05:18.100
00:05:22.600
Now these two lines are one task, the
same way for second

00:05:22.600
00:05:24.300
task also need to provide become.

00:05:24.300
00:05:25.300
Yes, I mean sudo.

00:05:27.000
00:05:30.600
Now if I write simply become: yes,
then that

00:05:30.600
00:05:33.500
is equal to sudo. That's it.

00:05:36.100
00:05:39.900
But one more thing here, you are
providing become yes

00:05:39.900
00:05:40.700
for your two tasks.

00:05:41.100
00:05:42.700
That's why instead of writing here,

00:05:43.000
00:05:46.200
you can also write simply entire play,

00:05:46.200
00:05:48.300
I want to run with sudo privilege.

00:05:48.700
00:05:52.300
You can write here in case if you want
to

00:05:52.300
00:05:55.800
exclude some tasks with sudo and
some just without

00:05:55.800
00:05:59.000
sudo, then only task level you have to
write here.

00:05:59.400
00:06:02.200
But if you want to exclude all tasks

00:06:02.200
00:06:05.600
with sudo privilege, then you can also
write instead of writing
00:06:05.600
00:06:06.900
here, become yes, become yes.

00:06:07.500
00:06:12.900
You can also write become yes here,
before your tasks section.

00:06:12.900
00:06:16.200
Right now anyway, as of now, I'm
commenting this is

00:06:16.200
00:06:17.100
the commenting line.

00:06:17.100
00:06:19.700
That means simply that is deleted
simply.

00:06:20.800
00:06:23.000
Now, let me save it and run it.

00:06:24.100
00:06:25.100
So, what is your play?

00:06:25.800
00:06:29.700
This is your play you're running that
Playbook now it is going

00:06:29.700
00:06:35.100
to install your Nano editor and then
one more thing is, you

00:06:35.100
00:06:38.000
are httpd. Just wait.

00:06:38.000
00:06:41.500
Yes, changed means it has been
installed.

00:06:41.600
00:06:45.900
What installed whatever the first task
you have then second

00:06:45.900
00:06:47.200
task, it is executing.

00:06:47.200
00:06:54.400
[no audio]

00:06:54.400
00:07:00.200
Done second task also done.
Changed right so totally on your

00:07:00.200
00:07:04.100
host 3 tasks have been executed. One
is gathering facts

00:07:04.800
00:07:06.300
remaining to order your yum
00:07:06.300
00:07:08.600
install Nano and Gem install httpd.

00:07:08.900
00:07:14.300
So those two changes the information,
that's why changed=2

00:07:14.300
00:07:18.900
But while running your playbook right
task simply yum.

00:07:19.700
00:07:21.200
I don't want to display in this way.

00:07:21.200
00:07:24.900
I want to display what actually that
task is, that's why if

00:07:24.900
00:07:28.900
you remember you can also write a
name for your tasks.

00:07:30.200
00:07:35.400
Simply see before yum, just enter see
you guys.

00:07:36.300
00:07:40.600
The spaces are very, very important
here named installing.

00:07:40.600
00:07:42.600
[no audio]

00:07:43.000
00:07:48.200
Nano editor. Then here also you can
write your name.

00:07:54.200
00:07:56.300
Installing httpd.

00:07:57.300
00:08:01.500
So now if you run your playbook right,
instead of displaying

00:08:01.500
00:08:05.400
like yum, instead of displaying like
task yam.

00:08:05.400
00:08:07.300
Here it will display your given name.

00:08:07.500
00:08:10.000
Let me run this and you already have
them.

00:08:10.100
00:08:16.300
I mean you're Nano and httpd but see
that previously you
00:08:16.300
00:08:20.100
got simply yum here, be clear in the
highlighted part, but here

00:08:20.100
00:08:22.000
installing Nano editor.

00:08:22.700
00:08:23.700
That is somewhat clear.

00:08:23.700
00:08:29.800
That's why we will use our name tag in
our tasks, but be clear

00:08:30.200
00:08:34.799
exactly under name how written yum.
Now these 3 lines are

00:08:34.900
00:08:39.000
under this task. So, these 3 lines are
one task.

00:08:39.000
00:08:41.900
These 3 lines are one task, right?

00:08:42.100
00:08:42.500
That's fine.

00:08:42.500
00:08:46.600
Now, this is the simple Playbook and
guys now, let me go

00:08:46.600
00:08:47.700
with your key points.

00:08:47.700
00:08:48.400
Very simple.

00:08:49.000
00:08:52.700
The very first one is how to run a
Playbook.

00:08:53.100
00:08:56.200
So how we are running our Playbook?
Simply ansible Playbook

00:08:56.799
00:09:23.500
your playbook. [some editing]

00:09:23.500
00:09:26.900
Now what I am saying is how to run a
playbook. Actually to

00:09:26.900
00:09:29.900
run your playbook, what you are doing
and Ansible Playbook than

00:09:29.900
00:09:31.000
your playbook name.
00:09:31.900
00:09:36.500
No need to run in this way. First just
check it which ansible

00:09:36.600
00:09:41.000
Playbook location of your ansible
playbook command. Just to

00:09:41.000
00:09:45.100
copy this, be clear then we open you
are.

00:09:46.300
00:09:51.300
Playbook instead of - - - three
hyphens at very first line

00:09:51.700
00:09:54.600
now. Just right like a shebang line.
That's it.

00:09:57.700
00:10:01.500
hash exclamation Tree location of your
ansible playbook command

00:10:02.900
00:10:05.700
save it provide execution permission.

00:10:05.700
00:10:09.000
[no audio]

00:10:09.300
00:10:13.100
Then simply run your playbook with a
DOT slash.

00:10:13.100
00:10:16.100
That's it. Now enter and see the result.

00:10:16.500
00:10:17.600
That's executing.

00:10:17.600
00:10:22.600
No, so no need to provide ansible -
Playbook again.

00:10:22.600
00:10:25.700
We mentioned that ansible - Playbook
inside of your playbook.

00:10:29.800
00:10:30.300
[no audio]

00:10:30.300
00:10:33.400
Right. So that is the way how you can
run your playbook without

00:10:33.400
00:10:38.800
mentioning ansible - Playbook before
your Playbook name
00:10:38.900
00:10:39.700
while running.

00:10:40.500
00:10:43.600
So instead of in this way, we can run
in this way.

00:10:43.600
00:10:44.600
It's very simple.

00:10:45.800
00:10:47.800
Right fine, then.

00:10:47.800
00:10:51.400
What is the next one is, how to verify
syntaxes suppose we

00:10:52.000
00:10:54.900
are writing our Playbook. Sometimes
maybe we missed some

00:10:54.900
00:10:58.600
syntaxes. So before running your
playbook suppose if I do

00:10:58.600
00:11:02.000
something like space is here.

00:11:02.000
00:11:03.700
I'll given space right now.

00:11:03.700
00:11:05.200
If I run this, you will get an error.

00:11:05.200
00:11:08.900
[no audio]

00:11:08.900
00:11:12.800
So before running this, you can also
simply check hyphen hyphen

00:11:13.700
00:11:15.000
syntax check.

00:11:15.000
00:11:23.400
[no audio]

00:11:23.400
00:11:25.500
Now see that it is giving an error.

00:11:25.500
00:11:29.600
[no audio]

00:11:29.600
00:11:31.300
Over here where you are having your
error.

00:11:33.100
00:11:35.100
Now, let me open that.
00:11:35.100
00:11:37.100
[no audio]

00:11:38.500
00:11:48.500
Now save it and again don't run
directly just ./install_yum_pks.yml __syntax-check

00:11:48.500
00:11:53.500
If there is no error syntax wise, then it
will say simply Playbook.

00:11:54.100
00:11:55.700
If you have an error, you will get in this
way.

00:11:56.700
00:11:59.900
So, if there are no errors, it will display
in this way.

00:12:00.400
00:12:01.500
Simply Playbook name it.

00:12:01.500
00:12:04.000
Will you know you can run your
playbook.

00:12:04.000
00:12:08.800
[no audio]

00:12:08.800
00:12:11.800
That's it. Anyway, already we have
those two packages.

00:12:11.800
00:12:15.200
That's why he's not going to install.
See change = 0

00:12:15.200
00:12:17.200
Means already we have them.

00:12:19.300
00:12:24.400
Then next point is how to run in dry
run mode.

00:12:24.800
00:12:26.200
First of all, what is dry run?

00:12:27.800
00:12:31.300
Say this mode does not make any
changes to remote machines.

00:12:31.400
00:12:32.700
I mean on your notes.

00:12:33.400
00:12:36.900
This only shows what changes would
have been made suppose
00:12:36.900
00:12:41.100
if you run your Playbook after running
successfully

00:12:41.100
00:12:45.400
your playbook what will happen. That
only it will show let

00:12:45.400
00:12:47.500
me do one thing first.

00:12:47.500
00:12:50.100
Let me remove yem install Nano
editor.

00:12:53.300
00:13:01.900
[no audio]

00:13:01.900
00:13:03.600
So as of now, do they have Nano?

00:13:04.100
00:13:05.900
Let me check it now hyphen hyphen
version.

00:13:07.700
00:13:10.900
[correction]

00:13:10.900
00:13:15.900
[no audio]

00:13:15.900
00:13:17.700
Okay, just now I remove Nano now.

00:13:17.700
00:13:21.900
We don't have Nano right now directly
suppose if you run

00:13:21.900
00:13:24.400
your playbook it will go and install your
Nano, because it

00:13:24.400
00:13:28.100
is not there, because your code is
there to install your Nano

00:13:29.000
00:13:30.800
and then to install your httpd.

00:13:31.900
00:13:35.200
Now I am not running directly my
ansible playbook.

00:13:35.500
00:13:38.800
What I am doing is, I am running in
this way - - check.
00:13:40.200
00:13:44.300
Right previously you have done with -
- syntax check, but now I

00:13:44.300
00:13:48.400
am passing argument as - - check
now see the result.

00:13:49.100
00:13:54.400
It is running your playbook, but it won't
modify the On your

00:13:55.000
00:14:00.600
nodes see that change it actually
change means what we will

00:14:00.600
00:14:02.800
feel it has been installed.

00:14:02.800
00:14:03.500
Let me check it.

00:14:03.500
00:14:04.600
Nano is installed.

00:14:06.300
00:14:10.300
No, but it showed that right
changed=1.

00:14:11.500
00:14:14.700
What it change installing nanometer,
let me remove one more thing

00:14:14.700
00:14:30.700
[no audio]

00:14:30.700
00:14:36.800
Now we don't have httpd as well as
Nano editors on my host

00:14:36.800
00:14:37.800
on my node.

00:14:39.100
00:14:41.000
Now what I'm doing is I'm running out
playbook.

00:14:42.400
00:14:45.700
But option as - - check now see the
result.

00:14:49.300
00:14:53.800
Change Nano editor installed installing
httpd changed.

00:14:54.500
00:14:58.800
So, changed=2 means generally we
will feel that your task
00:14:58.800
00:15:02.600
has been executed and they modified
on your nodes.

00:15:02.700
00:15:10.600
But if I check Nano, I don't have Nano
on my host.

00:15:10.900
00:15:16.100
And then if I check for httpd, I don't
have just now we ran

00:15:16.100
00:15:19.900
our Playbook and it showed that
change but actually it is

00:15:19.900
00:15:20.800
not installing.

00:15:21.300
00:15:24.400
It will tell you what will happen.

00:15:24.600
00:15:28.700
If you run your playbook with - - check
option.

00:15:28.700
00:15:30.700
[no audio]

00:15:31.900
00:15:33.600
Now this is called simply dry run.

00:15:34.900
00:15:38.100
Now if you removed dry run, now it will
execute actual task.

00:15:39.700
00:15:42.700
Right see that now, it is going to
install.

00:15:42.700
00:15:44.700
[no audio]

00:15:44.900
00:15:48.800
So simply - - check is the dry run if
you run your playbook

00:15:48.800
00:15:54.000
with - - check it will show you what
would happen if you

00:15:54.000
00:15:55.200
run your playbook.

00:15:55.200
00:15:57.100
[no audio]
00:15:57.100
00:16:01.000
If you remove - - check, now it will do
actual tasks.

00:16:01.000
00:16:03.000
[no audio]

00:16:03.800
00:16:05.900
You simply just to know what will
happen.

00:16:05.900
00:16:10.100
If you run your playbook without
modifying on your host on

00:16:10.100
00:16:13.800
your notes just to see the changes.

00:16:14.400
00:16:17.400
You can use - - check that's it.

00:16:17.400
00:16:20.600
[no audio]

00:16:20.600
00:16:21.000
Right.

00:16:21.000
00:16:26.000
That is simply dry run. Then how to
run Playbook to see verbose

00:16:26.100
00:16:27.400
output. Nothing.

00:16:27.400
00:16:29.800
See there guys, see very simple.

00:16:30.300
00:16:33.900
First of all, if I run simply my playbook,
it is displaying

00:16:33.900
00:16:37.600
only some steps like play localhost.

00:16:37.600
00:16:39.200
It is excluding on your localhost.

00:16:39.200
00:16:41.800
This is your target, then Gathering
facts.

00:16:41.800
00:16:43.100
Anyway, this is the default task.

00:16:43.100
00:16:46.900
We know then installing Nano editor
installing HTTP
00:16:46.900
00:16:53.200
editor. But if I go with - V option now
see the result?

00:16:53.200
00:16:55.200
[no audio]

00:16:55.300
00:17:00.000
It is giving some extra information like
using this as your

00:17:00.000
00:17:01.300
configuration file.

00:17:02.900
00:17:06.598
And installing Nano folder, see the
result previously you got

00:17:06.598
00:17:10.598
simply. Okay localhost, but it is giving
some verbose output.

00:17:12.200
00:17:17.000
If I use one more V - double v now it is
giving some more

00:17:17.000
00:17:26.000
information. So - vr - vvv options
verbose mode is

00:17:26.000
00:17:31.099
nothing but what your ansible is
taking, I mean, what are

00:17:31.099
00:17:34.300
the steps you are unable is taking to
execute your tasks.

00:17:34.300
00:17:38.099
So, if you want to see you can provide
a number of these

00:17:38.599
00:17:43.599
that see that each and every step now
it will show you how

00:17:43.599
00:17:46.599
it is going to connect. We know that it
is going to execute

00:17:46.599
00:17:48.000
your task with SSH, right?

00:17:48.200
00:17:52.800
You see that so now, if you see this
log this verbose information,
00:17:52.800
00:17:55.300
we can understand that what your
ansible is doing.

00:17:56.100
00:17:56.600
That's it.

00:17:57.200
00:18:01.500
So just - V or - VV.

00:18:01.900
00:18:03.600
I mean you can provide any number of
ways.

00:18:04.600
00:18:08.000
So, if you increase the number of v's,
you can see in detailed

00:18:08.000
00:18:08.900
output. That's it.

00:18:08.900
00:18:13.000
[no audio]

00:18:13.000
00:18:14.600
This is like verbose log.

00:18:16.200
00:18:19.500
Now actually by default your verbose
log is in some blue

00:18:19.500
00:18:20.300
color, right?

00:18:20.700
00:18:25.300
But if you want to change that, you
can change in your ansible

00:18:25.300
00:18:28.100
word CFG file grab.

00:18:30.000
00:18:33.800
See somewhere it is there were Bears
equals to Blue and there

00:18:33.800
00:18:37.400
is by default now, let me modify this.

00:18:41.500
00:18:45.400
Instead of blue, if you want to go with
some red.

00:18:45.500
00:18:46.800
Anyway, already that is there for error.

00:18:46.800
00:18:48.300
Let just let me show you that.

00:18:48.300
00:18:54.300
[no audio]
00:18:54.300
00:18:55.200
I will do one thing.

00:18:55.200
00:18:58.100
[no audio]

00:18:58.100
00:18:59.400
I will comment this line.

00:18:59.400
00:19:04.300
[no audio]

00:19:04.300
00:19:09.700
right now, I am running see now.

00:19:09.700
00:19:12.600
You're getting your verbose in terms of
red color.

00:19:12.600
00:19:14.600
[no audio]

00:19:14.700
00:19:17.000
Your or buzzlog you're getting in terms
of red color.

00:19:18.400
00:19:22.000
Right, so that's it, but I don't want to
use red, because red

00:19:22.000
00:19:22.900
is already for error.

00:19:22.900
00:19:26.600
[no audio]

00:19:26.600
00:19:29.700
If you want to take any other color, you
can mention

00:19:29.700
00:19:32.400
simply your color name here so that it
will work. That's it.

00:19:34.500
00:19:34.900
Right. So guys,

00:19:35.400
00:19:39.600
These are some simple points to
remember while working

00:19:39.600
00:19:41.900
with your playbooks, right?

00:19:41.900
00:19:44.300
[no audio]

00:19:44.300
00:19:46.000
Okay guys, thank you for watching this
video.
00:19:46.000
00:19:51.400
[no audio]
Transcript
00:00:01.700
00:00:02.400
Friends here.

00:00:02.400
00:00:06.400
We are discussing about how to print
any message using Playbook.

00:00:07.000
00:00:12.200
So we already know that if you want to
execute any task through

00:00:12.200
00:00:17.400
ansible, we need a model for that the
same way here print

00:00:17.400
00:00:20.600
any message is also a task now for
this task.

00:00:20.600
00:00:24.700
Also, we need a module now that
module is simply debug module.

00:00:25.400
00:00:29.600
So using debug module you can print
statements or variables
00:00:29.600
00:00:31.000
or any expressions.

00:00:32.500
00:00:36.300
And this debug module accepts three
parameters, they are

00:00:36.500
00:00:40.100
message variable and verbosity.

00:00:40.600
00:00:42.900
Let me go with one by one so that you
can understand the

00:00:42.900
00:00:44.200
usage of debug module.

00:00:44.800
00:00:46.900
Let me open My ansible Controller.

00:00:47.000
00:00:48.600
This is my ansible controller.

00:00:49.200
00:00:53.500
So here I have my inventory some
having two servers my in

00:00:53.500
00:00:57.300
my inventory one is my ansible
controller itself one is some

00:00:57.300
00:00:58.800
server from AWS cloud.

00:00:59.900
00:01:01.700
Anyway, let me check with.

00:01:05.500
00:01:08.300
I mean, let me check with connection
without your servers

00:01:08.900
00:01:10.000
using ping module.

00:01:13.100
00:01:15.100
So Local Host is able to reach now.

00:01:15.100
00:01:16.600
Let me check for your remaining.

00:01:16.600
00:01:20.100
Yeah, both to servers are able to
reach that's fine.

00:01:21.100
00:01:22.000
Now see here.

00:01:22.200
00:01:25.100
Our task is print any message through
Playbook.
00:01:25.500
00:01:25.700
Now.

00:01:25.700
00:01:29.200
I am going to write a play book that
Playbook is simply print

00:01:29.200
00:01:33.000
any message dot yml.

00:01:34.000
00:01:36.300
So first of all, we know the structure of
your aunt's will

00:01:36.300
00:01:36.800
play book.

00:01:37.200
00:01:39.300
So if you want to write a play book,
you have to start with

00:01:39.300
00:01:42.200
the three hyphens, or you can also
write a the location of

00:01:42.200
00:01:42.700
your answer.

00:01:43.500
00:01:45.400
Playbook command, we will see that.

00:01:46.500
00:01:48.700
First we have to start with the three
iPhones in the first

00:01:48.700
00:01:51.600
line in the next line first, you have to
provide space then

00:01:51.600
00:01:52.900
- then space.

00:01:53.500
00:01:59.700
So this - represents One play now
underplay we have different

00:01:59.700
00:02:04.300
sections one is Target Target means
on which server or group

00:02:04.300
00:02:08.100
you're going to execute this play or
play book so that we

00:02:08.100
00:02:11.900
have to represent with the host
parameter host.
00:02:14.199
00:02:17.000
As of now I am going to execute this
on my Local Host.

00:02:17.600
00:02:21.100
You can provide your group name
right or ever serve any required

00:02:21.100
00:02:22.900
server name then?

00:02:24.200
00:02:28.200
After that, you need to write a task
section means what are

00:02:28.200
00:02:31.200
the tasks you are going to execute on
your local host or

00:02:31.200
00:02:32.200
on your target?

00:02:33.300
00:02:37.000
So you may write any number of tasks
under your tasks section.

00:02:37.400
00:02:41.700
So each task you have to write with -
So suppose if I want

00:02:41.700
00:02:46.400
to write if I want to exclude for tasks
on my target for

00:02:46.400
00:02:49.900
- should be there and these for
iPhones should be there in

00:02:49.900
00:02:54.300
the same space and these four -
should be there under T exactly

00:02:54.300
00:02:56.900
under T letter in the in your task.

00:02:59.000
00:03:02.200
Then each task may have any number
of lines.

00:03:02.500
00:03:06.600
No problem suppose a surgeon that in
my first task I have

00:03:08.500
00:03:11.400
Line 1 line 2 line 3 likewise, you can
write any number of
00:03:11.400
00:03:16.600
lines just I am giving idea but all these
lines see that

00:03:16.700
00:03:19.500
lll should start with the same
indentation.

00:03:20.000
00:03:22.800
I mean same space should be there
for all these three lines.

00:03:23.200
00:03:23.800
That's it.

00:03:24.400
00:03:25.400
So that is the idea.

00:03:25.500
00:03:25.700
Now.

00:03:25.700
00:03:31.200
Let me go and use our debug module
to print any message.

00:03:31.800
00:03:35.100
We know that task can be executed
with the with the help

00:03:35.100
00:03:39.400
of any module now our task is any
Soon as I want to print

00:03:39.500
00:03:43.300
so for that you need to select debug
module then colon space.

00:03:44.200
00:03:47.400
So debug module taking three
parameters one is message.

00:03:48.000
00:03:51.000
Let me use message first message is
nothing, but just in

00:03:51.000
00:03:54.900
simply print to print any message, let's
say debug message

00:03:54.900
00:04:11.000
equals 2 Welcome to and symbol and
simple playbooks That's

00:04:11.000
00:04:12.300
it. Now.
00:04:12.300
00:04:18.300
Let me save it and run it and Sybil
Playbook print any message

00:04:18.300
00:04:21.000
dot. Yml, that's it now see the result.

00:04:24.500
00:04:28.200
So first to see your play book once we
don't have much Concepts

00:04:28.200
00:04:32.000
here simply, we have Target and Tas
section under task.

00:04:32.000
00:04:35.400
We have only one task now see the
result play.

00:04:36.300
00:04:37.900
It is executing on localhost.

00:04:39.200
00:04:41.900
Then first task is gathering facts.

00:04:41.900
00:04:45.200
We know that this is the default task
then our task is debug

00:04:45.200
00:04:47.700
task. So through debug what we are
doing simply.

00:04:47.700
00:04:50.600
We are printing a message called
Welcome to ansible Playbooks.

00:04:50.700
00:04:51.200
That's it.

00:04:51.600
00:04:54.300
So if you want to print any message
you have to use debug

00:04:54.300
00:04:56.500
module with message parameter.

00:04:57.800
00:05:01.800
See I want to modify this in this way
the same debug module.

00:05:02.300
00:05:05.600
You can also write parameters in the
next line, but under

00:05:05.600
00:05:08.600
debug you have to write see that
under debug.
00:05:11.500
00:05:14.000
Colon, then space be clear.

00:05:15.200
00:05:17.600
Let me keep that line as it is.

00:05:18.600
00:05:20.100
I want to comment this.

00:05:21.100
00:05:23.800
So this is one way to write your debug
module to print a

00:05:23.800
00:05:29.900
message. Then or you can also write it
debug:

00:05:29.900
00:05:36.300
enter under debug just to provide
some space after d then

00:05:36.300
00:05:38.300
write message then:

00:05:38.400
00:05:40.300
but not equally here then.

00:05:42.300
00:05:48.300
welcome to I mean any message
whatever you want to print

00:05:48.300
00:05:49.200
through your playbook.

00:05:49.200
00:05:49.800
That's it.

00:05:50.300
00:05:52.000
See the difference between here and
here.

00:05:54.500
00:05:57.500
So here I have written message colon
space here space is

00:05:57.500
00:06:00.200
needed then welcome to ansible
Playbook.

00:06:02.800
00:06:06.500
even if you want to verify, you know
how to verify your syntax

00:06:07.200
00:06:14.700
right simply - - syntax check Yes,
everything is fine.

00:06:16.800
00:06:18.800
Now, let me run it and see the result.
00:06:22.900
00:06:23.500
That's it.

00:06:24.500
00:06:25.700
Right same output.

00:06:25.700
00:06:27.600
There is no difference between your
previous output in the

00:06:27.600
00:06:32.600
current output and one more thing
while running your playbook.

00:06:32.700
00:06:36.200
I want to display the plane name, not
your target here by

00:06:36.200
00:06:37.700
default to display Target.

00:06:38.900
00:06:40.000
What is your Target?

00:06:40.900
00:06:44.500
CEO Target is localhost, but I want to
display here instead

00:06:44.500
00:06:45.500
of Target name.

00:06:45.500
00:06:47.600
I want to display some required name.

00:06:48.000
00:06:50.800
What is the play for that?

00:06:51.600
00:06:54.500
I mean, I can provide some name for
your clay.

00:06:54.900
00:06:58.800
So for that you have to add name
section name.

00:06:59.600
00:07:01.300
This is a simple play.

00:07:05.400
00:07:12.000
to understand Debug module, that's it.

00:07:13.200
00:07:16.600
The same way you can also provide
the name for your task

00:07:17.300
00:07:19.500
right name.

00:07:20.900
00:07:23.100
Printing message anything.
00:07:23.300
00:07:27.100
I mean, this is just a name for your
task printing a message

00:07:27.200
00:07:31.300
with message parameter of debug
module.

00:07:32.500
00:07:33.000
That's it.

00:07:33.300
00:07:34.800
Now, let me save it and run it.

00:07:40.600
00:07:41.800
See you're getting now.

00:07:41.800
00:07:44.300
This is a simple play to understand
debug module because

00:07:44.300
00:07:46.100
we have given a name for our play.

00:07:46.600
00:07:50.000
This entire thing is one play and for
that play we have given

00:07:50.000
00:07:53.600
a name and this entire thing is a task
done for this task.

00:07:53.600
00:07:54.600
We have given a name.

00:07:55.100
00:07:55.600
That's it.

00:07:58.600
00:07:59.800
Right, that's fine.

00:08:00.400
00:08:05.200
Now you can also print multiple
messages using your debug

00:08:05.200
00:08:06.800
module with message parameter.

00:08:07.100
00:08:11.000
So if you want to display multiple
messages see that under

00:08:11.000
00:08:18.100
message just right - then write one
more - see here what

00:08:18.100
00:08:18.700
I am writing.
00:08:20.400
00:08:22.700
And these are the basics Concepts.

00:08:32.100
00:08:33.900
If you want to write one more line you
can write.

00:08:37.700
00:08:38.500
We'll discuss.

00:08:42.799
00:08:47.299
Advanced two concepts Later, that's it.

00:08:47.400
00:08:47.500
Now.

00:08:47.500
00:08:48.799
Let me save it and run it.

00:08:50.200
00:08:53.900
See the output how many messages
you are going to print so

00:08:53.900
00:08:56.900
that is the way how you can print
multiple messages using

00:08:56.900
00:08:57.700
your message.

00:08:59.200
00:09:03.900
And if you know python this is a list of
values whenever

00:09:03.900
00:09:07.200
if I write hyphens that is the list or
sequence.

00:09:08.900
00:09:10.200
Right, that's fine.

00:09:12.500
00:09:14.900
Now we have our play in this way,
right?

00:09:16.900
00:09:18.700
They simply print a message now.

00:09:18.700
00:09:20.400
I want to print a variable value.

00:09:21.600
00:09:24.100
Now, let me write print variable dot.

00:09:24.100
00:09:24.600
Yml.

00:09:25.100
00:09:28.100
So again guys directly now, I am
writing three hyphens or
00:09:28.100
00:09:30.800
instead of this three instead of three
hyphens.

00:09:31.100
00:09:34.800
I want to write location of your unspool
playbook inside

00:09:34.800
00:09:35.600
of your play.

00:09:36.300
00:09:37.700
I mean instead of your playbook.

00:09:40.100
00:09:47.900
see that then space - then name.

00:09:49.300
00:10:00.400
usage of debug module then Target
host Local Host and then

00:10:02.100
00:10:03.000
tasks section.

00:10:03.600
00:10:05.300
So how many tasks you want to
execute?

00:10:05.300
00:10:07.300
I want X good only one task.

00:10:07.600
00:10:11.200
Let's say - name is printing.

00:10:13.800
00:10:20.400
A variable value using debug mod you
something like that

00:10:20.500
00:10:22.100
if you want write you can write any
message.

00:10:23.000
00:10:25.700
Then debug is here.

00:10:26.600
00:10:30.000
We know that I can write message
equals 2 in this line or

00:10:30.900
00:10:32.800
under debug be clear.

00:10:33.100
00:10:37.800
I am not starting from where D is
starting CD starting this

00:10:37.800
00:10:40.600
much space, so I don't want to take
that space.
00:10:40.700
00:10:42.200
I should not take that much space.

00:10:42.200
00:10:44.800
I have to take some extra space and I
need to write message

00:10:44.900
00:10:45.600
under debug.

00:10:46.500
00:10:48.800
See how some extra space here.

00:10:49.900
00:10:50.900
That is important.

00:10:52.000
00:10:55.400
then The host name.

00:10:55.400
00:10:58.400
I'm writing the host name is guys.

00:10:58.400
00:11:01.300
If you remember in our previous
videos, we have discussed

00:11:01.800
00:11:03.400
the default variable names.

00:11:04.100
00:11:05.000
Let me right.

00:11:06.100
00:11:11.300
Inventory hostname see observe that I
have written two curly

00:11:11.300
00:11:15.400
braces. So actually inventory variable
inventory host name

00:11:15.400
00:11:16.800
is a default variable.

00:11:17.000
00:11:18.900
I want to print the variable value.

00:11:20.400
00:11:22.700
Then I have to take two curly braces
for that.

00:11:23.400
00:11:23.600
Now.

00:11:23.600
00:11:27.800
Let me save it see suppose in your
shell scripting x equals

00:11:27.800
00:11:31.400
to 3 if you want to display x value we
are using dollar X.
00:11:32.100
00:11:37.800
So now to display my variable value
using your debug with

00:11:37.800
00:11:40.300
the help of message parameter.

00:11:40.300
00:11:41.900
I am using two curly braces.

00:11:43.900
00:11:48.100
Now if You observe your playbook
you're having shebang line,

00:11:48.200
00:11:51.200
I mean the location of your aunt's will
play book now directly

00:11:51.200
00:11:55.200
can run with the dot slash print where
variable dot yml,

00:11:55.500
00:11:57.600
but you should have a execution
permission for that.

00:11:57.900
00:12:02.600
So I am giving execution permission
now, I am running see

00:12:02.600
00:12:03.300
the result.

00:12:07.900
00:12:11.400
See you're getting Local Host because
in your playbook you

00:12:11.400
00:12:13.000
given Target as localhost.

00:12:14.300
00:12:16.900
Right now let me modify that.

00:12:18.100
00:12:26.000
all means all the servers which are
there in my inventory

00:12:26.800
00:12:27.900
now see the result.

00:12:37.400
00:12:39.900
So guys I already told that why it is
taking that much time

00:12:39.900
00:12:43.200
means one of the server is my local
server one more server
00:12:43.200
00:12:46.700
is my AWS Cloud Server for different
networks.

00:12:46.700
00:12:48.400
It is taking some time to connect with
that.

00:12:48.400
00:12:49.000
That's fine.

00:12:49.400
00:12:53.300
Now see the result the host name is
you're getting this is

00:12:53.300
00:12:56.700
the server remote server and this is
the one more remote

00:12:56.700
00:12:58.100
server. Anyway, that is localhost.

00:12:59.300
00:13:00.600
See now here.

00:13:00.900
00:13:03.600
I printed the variable name.

00:13:03.700
00:13:06.700
We're sorry variable value through
your message parameter

00:13:06.700
00:13:07.700
of debug module.

00:13:08.400
00:13:14.300
So whenever if you want to print the
message fizzy some message

00:13:14.800
00:13:17.900
along with variable value, then you
have to take message.

00:13:19.600
00:13:22.900
Parameter of your debug module, but I
don't want to print

00:13:22.900
00:13:24.000
any message simply.

00:13:24.000
00:13:26.700
I want to print variable value then in
that case.

00:13:26.700
00:13:28.300
You have to take simply.

00:13:29.300
00:13:30.600
Let me comment this line.
00:13:31.100
00:13:32.600
So I'm commenting this line.

00:13:33.000
00:13:38.600
sea ice I'm writing simply here where:

00:13:41.400
00:13:44.200
let me hear no need to take any curly
braces whenever if

00:13:44.200
00:13:47.800
you take where parameter of your
debug module no need to

00:13:47.800
00:13:48.600
take any.

00:13:50.800
00:13:54.400
Curly braces only for message
message parameter you have

00:13:54.400
00:13:58.800
to take curly braces for your variable
and the usage of message

00:13:59.200
00:14:01.400
parameter is with some message.

00:14:01.400
00:14:03.000
You can also print variable value.

00:14:04.300
00:14:05.600
See here directly.

00:14:05.600
00:14:07.700
We got our variable value.

00:14:10.000
00:14:10.700
Be clear.

00:14:13.000
00:14:16.400
If you go with message parameter,
you can print some message

00:14:16.700
00:14:18.000
as well as variable value.

00:14:18.500
00:14:21.600
But if you go with the variable where
where parameter of

00:14:21.600
00:14:24.700
your debug you can print only variable
values, you cannot

00:14:24.700
00:14:27.600
print any extra additional message
apart from this variable
00:14:27.600
00:14:31.600
value and here I'm using curly braces
here don't use curly

00:14:31.600
00:14:33.400
braces. There is a syntax root.

00:14:34.800
00:14:40.200
Right, then the last one of your debug
model parameter is

00:14:40.800
00:14:42.600
verbosity. What is that?

00:14:45.700
00:14:47.500
Let me write one extra.

00:14:48.700
00:14:55.700
Playbook Verbosity debug dot.

00:14:55.700
00:15:01.100
Yml any name so I am starting with
the three hyphens then

00:15:01.100
00:15:10.000
Hive space - a space name usage of
verbosity of debug.

00:15:11.500
00:15:15.800
Module then targets targets you have
to represent with the

00:15:15.800
00:15:18.300
host key right host suppose.

00:15:18.300
00:15:19.800
I am going to take only Local Host.

00:15:19.900
00:15:24.300
You can take any any group name
also, no problem then tasks

00:15:24.800
00:15:26.500
so I am going to write two tasks.

00:15:28.900
00:15:39.200
first task I am going to provide name
as verbosity as default

00:15:40.200
00:15:43.100
Debug, I am writing simply some
message.

00:15:43.100
00:15:47.300
I can write in the same line with
message equals 2 or under

00:15:47.300
00:15:48.500
debug. Message:
00:15:49.000
00:15:53.600
this is Default message.

00:15:53.600
00:15:55.700
I'm writing then second task.

00:15:55.700
00:15:56.400
I'm writing.

00:15:58.800
00:16:05.900
or birth city Is some to you can take
one two, three four,

00:16:06.200
00:16:06.700
no problem.

00:16:08.100
00:16:12.600
then debug I am writing messages as
first of the output this

00:16:12.600
00:16:19.000
is or let me write verbosity.

00:16:23.500
00:16:29.600
is too Let me run this and see the
output first before that.

00:16:29.600
00:16:31.400
Let me cut this.

00:16:35.100
00:16:41.500
Now I'm running see the output.

00:16:50.600
00:16:51.100
Right.

00:16:51.200
00:16:55.100
Now what I am doing is I am executing
with - V option and

00:16:55.100
00:16:55.900
see the result.

00:17:02.700
00:17:06.400
with the two - bees Oh, sorry.

00:17:09.200
00:17:16.900
VI by sub forgot to use verbosity here
Now let me use.

00:17:19.400
00:17:25.800
verbosity as to Yeah, now you can
understand.

00:17:25.900
00:17:26.800
So before that.

00:17:27.098
00:17:28.098
This is your playbook.
00:17:28.900
00:17:33.000
So for this message, I have given
verbosity as to for this.

00:17:33.099
00:17:34.400
Sorry for this task.

00:17:34.500
00:17:37.099
I did not provide any verbosity now.

00:17:37.099
00:17:41.599
Let me run this without any perversity
and see the result.

00:17:44.400
00:17:45.500
Say this is skipping.

00:17:46.800
00:17:50.000
This second task is not executing.

00:17:50.300
00:17:55.100
The reason is we have given verbosity
as to that means while

00:17:55.100
00:17:56.200
running your playbook.

00:17:56.200
00:18:01.500
If you provide - VV 2 or basicity levels
then only that message

00:18:01.500
00:18:03.300
will display now see the result.

00:18:07.200
00:18:08.500
Or suppose if I Q3?

00:18:12.400
00:18:16.500
See the result so minimum verbosity is
2 that means two or

00:18:16.500
00:18:17.100
more than that.

00:18:17.100
00:18:19.800
It will display by default.

00:18:19.800
00:18:22.800
It is displaying this task is by default
displaying.

00:18:23.000
00:18:29.200
The reason for that is See the I did not
provide any verbosity

00:18:29.200
00:18:34.100
here by default verbosity is 0 by
default verbosity value
00:18:34.100
00:18:34.900
is zero.

00:18:37.100
00:18:40.900
Whether you mention or not that is by
default 0 means without

00:18:40.900
00:18:46.300
any debug it will display your value
with verbosity as zero.

00:18:47.900
00:18:52.300
but whenever if you mention verbosity
if you pass that level

00:18:52.300
00:18:57.500
while running your playbooks then
only it will execute that

00:18:59.800
00:19:04.700
you simply ansible Playbook verbosity
Playbook.

00:19:05.000
00:19:08.300
If I do with - V only one verbosity level.

00:19:08.300
00:19:09.500
I want to see the output.

00:19:11.000
00:19:12.700
Now you're not getting second task.

00:19:13.100
00:19:16.300
You will get only first task second task
is skipping because

00:19:16.600
00:19:21.500
their verbosity is to so that is the
usage of verbosity level

00:19:21.500
00:19:22.900
of your debug module.

00:19:23.900
00:19:24.700
All right.

00:19:24.700
00:19:27.500
So while going forward while working
with the real-time scripts,

00:19:27.500
00:19:31.700
you will see the effective uses of
verbosity as of now try

00:19:31.700
00:19:36.000
to understand the usage of message
parameter and variable
00:19:36.000
00:19:41.500
parameter. Right, so just to go through
these two as of now.

00:19:42.600
00:19:44.500
And while working with the real-time
script, we will see

00:19:44.500
00:19:46.600
the usage of verbosity in detail.

00:19:48.000
00:19:48.600
That's fine.

00:19:49.900
00:19:50.400
Okay guys.

00:19:50.400
00:19:51.700
Thank you for watching this video.
Transcript
00:00:00.000
00:00:04.000
Friends here, we are discussing about
Ansible Variables

00:00:04.800
00:00:08.199
We had a small discussion on this
ansible variables in our

00:00:08.199
00:00:10.900
previous videos, but here we are
going to discuss them with

00:00:10.900
00:00:12.800
the help of ansible playbooks.

00:00:12.800
00:00:14.700
[no audio]

00:00:14.700
00:00:15.600
Let me go through that.

00:00:16.100
00:00:20.500
First of all, what is the variable?
Simply variable is used

00:00:20.500
00:00:24.000
to store value and we know that we
have different types of
00:00:24.000
00:00:28.200
variables in our ansible and these are
the variables and

00:00:28.200
00:00:30.700
if you remember, we had a discussion
on this default

00:00:30.700
00:00:34.100
variables and facts and local facts in
our previous videos.

00:00:34.700
00:00:37.900
And here we are going to discuss
about custom variables.

00:00:38.300
00:00:39.300
Let me go through that.

00:00:40.100
00:00:45.200
so first of all, what is a custom
variable? Simply, a variable

00:00:45.200
00:00:50.400
which is defined by us, is called a
custom variable.

00:00:50.800
00:00:54.200
Suppose if I go with shell script if I
want to define

00:00:54.200
00:00:58.200
a variable called x with value of 4,
then I have to

00:00:58.200
00:01:02.900
write x = 4, but same representation
we can do in

00:01:02.900
00:01:09.700
our yaml/Playbook with X colon space
4.

00:01:10.400
00:01:12.900
This is in your shell scripts or suppose
in Python script

00:01:13.200
00:01:15.600
the same representation in your
yaml/Playbook.

00:01:15.600
00:01:19.000
You have to write in this way X colon
space 4 is nothing
00:01:19.000
00:01:23.200
but x value is 4 and here x is a
variable or key and this

00:01:23.200
00:01:24.000
is a value.

00:01:24.000
00:01:26.000
[no audio]

00:01:26.000
00:01:30.400
So generally, we will represent a
variable in yaml/Playbook

00:01:30.400
00:01:34.700
as a key value pair representation, like
key: value.

00:01:35.100
00:01:38.200
So, example x colon space 23.

00:01:38.700
00:01:43.000
So here x is a key or variable and its
value is 23.

00:01:43.000
00:01:45.300
This is called key value pair
representation.

00:01:46.200
00:01:48.800
So same way if I want to define some
float value

00:01:48.800
00:01:53.800
y colon space some float number and
here y is a key or a

00:01:53.800
00:01:57.300
variable and this is the value, and this
is finally

00:01:57.300
00:01:58.900
key value pair representation.

00:01:59.300
00:02:03.700
So, this representation is called simply
scalar that's it.

00:02:04.500
00:02:08.699
Scalar a key value pair representation
in your ansible or

00:02:08.699
00:02:11.100
yamll script is called simply a scalar.

00:02:11.600
00:02:12.199
That's it.
00:02:12.900
00:02:15.200
Now here x is a key or variable right?

00:02:15.300
00:02:18.900
So, I have selected a variable name
as x or key name as x

00:02:18.900
00:02:23.200
No, while selecting this key or variable
names you have

00:02:23.200
00:02:24.300
to follow some rules.

00:02:25.300
00:02:29.800
They are like ansible variable names
or key name should be

00:02:29.800
00:02:35.700
Letters, numbers, underscores and
they should always start with

00:02:35.700
00:02:42.300
a letter. If I take x space y colon

00:02:42.300
00:02:43.700
some number.

00:02:43.700
00:02:47.600
This is not a valid variable or valid key,
x underscore y

00:02:47.600
00:02:52.400
is a valid and 1X is not a valid variable
or key x 1 is a

00:02:52.400
00:02:53.600
valid that's it.

00:02:53.700
00:02:58.400
So those are the rules to define your
key or variables. Now

00:02:58.400
00:03:00.800
let me explain them with the help of
your

00:03:02.400
00:03:06.800
Playbook, let me log in with my
ansible controller.

00:03:06.800
00:03:08.800
[no audio]

00:03:08.900
00:03:10.800
So, this is my ansible controller.
00:03:11.600
00:03:17.200
Let me define simply working with
vars.yml

00:03:17.600
00:03:22.500
so we have to start with the three
hyphens then enter

00:03:22.600
00:03:26.400
next line space - then play, right?

00:03:26.600
00:03:29.500
So, for our play we should have two
things minimum.

00:03:30.200
00:03:33.600
Those are targets and tasks.

00:03:34.700
00:03:38.500
So, targets as of now, I am taking
localhost and a task,

00:03:38.500
00:03:39.500
maybe one or more.

00:03:39.500
00:03:42.600
That's why I had to write under tasks
the first task

00:03:43.300
00:03:48.500
then second task something like that
right, fine.

00:03:49.100
00:03:51.000
So now first, let me delete your tasks.

00:03:51.600
00:03:55.700
So, first of all, simply our Playbook
should have one play

00:03:55.700
00:03:59.900
and each player should have minimum
target and tasks section.

00:04:00.800
00:04:04.200
Now we want to define our variables
custom variables whenever

00:04:04.200
00:04:06.600
if you want to define your variables,
you have to include

00:04:06.600
00:04:10.400
one more section called vars so under
vars,

00:04:10.400
00:04:12.200
you have to define your variables.
00:04:12.500
00:04:15.600
Let's say I want to define x as some
number.

00:04:18.100
00:04:21.800
Now, I define one variable called x
with value as 23.

00:04:22.600
00:04:26.899
So, we define that. Now I want to
display that a defined value

00:04:27.100
00:04:28.900
then under tasks section.

00:04:28.900
00:04:30.200
You have to use debug module.

00:04:30.200
00:04:33.700
If you remember from our previous
video, we know that we

00:04:33.700
00:04:38.100
have a debug module to display
variable values or message.

00:04:38.800
00:04:42.100
Now, simply variable equals 2x.

00:04:43.000
00:04:45.400
Right now, see the result I am

00:04:47.800
00:04:50.900
running this ansible Playbook.

00:04:50.900
00:04:52.700
Simply your playbook.

00:04:52.700
00:04:57.900
[no audio]

00:04:57.900
00:05:02.700
Yes, x value 23 or getting so here if
you don't want to display

00:05:02.700
00:05:06.100
This. I mean do if you don't want to
execute this Gathering

00:05:06.100
00:05:10.400
facts, you can also include, this is
optional guys.

00:05:10.700
00:05:16.900
You can include a section called
gather_facts: false.

00:05:18.600
00:05:19.600
Now see the result.
00:05:22.900
00:05:24.500
The red lead is executing your task.

00:05:24.500
00:05:26.300
Now this Gathering facts is skipping.

00:05:26.300
00:05:29.100
It is not executing because we
mentioned that don't execute

00:05:29.100
00:05:33.500
that, by writing simply gather facts as
false.

00:05:34.900
00:05:35.500
That's fine.

00:05:35.800
00:05:41.500
Now see, you know in your debug
module you can write in one

00:05:41.500
00:05:42.400
line in this way.

00:05:42.500
00:05:44.800
And if you want to write in the next line
you have to write

00:05:45.800
00:05:46.900
under debug.

00:05:47.300
00:05:50.000
var colon x not equal to x

00:05:50.000
00:05:52.900
If you are writing in the same line
where your debug module

00:05:52.900
00:05:57.600
is there then here, you can write very
close to x, but here

00:05:57.600
00:05:59.700
you have to write var colon x

00:05:59.700
00:06:03.000
This is going to display your variable
value. Now let me

00:06:03.000
00:06:06.300
save this and let me run it and see the
result.

00:06:07.900
00:06:09.800
Simply displaying your x value.

00:06:10.500
00:06:13.100
Let me define some multiple variable
values.
00:06:13.500
00:06:17.200
Let's say x value and suppose I am
taking my number.

00:06:17.600
00:06:23.500
Let's say some 45.67 then I am taking
my name suppose.

00:06:23.500
00:06:30.000
[no audio]

00:06:30.000
00:06:32.600
Right and I'm writing one more thing
called

00:06:34.300
00:06:38.800
my boolean, let's say my be
something variable name.

00:06:38.800
00:06:41.100
I am taking our key name and taking
my be but I am writing

00:06:41.100
00:06:43.900
data as let's say false.

00:06:43.900
00:06:45.900
[no audio]

00:06:46.100
00:06:47.400
Okay, fine.

00:06:48.200
00:06:50.600
Now I want to display all these
variables.

00:06:50.700
00:06:54.000
Let me go with the message
parameter because with message

00:06:54.000
00:06:57.200
we can display any number of
messages.

00:06:57.700
00:06:59.300
So first message, I am writing.

00:07:01.300
00:07:06.000
The value of x is so with curly brace.

00:07:07.100
00:07:11.800
You have to write then next line the
value of.

00:07:13.300
00:07:14.600
I'm writing my number.
00:07:17.700
00:07:22.400
let's say my_num: likewise, you can
display

00:07:22.400
00:07:23.900
your remaining values also.

00:07:25.000
00:07:28.700
Let me write them because I have
some extra point for that.

00:07:28.700
00:07:29.400
I am writing this.

00:07:31.100
00:07:37.300
"The value of my_name : }"

00:07:37.300
00:07:39.300
[no audio]

00:07:39.900
00:07:41.500
Then let me write one more thing.

00:07:42.900
00:07:55.100
The value of my_b is: }" Let me save it
and run it so before

00:07:55.100
00:07:57.200
running just see your playbook ones.

00:07:57.200
00:07:59.150
[no audio]

00:07:59.150
00:08:01.900
Now I'm running that see the result,
what you are getting

00:08:02.300
00:08:05.400
Value of x 23 you're getting your
values.

00:08:05.400
00:08:07.400
[no audio]

00:08:08.400
00:08:09.200
See that here.

00:08:09.200
00:08:11.800
I have written false small letters.

00:08:11.800
00:08:13.700
But here you are getting capital False.

00:08:14.600
00:08:16.000
There is no change.

00:08:16.800
00:08:20.000
I mean even though if the letter is
capital, the meaning is
00:08:20.000
00:08:23.600
same this is and this and this both are
equal false and false.

00:08:23.600
00:08:25.400
[no audio]

00:08:25.400
00:08:28.700
So, first of all, we know that how to
define your variables

00:08:28.900
00:08:33.000
with the help of vars section, then how
to display your variables

00:08:33.700
00:08:35.100
with the help of debug module.

00:08:35.700
00:08:41.799
Now the thing is Data types, what data
you store in your x.

00:08:41.799
00:08:44.600
What type of data you store in my
number?

00:08:44.799
00:08:46.799
What type of data you store in my
name?

00:08:46.900
00:08:48.799
What type of data you store in my be?

00:08:49.500
00:08:53.500
I want to know that. We know that this
is a integer and this

00:08:53.500
00:08:57.100
is a float point and this is actually a
Boolean data and

00:08:57.100
00:08:59.400
this is a string or ansible unique code.

00:09:01.300
00:09:01.700
Right.

00:09:01.700
00:09:04.600
Let me print them so that I can
understand.

00:09:05.600
00:09:07.200
See guys be clear.

00:09:07.200
00:09:12.600
What I am doing is, the value of x is
and type.
00:09:12.600
00:09:13.200
I am printing.

00:09:13.200
00:09:16.100
So, if you want to print a type, you
have to write }"

00:09:18.600
00:09:19.400
So, what is this?

00:09:19.400
00:09:22.600
We will see later for timing just
understand.

00:09:22.600
00:09:24.000
Just remember the syntax.

00:09:25.400
00:09:39.400
and type is your variable | type_debug
be clear and

00:09:40.000
00:09:50.300
type : }"

00:09:50.300
00:10:00.100
The last one and type is so simply
your variable

00:10:01.000
00:10:05.100
type :} let me run this and see the
result.

00:10:05.100
00:10:08.800
[no audio]

00:10:08.800
00:10:11.400
So, this is your playbook and I'm
running that.

00:10:13.100
00:10:19.700
See 23 you are getting as integer
45.67 float.

00:10:20.200
00:10:25.000
So, this is You're getting as ansible
Unicode are there is

00:10:25.000
00:10:30.100
a string. So I have done inside of
quotations, right and here

00:10:30.100
00:10:33.100
false. I have written for my b right?
See that data is my

00:10:33.100
00:10:35.600
false and type is Boolean.
00:10:36.000
00:10:39.700
So, whether you write here a small
false

00:10:39.700
00:10:41.700
or capital letters false see that?

00:10:41.800
00:10:43.100
What I am writing is next time.

00:10:43.100
00:10:46.200
I'm writing any value we have seen
about Falls right?

00:10:47.100
00:10:50.900
Let me write simply capital F false and
see the result.

00:10:50.900
00:10:52.900
[no audio]

00:10:53.900
00:11:00.200
False and Boolean. Not only that, let
me write one more thing no

00:11:00.900
00:11:03.700
No, no is also a Boolean.

00:11:05.200
00:11:09.800
See the difference. Boolean no you're
getting false, even

00:11:09.800
00:11:13.900
though if you write a data as no, but
while displaying it

00:11:13.900
00:11:20.000
is displaying as false and that is
Boolean. Same way yes or

00:11:20.000
00:11:21.200
two or also boolean.

00:11:26.000
00:11:30.000
Yes, even you can write to true but is
also a Boolean data

00:11:30.700
00:11:31.300
see I have written.

00:11:31.300
00:11:34.100
Yes, but see the output what you are
getting.

00:11:34.100
00:11:36.100
[no audio]
00:11:37.900
00:11:41.700
Boolean irrigating true right now. See
that.

00:11:41.700
00:11:46.400
What I am doing is for this my name I
am removing quotations.

00:11:46.400
00:11:48.400
[no audio]

00:11:52.400
00:11:56.800
See the result you're getting ansible
Unicode only whether

00:11:56.800
00:11:58.800
you have quotations or not, but you
are getting that as a

00:11:58.800
00:12:00.600
string only now.

00:12:00.600
00:12:02.600
Let me write a small note on this.

00:12:02.600
00:12:10.500
[no audio]

00:12:10.500
00:12:14.400
See, you know how to store a variable
value, right?

00:12:14.800
00:12:16.000
So, to define,

00:12:16.000
00:12:18.000
[no audio]

00:12:18.900
00:12:23.100
variable we have a vast section in
your playbook.

00:12:23.400
00:12:24.500
So, under vars section.

00:12:24.500
00:12:26.700
We are writing x some number.

00:12:27.800
00:12:32.300
Now we have different types of datas
or simply data types.

00:12:33.100
00:12:36.100
So, this is based on what type of data
you're storing into

00:12:36.100
00:12:38.700
your key or variable, right?
00:12:38.700
00:12:41.400
So, there is a integer, you know how
to represent integer,

00:12:41.400
00:12:45.500
simply x some number then float.

00:12:46.400
00:12:53.200
So, example simply was some 4.56
Then string let me take strings ()

00:12:53.200
00:13:00.100
[correction]

00:13:00.100
00:13:01.800
So how you can represent a string
simply.

00:13:01.800
00:13:06.500
I am taking (my_name: narendra
kumar or my_name)

00:13:06.500
00:13:08.600
Or you can also define

00:13:08.600
00:13:10.600
[no audio]

00:13:13.400
00:13:21.500
my_name: in quotations also you can
represent. But be

00:13:21.500
00:13:28.200
clear with the Boolean. Suppose if I
write something (x:

00:13:28.200
00:13:36.700
true|false|True|False|yes|no

00:13:36.700
00:13:39.600
These all are booleans.

00:13:39.600
00:13:42.100
[no audio]

00:13:42.100
00:13:44.200
I mean you have to write x equals
true.

00:13:45.800
00:13:54.100
y: false, z: True, p: False,

00:13:54.100
00:14:01.300
So all our Boolean type of datas, let's
say some q: yes, r: no)

00:14:06.400
00:14:11.300
Something like that, but same data, if
you write inside of
00:14:11.300
00:14:14.600
quotation, then this will become your
ansible Unicode.

00:14:14.700
00:14:15.600
Let me show you that.

00:14:15.600
00:14:17.600
[no audio]

00:14:18.800
00:14:22.300
See last one by default we are having
yes, but whenever if

00:14:22.300
00:14:27.800
you write yes in quotations, then see
the data

00:14:27.800
00:14:32.200
what you are getting? Yes, actually
yes is a Boolean type, but

00:14:32.200
00:14:36.500
you are getting ansible Unicode or
string. Reason is if we

00:14:36.500
00:14:39.300
have written that yes inside of
quotations.

00:14:40.100
00:14:43.700
So generally, if it is a string just fight
inside of quotation,

00:14:43.700
00:14:46.300
but if it is a Boolean don't write inside
of a quotation.

00:14:46.700
00:14:50.400
That's it, but even for strings, you don't
need to mention quotations,

00:14:50.800
00:14:53.200
but this type of data if we have
suppose.

00:14:53.200
00:14:56.200
Yes, I want to take it as a string then
write in quotations.

00:14:56.600
00:14:57.100
That's it.

00:14:57.400
00:14:58.300
So, by default.

00:14:58.300
00:14:59.800
Yes, no false true.
00:14:59.900
00:15:02.800
They are Boolean data's if you want to
convert that into

00:15:02.800
00:15:04.800
string then right inside of quotations.

00:15:04.800
00:15:05.200
That's it.

00:15:05.800
00:15:07.900
[no audio]

00:15:07.900
00:15:11.100
Okay guys, this is all about simply
custom variables.

00:15:12.200
00:15:12.600
Okay.

00:15:12.700
00:15:18.700
Thank you.
Transcript
00:00:00.000
00:00:01.700
Prince here

00:00:01.700
00:00:04.700
we are discussing about Ansible data
structures.

00:00:04.700
00:00:06.600
[no audio]

00:00:06.600
00:00:10.500
Let me go with that see data
structures is also called as

00:00:10.500
00:00:11.500
data collections.

00:00:12.200
00:00:15.500
So, data structures or data collections
or useful to store

00:00:15.500
00:00:17.900
multiple values or multiple data.

00:00:17.900
00:00:19.400
[no audio]

00:00:19.400
00:00:19.600
See already.
00:00:19.600
00:00:25.000
We know we have a scalar to store
single value, right?

00:00:25.400
00:00:27.800
Let me open your ansible controller.

00:00:30.500
00:00:33.400
Let me read a Ansible play book
called data structures.

00:00:33.400
00:00:36.110
[no audio]

00:00:36.100
00:00:41.100
And I am defining here simply Target
as my Local Host.

00:00:41.800
00:00:44.100
Then under vars section.

00:00:44.200
00:00:47.800
I am defining a single variable called x
with some value

00:00:47.800
00:00:52.400
34 and I want to display the value of
that defined variable.

00:00:52.400
00:00:55.500
Then I am taking a task with the
debug module and with the

00:00:55.500
00:00:57.900
parameter as var = x.

00:00:57.900
00:01:00.210
[no audio]

00:01:00.200
00:01:01.500
Right and one more thing.

00:01:01.500
00:01:04.400
I don't want to gather facts then.

00:01:04.400
00:01:06.200
Let me disable that.

00:01:07.500
00:01:10.300
Gather_facts : false.

00:01:11.000
00:01:15.700
Now, simply run your playbook ones
Ansible life and Playbook

00:01:15.700
00:01:17.900
data structures see the result.
00:01:19.100
00:01:23.500
So, if you observe this Playbook here,
we have taken one variable

00:01:23.500
00:01:28.200
called X and we stored the value 34
into that X and this

00:01:28.200
00:01:32.300
representation is called key value pair
representation or

00:01:32.400
00:01:33.800
simply a scalar.

00:01:34.400
00:01:38.300
So, scalar data structure is able to
store only one value.

00:01:39.700
00:01:42.600
Now, sometimes I want to store
multiple values.

00:01:43.800
00:01:47.600
In a single variable called X then how
we can store that

00:01:48.400
00:01:54.700
by using a data structure called a
sequence or a list and

00:01:54.700
00:01:56.800
for that you have to use square
brackets.

00:01:57.100
00:01:58.600
We are also having one more way.

00:01:58.600
00:02:02.000
I will show you while writing your
playbook see that suppose

00:02:02.000
00:02:05.800
just assume that I want to install
multiple packages like

00:02:05.800
00:02:11.500
VIM, Nano editor somenginx, some
httpd, right then

00:02:11.500
00:02:14.400
what I will do is first of all, I will store
all these values

00:02:14.400
00:02:15.300
into one variable.
00:02:16.100
00:02:18.900
Let me open your say now.

00:02:19.100
00:02:21.600
What I am doing is I am going to
Define one more variable

00:02:21.600
00:02:23.100
called packages.

00:02:24.300
00:02:28.800
So now suppose I want to install on
my notes some VIM, some

00:02:28.800
00:02:33.700
Nano editors, just Egyptian some
MySQL server some httpd some

00:02:33.700
00:02:34.500
nginx.

00:02:35.800
00:02:37.900
I don't want to take separate variables
for each and every

00:02:37.900
00:02:41.600
package. I am storing now all the
packages into one variable

00:02:41.600
00:02:42.500
called packages.

00:02:42.500
00:02:44.910
[no audio]

00:02:44.900
00:02:48.900
Right now, see first let me display the
output of this packages.

00:02:49.400
00:02:51.500
What is the output?

00:02:51.500
00:02:52.300
What is the value?

00:02:52.300
00:02:54.700
What are the values stored in your
packages variable?

00:02:56.800
00:02:57.900
See that now.

00:02:57.900
00:03:02.000
Let me run this your playbook and see
the result see in your

00:03:02.000
00:03:05.700
packages. You are having VIM, Nano,
httpd, nginx, see the
00:03:05.700
00:03:10.000
output with square brackets and this is
called sequence or

00:03:10.000
00:03:10.700
a list.

00:03:11.700
00:03:14.000
So, if you know python you can very
easily understand by seeing

00:03:14.000
00:03:19.600
this information because exactly a list
is equal to sequence

00:03:19.600
00:03:21.600
in your email or ansible Playbook.

00:03:22.600
00:03:24.100
Now, let me open once again.

00:03:25.200
00:03:29.300
See, I have written here packages in
square brackets, right?

00:03:29.400
00:03:30.600
Let me comment this.

00:03:31.000
00:03:34.401
And now I am defining simply

00:03:34.401
00:03:53.600
Pakgs: - ‘vim’ - ‘nana’ -‘httpd’ -‘nginx’,
that’s it

00:03:54.400
00:03:58.500
See whether you are going to use this
representation or this

00:03:58.500
00:04:02.600
representation. Both are same for you
to represent sequence

00:04:02.600
00:04:06.700
of values or list of values now variable
name is packages

00:04:06.700
00:04:10.500
under that we have all these four
values now we commented

00:04:10.500
00:04:13.700
this now the thing is we are displaying
these values with

00:04:13.700
00:04:14.900
the help of this packages
00:04:17.200
00:04:18.300
see your playbook.

00:04:18.500
00:04:18.600
Now,

00:04:18.600
00:04:20.600
I'm running that, see the output.

00:04:20.600
00:04:24.200
Is there any change while display
whether you are going to

00:04:24.200
00:04:29.100
Define your sequence or list in this
way or where is your

00:04:29.100
00:04:29.700
first one?

00:04:30.900
00:04:32.800
Anyway, in your playbook you have
that right?

00:04:34.600
00:04:37.300
Yeah, this one whether you are going
to use this one.

00:04:39.000
00:04:41.400
Or this one the output is same.

00:04:41.400
00:04:43.810
[no audio]

00:04:43.800
00:04:45.400
That means both are valid ones.

00:04:45.400
00:04:48.600
You can follow either this syntax or
this syntax to write

00:04:48.600
00:04:52.100
to store multiple values in a single
variable and this is

00:04:52.100
00:04:55.200
Simply called a sequence or list.

00:04:56.400
00:05:00.200
No, we are having one more row data
structure.

00:05:00.200
00:05:01.300
That is called dictionary.

00:05:01.500
00:05:03.500
Let me open your data structure.
00:05:04.200
00:05:08.600
And now what I am doing is see I am
taking suppose variable

00:05:08.600
00:05:17.300
name as web servers see sometimes
based on your operating

00:05:17.300
00:05:19.900
system. You need to select package
name different suppose

00:05:19.900
00:05:22.500
if I go with the line X I can install with.

00:05:22.500
00:05:25.010
[no audio]

00:05:25.000
00:05:30.900
Httpd right if I go with Ubuntu then
how to go with apache2.

00:05:30.900
00:05:32.659
[no audio]

00:05:32.650
00:05:32.900
That's it.

00:05:32.900
00:05:34.500
[no audio]

00:05:34.500
00:05:35.800
Now based on your operating system.

00:05:35.800
00:05:39.700
I have given my package name see
first of all, this is your

00:05:39.900
00:05:43.700
variable and I have written some data
inside of curly braces.

00:05:43.700
00:05:47.200
This is called dictionary or map in
Python.

00:05:47.200
00:05:48.100
This is called dictionary.

00:05:48.100
00:05:50.100
Whereas in ml or a School playbook.

00:05:50.100
00:05:51.200
This is called map.

00:05:52.300
00:05:52.900
This is a key.

00:05:52.900
00:05:53.800
And this is a value.
00:05:53.800
00:05:54.400
This is a key.

00:05:54.400
00:05:56.600
And this is a value for these wires.

00:05:56.600
00:05:58.800
I want to install http for this way.

00:05:58.800
00:06:00.100
I want to install apache2.

00:06:01.900
00:06:06.700
Right now, see that I am taking web
servers.

00:06:06.700
00:06:09.110
[no audio]

00:06:09.100
00:06:11.800
Yeah, I miss somewhere one more
single quotation.

00:06:11.800
00:06:19.210
[no audio]

00:06:19.200
00:06:20.000
Now, it's fine.

00:06:21.000
00:06:24.700
I'll just let me open your playbook
ones and let me run that

00:06:24.700
00:06:25.600
play book ones.

00:06:26.800
00:06:27.500
See the output.

00:06:27.500
00:06:29.250
[no audio]

00:06:29.250
00:06:32.900
So, web servers is the variable and I
am trying to print that

00:06:32.900
00:06:35.800
variable and how the output you're
getting inside of that

00:06:35.800
00:06:38.000
web server with curly braces.

00:06:38.300
00:06:42.000
You're getting your values key value
pair representation.

00:06:43.500
00:06:47.500
Let me modify this you can also write
this variable in this
00:06:47.500
00:06:56.600
way. first of all, web servers as you
are variable and inside

00:06:56.600
00:07:02.600
that you are having be clear.

00:07:03.800
00:07:04.300
In this way.

00:07:04.300
00:07:06.800
Also, you can Define your map or
dictionary.

00:07:06.800
00:07:11.110
[no audio]

00:07:11.100
00:07:13.400
That's it now sees the result.

00:07:13.400
00:07:15.400
New Text

00:07:15.400
00:07:18.110
[no audio]

00:07:18.100
00:07:20.400
Why you're getting same output
whether you're going to Define

00:07:20.400
00:07:25.100
in this way with curly braces or your
variable under that

00:07:25.500
00:07:29.600
with space then your key and your
value key and value now

00:07:29.600
00:07:33.700
these two key values or these two
scalars or they're under

00:07:33.700
00:07:35.400
this variable web servers.

00:07:36.000
00:07:36.500
That's it.

00:07:36.500
00:07:39.409
[no audio]

00:07:39.400
00:07:42.200
So that these are the different data
structures.

00:07:42.200
00:07:43.400
Simply one is scalar.
00:07:43.400
00:07:46.000
Second one is sequence Or List third
one is dictionary or

00:07:46.000
00:07:52.000
map. No, let me open your data A
playbook ones.

00:07:52.000
00:07:59.510
[no audio]

00:07:59.500
00:08:03.000
Now here what I am doing is suppose
I am taking packages.

00:08:03.600
00:08:06.500
So, if we take packages it is going to
display all packages.

00:08:06.600
00:08:09.200
I mean all the values which are there
under your packages?

00:08:09.200
00:08:11.210
[no audio]

00:08:11.200
00:08:13.200
We know that already we executed
that right?

00:08:13.200
00:08:15.110
[no audio]

00:08:15.100
00:08:17.300
But I want to print the first value which
is there in your

00:08:17.300
00:08:18.400
packages variable.

00:08:18.500
00:08:23.900
Then you have to take index values
see here or here you can

00:08:23.900
00:08:25.800
go with index position V.

00:08:25.800
00:08:29.700
I am either in this representation or in
this representation.

00:08:29.800
00:08:33.600
That is an index 0 then this is at index
1 and x 2 and x

00:08:33.600
00:08:38.900
3 so 0 1 2 and this is 3 now.
00:08:38.900
00:08:41.799
Let me print with square brackets
packages.

00:08:41.799
00:08:43.299
I don't want to print all the values.

00:08:43.299
00:08:44.600
I want to print only first value.

00:08:45.100
00:08:49.000
Then 0 likewise, you can print the
remaining values as well.

00:08:49.200
00:08:51.600
See the output now you are getting
only V.

00:08:51.600
00:08:54.400
I am because you are printing from
your variable index zero

00:08:54.400
00:08:58.800
value index zero value means first
value index 1 index to

00:08:58.800
00:09:00.000
index 3, that's it.

00:09:01.500
00:09:04.300
Now, let me open once again, and I
want to work with now

00:09:04.300
00:09:05.500
Maps or dictionaries.

00:09:05.500
00:09:08.610
[no audio]

00:09:08.600
00:09:11.500
See your map or dictionary name is
web servers.

00:09:11.500
00:09:13.310
[no audio]

00:09:13.300
00:09:15.800
So, if you go in this way, you're going
to get all the values,

00:09:15.800
00:09:23.200
right? Now I want to see what only
keys inside of your web

00:09:23.200
00:09:28.300
servers map Linux and open to only I
want to see then see
00:09:28.300
00:09:32.600
that. You can do simply dot Keys
operation.

00:09:32.700
00:09:35.600
This is python operation dot keys.

00:09:36.600
00:09:40.200
Now see the result you're going to get
only Linux on open

00:09:40.200
00:09:45.500
to now instead of displaying in this
way or instead of getting

00:09:45.500
00:09:46.500
only keys.

00:09:46.600
00:09:50.900
I want to display from web servers the
Linux key value that

00:09:50.900
00:09:53.500
is httpd now see the result.

00:09:53.500
00:09:55.500
I mean the way how you are going to
work.

00:09:56.500
00:10:01.000
So, from web server�s square
brackets if Linux key is there

00:10:01.000
00:10:03.600
I want to display the value of that line
X key.

00:10:04.100
00:10:04.600
That's it.

00:10:04.600
00:10:07.410
[no audio]

00:10:07.400
00:10:10.400
Now see the output if I run our
Playbook what you're getting

00:10:10.400
00:10:11.400
you're getting httpd.

00:10:11.400
00:10:15.700
What is this httpd from web servers
the key for Linux.

00:10:16.200
00:10:19.300
Sorry the value of this Lennox key is
httpd.
00:10:20.000
00:10:20.500
That's it.

00:10:21.900
00:10:25.200
You can go in this way, or you have
one more syntax that

00:10:25.200
00:10:26.000
is called.

00:10:26.000
00:10:29.610
[no audio]

00:10:29.600
00:10:34.800
dot get not get now parentheses
previously square brackets

00:10:34.800
00:10:38.700
now parentheses, Lennox That's it.

00:10:38.700
00:10:43.210
[no audio]

00:10:43.200
00:10:44.600
So, you are getting same output.

00:10:44.600
00:10:46.710
[no audio]

00:10:46.700
00:10:47.100
Right.

00:10:47.400
00:10:51.900
So, these are the different data
structures and how to use

00:10:51.900
00:10:54.700
or how to get your values from your
data structures.

00:10:54.700
00:10:58.410
[no audio]

00:10:58.400
00:11:02.800
right So guys well going forward we
will use in different

00:11:02.800
00:11:04.800
places or different data structures.

00:11:04.800
00:11:07.600
Sometimes we use sequence or
sometimes we use map.

00:11:07.600
00:11:11.000
Sometimes we use simply scalar So
based on situation, you
00:11:11.000
00:11:13.800
can understand when you have to take
your different types

00:11:13.800
00:11:15.500
of data structures in your playbooks.

00:11:16.000
00:11:19.100
So, for time being just go through them
how we are going to

00:11:19.100
00:11:22.300
define a scale of how we are going to
define a sequence and

00:11:22.300
00:11:24.800
how we are getting a particular value
from your sequence

00:11:25.000
00:11:28.100
and how we are defining a map or
dictionary and how we are

00:11:28.100
00:11:31.000
getting the value from your map or
dictionary based

00:11:31.000
00:11:31.800
on keys.

00:11:31.800
00:11:33.510
[no audio]

00:11:33.500
00:11:33.700
Right.

00:11:34.600
00:11:35.000
Okay.

00:11:35.000
00:11:35.600
Okay guys.

00:11:35.600
00:11:36.900
Thank you for watching this video.
Transcript
00:00:00.000
00:00:01.200
Friends here.

00:00:01.200
00:00:04.900
We are discussing about the usage of
register and set fact

00:00:05.000
00:00:07.700
with the help of a simple Playbook that
Playbook is just

00:00:07.700
00:00:11.100
to find the bash version of all servers
first.

00:00:11.100
00:00:16.100
Let me go through what is register see
in your ansible playbook

00:00:16.100
00:00:19.100
whenever if you run any task with the
help of module that

00:00:19.100
00:00:22.300
module will return some output.
00:00:23.200
00:00:27.300
That output may be in the form of a
scalar or a sequence

00:00:27.300
00:00:31.300
or maybe map that I simply am saying
that ansible modules

00:00:31.600
00:00:33.700
normally returns a data structure.

00:00:35.400
00:00:40.300
That output we can store we can
register into a variable.

00:00:40.900
00:00:45.000
So how we can register so ansible
resistors are used to store

00:00:45.000
00:00:48.600
the output of a module into a variable
see first of all,

00:00:48.700
00:00:51.700
whenever if you run any task with the
help of a module in

00:00:51.700
00:00:55.000
your hands will play book that model
will return some output.

00:00:56.400
00:00:59.700
That model will return some data
structure that output we

00:00:59.700
00:01:06.099
can store into a variable by using
registers key and whatever

00:01:06.099
00:01:10.800
the output we stored into a variable
that variable we can

00:01:10.800
00:01:13.900
use in different scenarios like
conditional statements for

00:01:13.900
00:01:17.100
logging. I mean to debug the output,
right?

00:01:17.200
00:01:19.500
Let me explain this with a simple
Playbook.

00:01:20.300
00:01:22.300
Then we'll go with your set fact.
00:01:23.300
00:01:26.100
See, I'm going to write a simple
Playbook that Playbook is

00:01:26.100
00:01:29.400
just to find the bash version of my
localhost suppose.

00:01:29.400
00:01:31.260
[no audio]

00:01:31.250
00:01:33.300
Get bash version.

00:01:33.300
00:01:35.100
[no audio]

00:01:35.199
00:01:36.300
See I am taking.

00:01:36.300
00:01:39.710
[no audio]

00:01:39.700
00:01:41.600
We know that we have to start with
three hyphens.

00:01:41.600
00:01:43.900
Then Enter space - then first play.

00:01:43.900
00:01:49.200
We are going to write right so Target I
am taking as localhost

00:01:49.500
00:01:52.300
forget. We have to represent it with
the hosts then tasks

00:01:52.300
00:01:54.600
section. So, what is my task?

00:01:54.800
00:01:57.900
I need to execute bash iPhone version
command.

00:01:58.200
00:02:00.400
So, to execute your bash command.

00:02:00.400
00:02:02.100
I mean you're in it's like system
commands.

00:02:02.100
00:02:04.400
We have to use either shell or
Command Module.

00:02:04.800
00:02:07.300
I am using simply shell module here.
00:02:08.699
00:02:11.800
Let's say simply our Command is Bash
- iPhone version.

00:02:12.300
00:02:15.100
Let me save it and run it so be clear.

00:02:15.400
00:02:17.900
We have SIMPLE Playbook and guys.

00:02:17.900
00:02:19.900
Let me disable gather facts.

00:02:20.000
00:02:23.400
I don't want to fetch facts.

00:02:24.300
00:02:29.100
So, gather facts false or know you can
write.

00:02:30.500
00:02:34.600
Now simply I'm running ansible
Playbook see the output.

00:02:34.600
00:02:36.459
[no audio]

00:02:36.450
00:02:38.500
See it has been executed but there is
no output.

00:02:38.500
00:02:39.900
It is not displaying anything.

00:02:40.100
00:02:43.000
She'll change means it has been
executed whatever the task

00:02:43.000
00:02:46.100
you have given in the Shell module
that has been executed.

00:02:46.100
00:02:49.200
But what is the output actually it will
return the output

00:02:49.200
00:02:53.000
but you should be able to store that
into some variable now

00:02:53.000
00:02:56.900
to store that into some variable you
have to use a register

00:02:57.000
00:03:00.200
key and you have to provide any
variable here.
00:03:00.200
00:03:02.000
Let's say bash version variable.

00:03:02.000
00:03:07.600
I am giving be clear shell this is
Module and for register

00:03:07.700
00:03:10.700
for module and register you should
have same indentation.

00:03:10.700
00:03:12.659
[no audio]

00:03:12.649
00:03:16.000
See optionally you may have some
arguments for your some

00:03:16.000
00:03:17.300
parameters for your shell.

00:03:18.700
00:03:21.900
But this register whenever if you are
going to use register

00:03:21.900
00:03:26.900
for any module the space for your
module and for your register

00:03:26.900
00:03:29.600
key should be same that's fine.

00:03:29.600
00:03:31.359
[no audio]

00:03:31.350
00:03:33.000
Now this is your simple Playbook.

00:03:33.000
00:03:36.000
Now, I am running that but still there is
no output.

00:03:37.000
00:03:41.700
Now, what we done is we have been
executed this command with the

00:03:41.700
00:03:45.000
help of shell module and it is getting

00:03:45.000
00:03:47.800
some output, that output we store into
this variable with

00:03:47.800
00:03:51.700
the help of this register key, but I want
to see that output
00:03:51.700
00:03:55.400
then if you want to display the output,
we have to use debug

00:03:55.400
00:03:58.100
module. We have to write one more
task.

00:03:58.600
00:03:59.700
See for each module.

00:03:59.700
00:04:01.400
There should be a separate task.

00:04:01.400
00:04:04.500
You cannot club two modules under
one task.

00:04:04.500
00:04:10.277
Now, I am writing debug module
simply very close to bash_ver

00:04:11.899
00:04:12.900
Now see the output.

00:04:13.100
00:04:16.300
So, before that first see your code and
I am running that

00:04:16.300
00:04:18.810
[no audio]

00:04:18.800
00:04:21.500
You are getting our output see that
there are different.

00:04:21.600
00:04:23.200
First of all, see the bash_version.

00:04:23.200
00:04:25.100
This is the variable in this variable.

00:04:25.100
00:04:28.300
We stored our output of your
bash_version and if

00:04:28.300
00:04:30.200
you observe that, that is a map.

00:04:30.800
00:04:34.400
That's why we are saying that
whenever if you run ansible

00:04:34.400
00:04:37.700
modules it is giving some it is
threatening some data structure
00:04:38.000
00:04:40.100
now see that this is the map or
dictionary.

00:04:41.600
00:04:44.700
In this we have different parameters,
like see that ansible

00:04:44.700
00:04:48.800
facts. So that is you discovered a
python location change

00:04:48.800
00:04:50.700
your true means your task has been
executed.

00:04:50.700
00:04:51.600
What is the command?

00:04:51.800
00:04:54.400
What is the time it has taken right or is
the end of time.

00:04:55.400
00:05:00.200
Failed? No, false written code zero
means success start time

00:05:00.200
00:05:02.600
end time right STD error.

00:05:02.600
00:05:05.600
There is no error. STD line, STD error
line.

00:05:05.600
00:05:08.800
There are no errors. STD out.

00:05:09.000
00:05:10.100
This is your output.

00:05:11.300
00:05:14.300
And this output in terms of line-by-line.

00:05:14.300
00:05:18.400
This is the output now; I don't want to
display all these

00:05:18.400
00:05:22.700
things. I want display simply STD
outlines or STD out that

00:05:22.700
00:05:23.400
is your wish.

00:05:24.500
00:05:27.300
So, for time being I'm taking STD out
because I want to explain
00:05:27.300
00:05:33.100
something. See now from your
bash_version

00:05:33.100
00:05:35.400
I want to display only STD out.

00:05:35.500
00:05:39.300
So simply your variable dot your
required value from your

00:05:39.300
00:05:41.100
output, STD out.

00:05:41.700
00:05:42.300
See you guys.

00:05:42.800
00:05:45.600
If you observe here, this is Bash
version in that we have

00:05:45.600
00:05:52.200
these are the keys. I can use .get. See
if

00:05:52.200
00:05:55.400
it is a out bash_version is the variable
I can

00:05:55.400
00:05:57.600
use dot get STD out.

00:05:57.600
00:05:59.310
[no audio]

00:05:59.300
00:06:05.100
Or I can use bash version in square
brackets STD out or simply

00:06:05.100
00:06:09.500
I can use bash_version.STDout all will
give

00:06:09.500
00:06:10.400
same output.

00:06:10.400
00:06:12.360
[no audio]

00:06:12.350
00:06:15.500
Right, so that's why I use here.

00:06:15.600
00:06:19.900
Simply your output variable.STD out
now.

00:06:19.900
00:06:23.200
Let me run this and see the output
what you are getting.
00:06:23.200
00:06:25.610
[no audio]

00:06:25.600
00:06:28.600
See that we are getting now only
output you are getting actually

00:06:28.600
00:06:31.400
different parameters in your data
structure in your output.

00:06:32.000
00:06:35.300
But I want to concentrate only on
output then I am getting

00:06:35.300
00:06:36.400
that output here.

00:06:37.100
00:06:39.100
But if you have this output, this is
entire thing is

00:06:39.100
00:06:42.600
a string and actually this string consist
of multiple lines.

00:06:42.600
00:06:46.400
See here /n somewhere slash n now.

00:06:46.400
00:06:50.300
I want to split this, I want to divide this
into number of

00:06:50.300
00:06:51.300
lines then

00:06:52.300
00:06:56.900
see the output STDout.split

00:06:56.900
00:07:02.100
operation in your python. So /n, based
on /n split my output.

00:07:02.100
00:07:04.050
[no audio]

00:07:04.050
00:07:04.900
Now, see the output.

00:07:06.400
00:07:08.100
You're getting in terms of lines.

00:07:08.300
00:07:11.900
Actually, this is what you are getting by
using your SGD

00:07:11.900
00:07:15.900
outlines, right. From this you are
getting this output.
00:07:15.900
00:07:17.610
[no audio]

00:07:17.600
00:07:21.100
With the help of your split operation
that will done by your

00:07:21.100
00:07:23.400
ansible. But here we are doing from
your STD out.

00:07:23.400
00:07:25.600
We are splitting the lines now.

00:07:25.600
00:07:29.400
If you have there in this entire output
our bash version

00:07:29.400
00:07:30.700
is there in very first line.

00:07:30.700
00:07:33.110
[no audio]

00:07:33.100
00:07:35.900
See, this is a list or sequence.

00:07:36.300
00:07:39.600
So, this is the first value this entire
thing is a first value

00:07:40.100
00:07:45.000
now from our
bash_version.STDout.split from that

00:07:45.000
00:07:51.200
I need first value, first line, first value
then index 0.

00:07:53.700
00:07:55.800
Guys, this is a list or sequence.

00:07:56.500
00:07:57.500
We need first value,

00:07:57.500
00:08:01.200
First of all is always index 0 that's why
I have given here

00:08:01.400
00:08:02.600
index 0

00:08:02.600
00:08:04.810
[no audio]

00:08:04.800
00:08:08.400
Now, let me run this play book and
see the output.
00:08:08.400
00:08:11.909
[no audio]

00:08:11.900
00:08:16.800
Now you're getting your output as only
first line, but in

00:08:16.800
00:08:22.960
this entire line, we need this value only
suppose 4.2.46

00:08:22.960
00:08:26.900
of something, some version we have
now, what I want

00:08:26.900
00:08:31.400
to do is first of all, I want to split this
based on space

00:08:31.500
00:08:35.900
and see the output. As I am doing so
many modifications here

00:08:35.900
00:08:39.200
be clear split based on space.

00:08:39.200
00:08:40.500
I am splitting the output.

00:08:40.500
00:08:43.110
[no audio]

00:08:43.100
00:08:45.299
See the result what you're getting.

00:08:45.299
00:08:47.610
[no audio]

00:08:47.600
00:08:51.600
Bash_version, right, this is my version.

00:08:52.299
00:08:54.000
Now you're watching is there.

00:08:55.500
00:08:59.900
0, 1, 2, 3, 4th line means index 3. 4th

00:09:00.600
00:09:08.100
value means index 3, let me take
index 3 now see the output.

00:09:08.100
00:09:10.910
[no audio]

00:09:10.900
00:09:12.600
Yes, you are getting your version.

00:09:13.900
00:09:16.100
That's fine. Now, Let me open.
00:09:16.100
00:09:16.600
Once again.

00:09:16.600
00:09:21.900
You are Playbook see suppose if I
want to use this version.

00:09:21.900
00:09:25.200
This entire thing is your version value
in different places.

00:09:25.400
00:09:27.900
Always I have to write this entire
syntax.

00:09:28.800
00:09:29.900
I don't want to write.

00:09:31.200
00:09:35.600
I want to create a new variable and
assign to and assign

00:09:35.600
00:09:37.200
this output into that variable.

00:09:37.800
00:09:39.600
Let's say, suppose

00:09:39.600
00:09:41.000
I am entering into my python.

00:09:41.400
00:09:45.200
So, I have X value for I have a value
as 6 and I need to

00:09:45.200
00:09:47.100
find out Z=X_Y.

00:09:47.300
00:09:51.700
So, what we are doing the expression
output X+Y output

00:09:51.700
00:09:56.100
we are storing into Z. Now assume
that this entire thing is

00:09:56.100
00:10:00.400
a like X + Y some operation. This
operation result is this

00:10:00.400
00:10:05.000
one. Now, I want to assign this entire
output into a some extra

00:10:05.000
00:10:06.800
variable into some new variable.
00:10:08.500
00:10:11.000
Right now, see how I'm going to do
that.

00:10:11.000
00:10:13.110
[no audio]

00:10:13.100
00:10:16.900
See we have a vast section here so
that we can define our

00:10:17.000
00:10:20.900
variables in your verse section.

00:10:20.900
00:10:24.810
[no audio]

00:10:24.800
00:10:27.600
Let me write that suppose if you want
to define any variables

00:10:27.600
00:10:31.200
already. We know that we can define a
verse here, but here

00:10:32.000
00:10:32.800
we don't know initially.

00:10:32.800
00:10:35.800
What is the variable we want to take
but after some time

00:10:35.800
00:10:39.100
after some because of some output
we are getting some variable,

00:10:39.800
00:10:44.300
right? So after some execution of
some tasks, you have a variable

00:10:44.400
00:10:48.100
and you need to define a new variable
here now to define

00:10:48.100
00:10:51.700
a new variable while writing your task
sections.

00:10:52.100
00:10:54.500
You have a module called set.

00:10:54.600
00:10:58.900
fact Set_fact.

00:10:59.200
00:11:02.400
So, the purpose of set fact is simply
just to create a new
00:11:02.400
00:11:03.500
variables. That's it.

00:11:04.400
00:11:10.681
Now I am taking simply Bash_version,

00:11:11.865
00:11:15.600
so simply this entire output I want to
store into.

00:11:15.600
00:11:17.350
[no audio]

00:11:17.350
00:11:21.600
So, you guys how I am storing be
clear.

00:11:22.000
00:11:25.600
So, let me take here single quotes
because there we have double

00:11:25.600
00:11:30.200
quotes. That's it.

00:11:31.200
00:11:36.500
So, guys how I did is first of all inside
of your quotations,

00:11:37.200
00:11:41.000
whatever the output you're expecting
by doing some modifications

00:11:41.300
00:11:45.300
that I have written here inside of curly
two curly braces.

00:11:45.700
00:11:48.100
Now, what will happen means just
assume that this is like

00:11:48.100
00:11:51.900
X + Y this Expressway result is
assigned to a new variable

00:11:51.900
00:11:54.510
called bash_version. That's it.

00:11:54.500
00:11:58.500
Now while displaying the output in
order to use this lengthy

00:11:58.500
00:12:01.100
variable. Simply you can write.

00:12:02.300
00:12:04.000
Bash_version, that's it.
00:12:05.900
00:12:08.400
Nothing, is there guys using set_fact
you can define a new

00:12:08.400
00:12:11.900
variable. So, we have some
expression that expression is giving

00:12:11.900
00:12:15.300
some output so that output we are
assigning to a new variable.

00:12:15.400
00:12:19.600
So, set_fact is always useful to define
a new variable.

00:12:19.700
00:12:22.100
You can hide any number of variables
here, see? Suppose

00:12:22.100
00:12:24.900
just I'm randomly, I'm writing my value.

00:12:24.900
00:12:27.610
[no audio]

00:12:27.600
00:12:29.900
Bash_version, that's it.

00:12:29.900
00:12:32.500
We can Define any number of
variables under your state fact

00:12:33.300
00:12:34.900
right now.

00:12:34.900
00:12:38.700
Let me save it and see your code first
and I'm going to run

00:12:38.700
00:12:42.500
that. See the output.

00:12:42.500
00:12:44.510
[no audio]

00:12:44.500
00:12:46.000
She simply are getting your version.

00:12:46.200
00:12:46.600
See now.

00:12:46.600
00:12:50.600
You're not getting here lengthy
variable because this entire

00:12:50.600
00:12:53.900
thing this entire output, we stored into
this variable and
00:12:53.900
00:12:56.100
we are using this variable to display
the output.

00:12:56.500
00:12:58.400
So, that is the use of set_fact.

00:12:58.800
00:13:01.600
So very very useful guys this set_fact
module.

00:13:01.900
00:13:06.500
So, simply set_fact module allows us
to define a new variable. That's it.

00:13:06.500
00:13:08.500
[no audio]

00:13:08.500
00:13:09.100
Okay guys.

00:13:09.100
00:13:10.500
Thank you for watching this video.
Transcript
00:00:00.000
00:00:01.600
Friends here

00:00:01.600
00:00:05.400
we are discussing about input and
outputs of ansible Playbook

00:00:05.400
00:00:09.800
or simply how to read and print a
variable value using your

00:00:09.800
00:00:10.800
ansible playbook.

00:00:11.600
00:00:17.300
See let me open My ansible Controller
first see already.

00:00:17.300
00:00:20.800
We know in your playbook how to
define a variable value and

00:00:20.800
00:00:23.700
how to display that let me show you
that first.

00:00:24.300
00:00:29.110
So simply input_outputs.yml.
00:00:29.110
00:00:31.900
See I'm writing a simple ansible
Playbook.

00:00:32.400
00:00:35.000
So, you have to write you have to start
with the three hyphens

00:00:35.000
00:00:38.200
then enter space - then Target.

00:00:38.600
00:00:43.200
So as of now I am taking Target as I
mean host as Local Host.

00:00:43.200
00:00:45.100
[no audio]

00:00:45.100
00:00:49.500
Now next thing is if you want to define
a variable, we have

00:00:49.500
00:00:54.300
a vast section simply bars then under
that you can define

00:00:54.400
00:00:58.000
any variable value like suppose X
some number or suppose

00:00:58.000
00:01:01.800
my name, I can define suppose
something called.

00:01:01.800
00:01:03.500
[no audio]

00:01:03.500
00:01:08.600
likewise, and if I want to display the
values, I have to use

00:01:08.600
00:01:10.300
debug module debug:

00:01:10.600
00:01:14.500
I can use a message parameter so
that I can display two variables

00:01:14.500
00:01:27.000
values. “the x value is: }”

00:01:27.300
00:01:35.600
the same way you can define the my
name

00:01:35.600
00:01:40.000
value “the my_name value is: }”
00:01:41.800
00:01:45.600
So, this is the way how we can directly
define a variable

00:01:45.600
00:01:48.900
value inside of your playbook and how
we can display that

00:01:48.900
00:01:49.800
using you are.

00:01:49.800
00:01:52.010
[no audio]

00:01:52.000
00:01:55.800
Ansible Playbook now, let me run this
and see the output

00:01:55.900
00:01:58.000
and I don't want to gather facts.

00:01:58.000
00:02:02.100
Let me disable that so that I can save
some time so simply

00:02:02.100
00:02:02.800
I am writing.

00:02:02.800
00:02:05.310
[no audio]

00:02:05.300
00:02:08.699
Gather facts, sometimes we need to
collect the facts.

00:02:08.699
00:02:12.300
So, at that time, we don't we want to
disable that as of now,

00:02:12.300
00:02:13.400
I don't want to collect.

00:02:13.500
00:02:14.700
That's why I'm writing.

00:02:15.300
00:02:17.200
I'm making it as a false.

00:02:17.200
00:02:19.200
[no audio]

00:02:19.200
00:02:22.100
Right now, see I am running our
ansible Playbook.

00:02:22.100
00:02:24.910
[no audio]

00:02:24.900
00:02:25.700
See the output.
00:02:26.200
00:02:31.000
Yes, you're getting your defined values
X value and you are

00:02:31.000
00:02:33.000
my name value you're getting now.

00:02:33.000
00:02:37.200
My requirement is I don't want to fix
the variable value

00:02:37.200
00:02:38.500
inside of your playbook.

00:02:39.500
00:02:40.700
While running my playbook.

00:02:40.700
00:02:44.800
I need to read the variable values then
see that how you

00:02:44.800
00:02:50.000
can read a variable value from your
while running your playbook

00:02:50.600
00:02:51.100
for that.

00:02:51.100
00:02:56.100
You have to include one more section
called vas from then

00:02:56.100
00:02:58.200
under that see suppose.

00:02:58.200
00:02:59.500
I want to read a variable.

00:02:59.600
00:03:04.100
Let's say my variable is suppose some
name or let's say some

00:03:04.500
00:03:09.370
y value then you have to write Name :
y

00:03:09.370
00:03:16.000
then prompt: so this prompt usage is
just to display

00:03:16.000
00:03:18.200
some essays on your command line
on you.

00:03:18.200
00:03:23.491
I mean, Iine on your playbook, enter
the value for Y.
00:03:23.491
00:03:25.400
That's it.

00:03:25.400
00:03:28.700
Now, let me save it and run it.

00:03:30.000
00:03:34.000
So, before that, this is your playbook
guys using vast section

00:03:34.000
00:03:37.100
directly can define your variables, but
if you want to read

00:03:37.100
00:03:40.300
a variable value while running your
playbook, you have to

00:03:40.300
00:03:43.900
include where's prompt section and
under that.

00:03:44.400
00:03:46.400
What is the variable value, variable
name

00:03:46.400
00:03:49.000
you want to take that you have to
represent with the name

00:03:49.000
00:03:52.000
key, name Y that is a variable.

00:03:52.200
00:03:55.400
So, inside that variable Y want to store
a value than simply

00:03:55.400
00:03:57.200
run your playbook and see the result.

00:03:58.200
00:04:00.000
Enter the value for Y suppose.

00:04:00.000
00:04:02.000
I'm entering some number called 46.

00:04:02.000
00:04:04.200
But anyway, it is not displaying while
typing.

00:04:05.600
00:04:09.700
But let me display that value so that
you can see what value

00:04:09.700
00:04:11.700
we are providing for your why.

00:04:11.700
00:04:13.300
[no audio]
00:04:13.399
00:04:23.800
see the value of Y is so if you don't
want to print X and

00:04:23.800
00:04:26.700
my name the defined variable you can
disable it, but I want

00:04:26.700
00:04:27.700
to keep it as it is.

00:04:27.700
00:04:29.510
[no audio]

00:04:29.500
00:04:35.300
now let me see your play book first
and I want to run that

00:04:35.300
00:04:38.900
Playbook. So, it is asking enter the
value for Y.

00:04:39.000
00:04:41.900
I'm entering suppose some number 56
see the result.

00:04:42.000
00:04:46.700
Yes, you are getting 56 but while
typing it is not displaying

00:04:46.700
00:04:49.000
here. That means by default.

00:04:49.000
00:04:52.400
This prompt is worse prompt is a
private section.

00:04:52.900
00:04:56.100
I mean, this is a prompt is private if
you don't want

00:04:56.100
00:05:01.900
to Hide the data while typing then you
have to add one more

00:05:02.300
00:05:04.800
key called private.

00:05:04.900
00:05:10.700
No or false you can take either no or
false now see that

00:05:10.800
00:05:12.800
I am running so before running.

00:05:12.800
00:05:16.110
[no audio]
00:05:16.100
00:05:17.100
Now, let me run it.

00:05:18.400
00:05:19.700
See guys here.

00:05:19.700
00:05:21.600
I have given private false.

00:05:21.600
00:05:24.200
That's why while typing your data.

00:05:24.200
00:05:27.600
It is displaying previously it is it is it
was not displaying

00:05:27.600
00:05:28.800
while typing your data here.

00:05:28.800
00:05:29.700
Now it is displaying.

00:05:29.800
00:05:30.300
That's it.

00:05:31.700
00:05:36.000
So, this is the way how we can read
any variable value from

00:05:36.000
00:05:38.200
your while running your ansible
playbook.

00:05:39.700
00:05:41.200
Right see suppose.

00:05:41.500
00:05:45.400
I want to read some username and
password while running my

00:05:45.400
00:05:50.600
Ansible play book then let me simply
open my existing

00:05:50.600
00:05:55.500
Playbook. So, see that what I am
doing is so guys whenever

00:05:55.500
00:05:59.100
if you want to read two variables two
variables then take

00:05:59.100
00:06:03.400
it as a sequence - name username.

00:06:03.400
00:06:06.400
I am taking then prompt.
00:06:08.500
00:06:19.900
enter your username Then private
know Falls are no both are

00:06:19.900
00:06:21.200
same then.

00:06:21.200
00:06:22.500
I want to read password as well.

00:06:22.500
00:06:25.200
Then there is the second variable then
use one more - then

00:06:25.200
00:06:38.200
name. password then prompt enter
your password.

00:06:38.200
00:06:40.210
[no audio]

00:06:40.200
00:06:45.300
So here private I want to I mean
wildest while typing my

00:06:45.300
00:06:46.700
password I don't want to display.

00:06:46.700
00:06:50.200
That's why I am not writing private as
no by default private

00:06:50.200
00:06:53.300
is yes if you want to write you can
write private.

00:06:54.100
00:06:58.100
Yes, Right now, let me remove all
these remaining things.

00:06:58.100
00:07:02.909
[no audio]

00:07:02.900
00:07:04.400
Now I am writing.

00:07:04.400
00:07:09.510
[no audio]

00:07:09.500
00:07:10.900
See the username.

00:07:10.900
00:07:12.860
[no audio]

00:07:12.850
00:07:13.700
It is so here.

00:07:13.700
00:07:15.200
I want to display the username.
00:07:15.200
00:07:17.610
[no audio]

00:07:17.600
00:07:21.200
And password just if you can case if
you want to display

00:07:21.200
00:07:25.300
the password value, then we're able
for password.

00:07:25.300
00:07:26.800
We have taken as password.

00:07:26.800
00:07:27.300
That's it.

00:07:28.500
00:07:30.800
Now, let me remove our section if you
want to keep it as

00:07:30.800
00:07:31.500
a vast section.

00:07:31.500
00:07:32.100
You can keep it.

00:07:32.100
00:07:34.300
No problem. Right.

00:07:34.700
00:07:38.000
Now, let me save it and run it before
going to run just to

00:07:38.000
00:07:39.400
see your hands will play book ones.

00:07:40.900
00:07:43.200
So, this is your ansible playbook now
here.

00:07:43.200
00:07:48.000
What I am doing is I want to read
username and password while

00:07:48.000
00:07:50.600
typing username on my command
line.

00:07:50.600
00:07:53.900
I want to display that's why how kept
here private value

00:07:53.900
00:07:55.400
as no but password.

00:07:55.400
00:07:57.900
I don't want to display while typing on
my command line.
00:07:58.200
00:08:00.800
That's why I hug you in private as yes
Anyway by default.

00:08:00.800
00:08:03.200
This is yes, you do need to mention,
but if you mention no

00:08:03.200
00:08:06.900
problem now, let me run it
Ansible_Playbook.

00:08:06.900
00:08:09.310
[no audio]

00:08:09.300
00:08:11.400
See that enter your username
suppose.

00:08:11.400
00:08:14.900
I am entering answered me enter your
password.

00:08:14.900
00:08:18.300
Actually, I'm entering and admin or the
right one two, three

00:08:18.700
00:08:22.900
see that it is not displaying while
typing because I have

00:08:22.900
00:08:24.200
given private as yes.

00:08:26.500
00:08:28.500
Now anyway forcefully here.

00:08:28.500
00:08:31.300
I am displaying my username and
password this you are getting

00:08:31.300
00:08:32.799
your username and password.

00:08:33.200
00:08:33.799
That's it.

00:08:34.299
00:08:38.000
So, there is this is the way how we
can read a variable or

00:08:38.000
00:08:41.700
multiple variables and we can display
the value simply input

00:08:41.700
00:08:43.799
and outputs of your ansible playbook.
00:08:44.900
00:08:48.600
Be clear if it is only one variable then
no need to mention

00:08:48.600
00:08:52.000
- if you want to read multiple variables,
it's better to

00:08:52.000
00:08:54.900
mention as a hyphen or sequence on
list of values.

00:08:56.500
00:08:59.700
So, this - represent one variable this -
represent one variable

00:09:00.100
00:09:01.300
and to read a variable.

00:09:01.300
00:09:05.600
We are having three parameters here
named prompt private.

00:09:07.100
00:09:07.500
Right.

00:09:07.900
00:09:12.500
So, this is the simple way to read a
variable values while

00:09:12.500
00:09:14.500
running your ansible playbooks.

00:09:15.300
00:09:15.700
Okay guys.

00:09:15.700
00:09:17.000
Thank you for watching this video.
Transcript
00:00:00.000
00:00:01.400
Friends here

00:00:01.400
00:00:04.700
we are discussing about how to read
variables from a file.

00:00:04.800
00:00:10.200
That means I will store my variables in
one file then using

00:00:10.200
00:00:10.800
play book.

00:00:10.800
00:00:14.300
I want to read them then how we can
read so before going

00:00:14.300
00:00:15.600
to discuss this concept.

00:00:15.600
00:00:18.900
First of all, we have different files to
store our variables

00:00:19.800
00:00:24.600
so, they are like, you know Yaml files
or Json files, of course,
00:00:24.700
00:00:27.400
our inventory file is also one of the
files to store some

00:00:27.400
00:00:30.200
variables, but there is a different story
will discuss about

00:00:30.200
00:00:30.900
that later.

00:00:31.400
00:00:35.200
So as of now, I am going to store my
variables inside of

00:00:35.300
00:00:37.300
Yaml file or Json files.

00:00:37.600
00:00:41.000
Then I am trying to read the variables
which are stored in

00:00:41.000
00:00:44.300
your Yaml files or Json files using our
Playbook.

00:00:45.000
00:00:47.600
Let me open my ansible Controller
here.

00:00:47.600
00:00:49.500
[no audio]

00:00:49.500
00:00:53.700
Let me write down Yaml file so
variables.

00:00:56.500
00:00:59.700
Variable values.Yaml.

00:01:00.600
00:01:04.800
So, if you want to store any variables
inside a separate am

00:01:04.800
00:01:07.600
L Phi, then you have to first of all you
have to start with

00:01:07.600
00:01:11.200
the hyphens then simply write your
variable suppose.

00:01:11.600
00:01:13.000
I want to define a scalar.

00:01:13.000
00:01:18.300
Let's say x values some value then I
want to define a sequence
00:01:18.300
00:01:23.700
or list then you can write some why
under why I want to store

00:01:23.700
00:01:25.300
suppose some number 4.

00:01:26.700
00:01:35.000
some 67, some ansible then I want to
define Yaml map variable

00:01:35.000
00:01:35.400
as well.

00:01:35.600
00:01:38.000
Let me Define that suppose.

00:01:38.100
00:01:39.200
I want to Define.

00:01:39.200
00:01:42.810
[no audio]

00:01:42.800
00:01:47.400
Any dictionary or map let's say I'm
going to store

00:01:47.400
00:01:49.300
it as packages.

00:01:50.300
00:01:54.400
So here I am writing suppose for Linux
package for Linux.

00:01:54.400
00:01:59.800
I want to take package suppose some
httpd then for Ubuntu.

00:01:59.800
00:02:04.100
I am taking package name as
Apache2, that's it.

00:02:04.700
00:02:09.600
Now, we have a separate file,
separate Yaml file where we stored

00:02:09.600
00:02:15.600
our variables. Now, I want to write a
play book and using that play book.

00:02:15.600
00:02:18.200
I want to read this variable values.
Now,

00:02:18.200
00:02:21.400
let me write read variables.

00:02:22.500
00:02:26.800
from files .yml.
00:02:27.700
00:02:31.900
So, first of all, let me take the file
name variable values.yml

00:02:31.900
00:02:33.700
[no audio]

00:02:33.750
00:02:35.100
Now I am writing a play book.

00:02:35.900
00:02:41.500
So, target I'am writing as of now
simply localhost then see

00:02:41.500
00:02:44.300
if you want to define variables directly
in your playbook

00:02:44.300
00:02:48.800
itself. We are using vars section, right
or if you want to

00:02:48.800
00:02:52.800
read your variables while running your
playbooks, then we

00:02:52.800
00:02:54.500
are using vars_prompt.

00:02:55.800
00:02:58.800
But here I want to read variables from
a file.

00:02:58.900
00:03:04.900
So, where's files then space just write
your file name then

00:03:04.900
00:03:09.600
write your tasks section and let me
display the any one of

00:03:09.600
00:03:13.600
the variable or all variables from your
variables.

00:03:14.900
00:03:18.800
Amal file so let me display simply this
variable package

00:03:18.800
00:03:25.100
is variable from that variables
values.yml, so so simply

00:03:25.100
00:03:29.200
I am writing vars=variable name,
which is there
00:03:29.200
00:03:31.400
in your variable values.yml file.

00:03:32.500
00:03:37.300
So, see that so this is the variable
which is there any were

00:03:38.300
00:03:41.200
this variable values.yml file that file.

00:03:41.200
00:03:42.800
I am including here.

00:03:43.000
00:03:45.900
I am calling that file to collect variables
which are there

00:03:45.900
00:03:49.000
in this file with the help of vars file
section.

00:03:49.900
00:03:53.600
Now in this variable values you have
different variables.

00:03:53.800
00:03:57.500
I am displaying one of the variables
like packages now.

00:03:57.500
00:03:59.800
Let me run your playbook.

00:04:01.400
00:04:02.300
See the output.

00:04:05.000
00:04:05.500
That's it.

00:04:05.600
00:04:06.900
See that packages.

00:04:06.900
00:04:10.600
Is there in this your variable
values.yml file and were

00:04:10.600
00:04:11.800
able to display that.

00:04:12.200
00:04:12.700
That's it.

00:04:12.800
00:04:16.600
This is the simple way to read your
variables using your

00:04:16.600
00:04:19.500
ansible from your ayml file.
00:04:20.399
00:04:23.408
Now the same way you can also
define some Json file.

00:04:23.399
00:04:24.300
In the Json file

00:04:24.300
00:04:25.500
can define variables.

00:04:25.700
00:04:26.600
Let me write

00:04:27.800
00:04:33.900
variable values.Json, now in Json if
you want to define

00:04:33.900
00:04:37.700
any data, you have to start and close
with the curly braces

00:04:37.700
00:04:41.400
then inside of that suppose if I want to
define a scalar

00:04:41.700
00:04:42.900
then X.

00:04:42.900
00:04:44.600
[no audio]

00:04:44.600
00:04:45.400
Let's say suppose.

00:04:45.400
00:04:46.600
I'm writing some number.

00:04:47.800
00:04:53.900
then, I will take different variables
because already same

00:04:53.900
00:04:56.700
variable is there let's say some P.

00:04:56.700
00:04:58.700
[no audio]

00:05:02.600
00:05:04.010
Let's say some Q.

00:05:04.000
00:05:07.400
So, inside of Q list of values, I want to
store,

00:05:07.400
00:05:09.710
[no audio]

00:05:09.700
00:05:16.000
, then I'm taking one or map, map or
dictionary.
00:05:16.900
00:05:19.000
So here I am writing simply.

00:05:19.000
00:05:21.909
[no audio]

00:05:21.900
00:05:29.200
One:1, two: 2, so this is the way how
you can define a Json data.

00:05:29.700
00:05:32.500
So, this is a Json data inside my Json
data.

00:05:32.500
00:05:38.000
I have one scalar one list and one
dictionary or map, right?

00:05:38.200
00:05:39.630
Let me save this.

00:05:39.630
00:05:41.700
Now, our file is .json

00:05:41.700
00:05:43.800
variables values .Json.

00:05:43.800
00:05:45.409
[no audio]

00:05:45.400
00:05:49.000
Now, I want to read variables from
multiple files then instead

00:05:49.000
00:05:49.800
of in this way.

00:05:49.800
00:05:52.800
Just right where's file section under
that just the right

00:05:52.800
00:05:57.100
with hyphens - first file to read your
variable second file

00:05:57.100
00:06:02.100
to read your variables right now from
the second file.

00:06:02.100
00:06:06.600
You have one of the variables called
it's a are I want to

00:06:06.600
00:06:12.200
display that variable right now see that
see first of all

00:06:12.200
00:06:14.110
[no audio]
00:06:14.100
00:06:17.800
.json you have a variable or here for
this or this is

00:06:17.800
00:06:22.500
the data now I am trying to read that
with the help of our

00:06:22.500
00:06:24.500
Playbook.

00:06:24.500
00:06:25.900
Var = R.

00:06:26.000
00:06:28.800
Now, let me run this and see the
output whether you're able to

00:06:29.000
00:06:31.900
read the data from your Json file or
not.

00:06:31.900
00:06:35.409
[no audio]

00:06:35.400
00:06:35.900
See that?

00:06:36.800
00:06:40.900
Yes, we can able to read that Json
data as well using your

00:06:40.900
00:06:43.100
ansible playbook, right?

00:06:43.200
00:06:46.700
So, guys, this is the simple way to
define your variables

00:06:46.700
00:06:51.400
in separate files, maybe Yaml files or
Json files and those

00:06:51.400
00:06:55.700
variables. We are calling we are
displaying we are using

00:06:55.900
00:06:57.500
inside of our playbooks.

00:06:57.500
00:06:59.360
[no audio]

00:06:59.350
00:07:01.000
Okay guys, thank you for watching this
video.
Transcript
00:00:00.000
00:00:01.500
Friends here

00:00:01.500
00:00:04.600
our concept is working with command
line arguments.

00:00:04.700
00:00:07.600
So first, let me open my ansible
controller there,

00:00:07.600
00:00:11.600
I want to show you a simple Playbook.
See I am writing a simple

00:00:11.600
00:00:15.737
Playbook called cmd_line_args.yml.

00:00:15.737
00:00:17.800
So I am starting with the three
hyphens.

00:00:17.800
00:00:20.410
[no audio]

00:00:20.400
00:00:24.300
So, in the next line space - then I am
mentioning target as
00:00:24.300
00:00:29.600
localhost. Then I am defining a
variable by using various

00:00:29.600
00:00:33.200
section, simply a scalar variable that is
suppose some variable

00:00:33.200
00:00:37.800
value. Then I want to display that, then
using tasks section.

00:00:38.200
00:00:40.600
I am writing a task with debug module.

00:00:40.700
00:00:44.100
I am using var parameter of your
debug to display variable

00:00:44.100
00:00:48.800
value and I want to disable gather
facts.

00:00:48.800
00:00:51.809
[no audio]

00:00:51.800
00:00:54.200
Now, see this is our Playbook.

00:00:54.300
00:00:55.500
I am running this Playbook.

00:00:55.700
00:01:00.400
So, what we return in our Playbook is
simply we define a variable

00:01:00.400
00:01:03.000
and we are displaying that variable
with the help of debug

00:01:03.000
00:01:04.800
module. Just observe the output.

00:01:04.800
00:01:08.300
Yes, we're able to display the value
which we define for

00:01:08.300
00:01:08.900
your X.

00:01:10.000
00:01:13.400
Now what I am doing is simply I am
removing vars section.

00:01:13.400
00:01:16.110
[no audio]
00:01:16.100
00:01:20.800
Now if I run this what is output, you're
going to get X variable

00:01:20.800
00:01:24.300
is not defined actually as of now, we
don't have a variable

00:01:24.300
00:01:27.200
called X in our Playbook just now we
remove that vars

00:01:27.200
00:01:31.200
section. Now we know that we can
Define variable in different

00:01:31.200
00:01:35.100
ways using vars section or vars
prompt or vars file.

00:01:35.500
00:01:38.900
We have been discussed all those
different procedures in

00:01:38.900
00:01:43.200
our previous videos, now apart from
that procedures

00:01:43.200
00:01:46.900
I want to do some different procedure
see that this is our

00:01:46.900
00:01:50.200
Playbook and if I run that you are
getting a variable X is

00:01:50.200
00:01:51.100
not defined.

00:01:52.000
00:01:54.800
Now what I am doing is while running
our playbook in the

00:01:54.800
00:01:56.000
command line itself.

00:01:56.000
00:01:59.900
I am passing a value for your X, now
see the result.

00:01:59.900
00:02:01.760
[no audio]

00:02:01.750
00:02:06.603
So, while running your playbook I am
passing a variable X = 256.
00:02:06.603
00:02:09.199
So that this value you can be able to
read with the

00:02:09.199
00:02:12.100
help of your playbook and you are
able to display that value.

00:02:12.500
00:02:15.600
Now, this is called simply command
line argument.

00:02:15.600
00:02:17.700
[no audio]

00:02:17.700
00:02:22.400
Right, see simply command line
arguments are useful to pass

00:02:22.400
00:02:24.100
variables from command line.

00:02:24.800
00:02:28.100
Now, we can pass different types of
variables in different

00:02:28.100
00:02:29.900
formats to your playbook.

00:02:30.600
00:02:33.500
So, first of all, we are using command-
line arguments to pass

00:02:33.500
00:02:36.400
some variable values to your playbook
while running your

00:02:36.400
00:02:41.700
playbook. Right, but you can pass
different types of variables.

00:02:41.700
00:02:44.200
So, we know we have different types
of data structures in

00:02:44.200
00:02:46.300
our ansible Playbook or a yml script.

00:02:46.500
00:02:50.000
They are like scale or sequence and
map you can pass any

00:02:50.000
00:02:53.400
one of the data structure or
combination of your data structures
00:02:53.400
00:02:56.300
to your Ansible play book while
running as a command

00:02:56.300
00:02:57.400
line arguments.

00:02:58.600
00:03:00.000
Not only these data structures,

00:03:00.200
00:03:03.500
you can store your variable values you
are data structures

00:03:03.500
00:03:07.500
into one file like Json or yml file and
that file also, you

00:03:07.500
00:03:11.100
can pass as a command line argument
for your ansible playbook

00:03:11.200
00:03:13.900
and you can use the variable values
which are there in your

00:03:13.900
00:03:16.700
files by using your ansible playbook.

00:03:16.700
00:03:18.550
[no audio]

00:03:18.550
00:03:21.000
So, this is the concept of your
command line arguments now,

00:03:21.000
00:03:22.400
let me go with step by step.

00:03:23.500
00:03:25.700
First, I want to work with scalar.

00:03:25.800
00:03:29.742
I mean, I want to pass command line
argument as a scalar.

00:03:29.742
00:03:33.400
See, suppose if you want to define
any variable inside of your

00:03:33.400
00:03:37.700
playbook, then you are defining X : 34
under Var

00:03:37.700
00:03:43.000
section. So instead of that we are
passing directly from
00:03:43.000
00:03:43.600
command line.

00:03:44.000
00:03:47.600
Then you have to follow in this way
ansible Playbook

00:03:47.700
00:03:49.400
this is your answer will play book
command.

00:03:49.500
00:03:56.310
Then you're required Playbook then --
extra-var "X=34"

00:03:56.300
00:03:59.800
So inside of quotations, you have to
pass what var for single

00:03:59.800
00:04:03.300
variable no need to pass these
quotations, but for multiple

00:04:03.300
00:04:07.900
variables, it's better to pass
quotations, right see that.

00:04:07.900
00:04:10.410
[no audio]

00:04:10.400
00:04:12.000
So, this is your playbook.

00:04:12.200
00:04:15.600
We are running that Playbook simply
by-passing variable value

00:04:15.600
00:04:16.500
from command line.

00:04:16.600
00:04:22.500
I can pass - - extra VAR then with the
quotations or without

00:04:22.500
00:04:25.399
quotations? It's working without
quotations.

00:04:25.399
00:04:26.700
It is working with quotations.

00:04:26.700
00:04:29.600
Also, it will work but actually with
quotations is the best

00:04:29.600
00:04:33.300
practice and here option are some
lengthy option.
00:04:33.800
00:04:37.000
Now I can also use instead of this --
extra-var a

00:04:37.000
00:04:44.600
shortcut for your option simply -e. I
can also pass your

00:04:44.600
00:04:47.675
scalar value in this way also

00:04:47.675
00:04:57.767
-e “”

00:04:57.767
00:05:01.210
be clear " then {

00:05:01.200
00:05:04.200
Then this is X scalar value now see
the result.

00:05:04.800
00:05:07.110
That's it. Right.

00:05:07.100
00:05:10.500
So, these are the different ways to
pass your single scalar

00:05:10.500
00:05:12.300
value to your playbook.

00:05:12.300
00:05:14.909
[no audio]

00:05:14.900
00:05:17.800
Now, if I want to pass multiple
variables then how we can

00:05:17.800
00:05:22.700
passes see that I want to modify my
playbook such that I want

00:05:22.700
00:05:25.800
to read two variable values to I want to
display two variables

00:05:25.800
00:05:29.700
values then let me take message
parameter for your debug.

00:05:29.700
00:05:35.210
That's better. So, I am passing

00:05:35.200
00:05:39.600
the X value is "}.

00:05:39.600
00:05:42.409
[no audio]
00:05:42.400
00:05:48.600
Then the Y value is, I mean actually
we don't have x + y inside

00:05:48.600
00:05:52.300
of our Playbook, but I want to pass X
and Y both the values

00:05:52.600
00:05:57.100
from command line see that how I am
passing ansible - Playbook

00:05:57.500
00:05:58.900
command-line arguments.

00:05:59.100
00:06:08.717
Sorry, your playbook then - e "X=56"
Y= 89"

00:06:08.717
00:06:10.100
now see the result.

00:06:11.400
00:06:15.900
Yes, now instead of these you can
also pass as a map value.

00:06:15.900
00:06:19.300
I mean inside of curly brace see that
curly brace.

00:06:19.300
00:06:21.409
[no audio]

00:06:21.400
00:06:24.500
But the way how you are going to
pass that procedure is different

00:06:24.500
00:06:41.135
-e “”

00:06:41.135
00:06:41.600
That's it.

00:06:41.600
00:06:43.510
[no audio]

00:06:43.500
00:06:44.300
Now see the result.

00:06:44.300
00:06:46.409
[no audio]

00:06:46.400
00:06:50.300
So, you can pass your multiple values
in this way or in this

00:06:50.300
00:06:53.800
way. Both are valid, right. Suppose
00:06:54.100
00:06:59.200
I want to pass one variable as simply
suppose some number

00:06:59.400
00:07:00.900
and second variable as suppose

00:07:00.900
00:07:06.800
I want to pass like a this is from
command line or let's

00:07:06.800
00:07:13.300
say simply Ansible playbooks so
y=ansible playbooks,

00:07:13.300
00:07:16.500
but see the result what you are getting
the Y value we are

00:07:16.500
00:07:19.700
getting only ansible you are not getting
ansible playbooks.

00:07:20.000
00:07:23.500
So whenever if you have spaces in
your value for your variable

00:07:23.600
00:07:27.800
at the time, please use quotation
single quotation or use

00:07:27.800
00:07:29.400
quotations for string values.

00:07:29.400
00:07:29.900
That's it.

00:07:29.900
00:07:31.610
[no audio]

00:07:31.600
00:07:33.700
The answer will play books is a single
string, right?

00:07:34.200
00:07:37.500
That's why use quotation for string of
string values now

00:07:37.500
00:07:40.100
see that you are getting complete and
civil playbooks previously

00:07:40.100
00:07:41.200
got only ansible.

00:07:42.200
00:07:45.700
So, this is the way how you can work
with
00:07:45.700
00:07:47.700
[no audio]

00:07:47.700
00:07:53.100
scalar values simply how to work with
scalar values Right

00:07:53.300
00:07:57.400
now, let me go and work with
sequence very simple.

00:07:57.400
00:08:00.600
If you want to work with your
sequence, simply inside of

00:08:00.600
00:08:04.200
your curly braces, just write your
sequence values as a list

00:08:04.500
00:08:06.400
in your python, see that.

00:08:08.200
00:08:13.400
Now let me pass one value as I will do
one thing.

00:08:13.400
00:08:17.610
[no audio]

00:08:17.600
00:08:20.400
Let me take let me comment this now.

00:08:20.400
00:08:22.300
I am passing only sequence.

00:08:23.400
00:08:26.400
So, if you want to pass a sequence,
you have to pass in this

00:08:26.400
00:08:31.600
way. Quotations, sorry curly brace
then inside of that your

00:08:31.600
00:08:34.500
x then as a list.

00:08:34.500
00:08:37.299
That is the sequence right now see
the result.

00:08:37.700
00:08:39.200
They're getting list of values.

00:08:39.200
00:08:42.010
[no audio]

00:08:42.000
00:08:46.000
Now I want to pass suppose map or
dictionary
00:08:46.200
00:08:51.600
then you can pass suppose X is my
map variable then inside

00:08:51.600
00:08:53.299
that key value pair representation.

00:08:53.500
00:08:57.100
Let's say 1 then 2.

00:08:57.100
00:08:59.810
[no audio]

00:08:59.800
00:09:00.300
That's it.

00:09:01.500
00:09:02.500
Now see the result.

00:09:02.500
00:09:05.910
[no audio]

00:09:05.900
00:09:06.400
Right.

00:09:07.000
00:09:10.100
So, this is the way how you can pass
your different types

00:09:10.100
00:09:14.800
of data structures like your scalar
sequence and your map.

00:09:15.500
00:09:20.100
No, we can also pass command line
arguments as some file

00:09:20.600
00:09:21.700
inside of that file

00:09:21.700
00:09:23.200
we will define our variables.

00:09:23.700
00:09:26.700
If you want to pass your file simply
how to use other at

00:09:26.700
00:09:29.800
your file name, maybe yml file or
maybe Json file.

00:09:30.800
00:09:35.200
Let me open my controller see that we
have something called

00:09:35.200
00:09:38.300
here already from our previous
classes.
00:09:38.300
00:09:40.160
[no audio]

00:09:40.150
00:09:43.700
X value is there in this yml file now, let
me run.

00:09:44.900
00:09:47.100
Simply by passing at the rate

00:09:48.300
00:09:50.200
your yml file.

00:09:50.500
00:09:51.700
So, what is the x value here?

00:09:51.700
00:09:55.000
45 this value will be displayed by your
playbook.

00:09:56.600
00:10:00.400
See that? We are defining our variable
values inside of a

00:10:00.400
00:10:03.700
1 yml file and that file I am passing as
a command line

00:10:03.700
00:10:08.200
argument so that from this file the
variable value will be

00:10:08.600
00:10:10.500
get by using your playbook.

00:10:10.500
00:10:14.900
That's it. The same way you can also
work with Json file.

00:10:14.900
00:10:17.300
Let me open your Json file in Json file.

00:10:17.300
00:10:22.100
We have P Q R, so let me modify this
Json file with X suppose.

00:10:22.200
00:10:29.300
Let's say X, now in your Jason we
have a variable called X

00:10:29.800
00:10:32.200
that X I want to read by using our
Playbook.

00:10:33.400
00:10:36.300
right now, see that simply.

00:10:36.300
00:10:38.910
[no audio]
00:10:38.900
00:10:41.500
Instead of yml now I am passing Json.

00:10:41.500
00:10:43.260
[no audio]

00:10:43.250
00:10:45.200
Now see the result we are getting your
x value.

00:10:45.300
00:10:45.800
That's it.

00:10:45.800
00:10:47.209
[no audio]

00:10:47.199
00:10:47.400
So, guys.

00:10:47.400
00:10:52.600
This is the way how we can read
variables with the help of

00:10:52.600
00:10:53.900
command line arguments.

00:10:54.200
00:10:57.500
So those command line arguments we
can pass as a scalar or

00:10:57.500
00:11:03.000
sequence or map or even maybe
some Json or XML files, right.

00:11:03.500
00:11:06.200
Now, let me go with one simple
example to understand the

00:11:06.200
00:11:09.600
use case of your command line
arguments in your real time.

00:11:09.600
00:11:11.510
[no audio]

00:11:11.500
00:11:16.000
See, let me write a simple A playbook
just to install some httpd

00:11:16.600
00:11:18.400
let me check whether do I how,

00:11:19.000
00:11:20.600
Yeah, I don't have HTTP on my host.

00:11:20.600
00:11:24.500
Let me write simply install and
uninstall.
00:11:25.700
00:11:28.700
Httpd.yml. Because of all, directly

00:11:28.700
00:11:31.400
I'm writing a play book just to install
your httpd.

00:11:31.700
00:11:33.500
So, I am giving a name for my play.

00:11:34.300
00:11:47.100
This is a simple play to understand
command line arguments

00:11:48.600
00:11:51.600
Right, and I'm taking Target as simply
localhost.

00:11:51.600
00:11:53.460
[no audio]

00:11:53.450
00:11:56.600
Now, let me write a task section.

00:11:56.800
00:11:57.800
So, under tasks.

00:11:57.800
00:11:59.800
I am writing a task name called.

00:11:59.800
00:12:01.510
[no audio]

00:12:01.500
00:12:08.700
working with httpd then let's say I want
to install this

00:12:08.700
00:12:11.400
right? So, if you want to install you
have to take a name

00:12:11.400
00:12:14.900
as httpd then state as supposed
present.

00:12:14.900
00:12:16.810
[no audio]

00:12:16.800
00:12:17.300
Be clear.

00:12:17.500
00:12:19.100
This is simply our Playbook.

00:12:20.200
00:12:23.300
To install your httpd now I am running
this.

00:12:23.300
00:12:28.210
[no audio]
00:12:28.200
00:12:30.900
Install and uninstall httpd.yml.

00:12:31.100
00:12:35.100
Let me run this and see the output and
I don't want to gather

00:12:35.100
00:12:38.000
facts, let me disable that.

00:12:39.100
00:12:43.100
So that I can save some time while
executing my script but

00:12:43.100
00:12:45.600
sometimes you need to collect your
facts at the time don't

00:12:45.600
00:12:50.510
disable. It will discuss that situation
later.

00:12:50.500
00:12:55.400
Now, let me run this so simply ansible
Playbook.

00:12:55.400
00:13:01.100
I am running see that It is installing
your httpd.

00:13:01.100
00:13:06.610
[no audio]

00:13:06.600
00:13:07.400
Just wait.

00:13:08.500
00:13:09.000
What happened?

00:13:10.000
00:13:12.400
Yeah, you need to be route to perform
this Command, right?

00:13:13.600
00:13:18.000
So, let me make let me provide root
privileges sudo privileges

00:13:18.000
00:13:20.700
by giving become as yes option.

00:13:21.900
00:13:23.000
Now, let me run this.

00:13:23.000
00:13:29.410
[no audio]

00:13:29.400
00:13:31.400
Now it is installing your httpd.
00:13:31.400
00:13:34.010
[no audio]

00:13:34.000
00:13:36.000
Yes, it has been installed your httpd.

00:13:36.000
00:13:38.310
You can check whether it is installed
or not. Yes,

00:13:38.300
00:13:42.400
it has been installed. Now using the
same Playbook.

00:13:42.400
00:13:44.359
[no audio]

00:13:44.349
00:13:46.900
suppose if I want to install some other
package then what

00:13:46.900
00:13:47.500
I have to do.

00:13:48.200
00:13:49.100
I need to open it.

00:13:49.100
00:13:51.200
Let's say I want to install nginx as well.

00:13:51.400
00:13:55.400
Then I need to open this and I need to
modify in different

00:13:55.400
00:13:56.200
places here.

00:13:56.200
00:13:57.300
I want to modify.

00:13:58.400
00:14:01.900
Let's say in genetics and here also, I
want to modify in

00:14:01.900
00:14:10.400
genetics. Right, then I have to run this,
but I don't want

00:14:10.400
00:14:15.300
to modify a package name inside of
my playbook to install

00:14:15.300
00:14:18.500
or uninstall suppose if you want to
uninstall you need right

00:14:18.500
00:14:22.300
here absent, but I don't want to open
my script and I don't
00:14:22.300
00:14:24.200
want to edit instead of that.

00:14:24.300
00:14:27.200
I am writing my playbook in terms of
variables.

00:14:27.200
00:14:29.900
See that what I am writing so we can
understand the usage

00:14:29.900
00:14:31.900
of your command line arguments.

00:14:31.900
00:14:33.460
[no audio]

00:14:33.450
00:14:34.900
See working with some package.

00:14:34.900
00:14:38.400
I will take a variable called package so
variable I'm writing

00:14:38.500
00:14:41.200
by using two curly braces here.

00:14:41.200
00:14:45.400
Also, package name right here
quotations be clear.

00:14:45.400
00:14:46.400
There is a syntax rule.

00:14:46.400
00:14:49.610
[no audio]

00:14:49.600
00:14:52.200
Then required state I will take here as
a variable.

00:14:52.200
00:14:56.810
[no audio]

00:14:56.800
00:15:00.900
Now know where we don't know
where we are having simply like

00:15:00.900
00:15:03.700
a package name and state all are in
terms of variables.

00:15:03.900
00:15:07.100
So, that's why what I will do is first up
the river.

00:15:08.700
00:15:11.700
Now I am running our Playbook to
install suppose in genetics.
00:15:12.300
00:15:15.900
Then what I am doing is simply I am
running my PlayBook.

00:15:17.000
00:15:19.000
Bypassing command-line arguments
there.

00:15:19.000
00:15:23.800
I am passing variable names package
variable name as in genetics

00:15:24.400
00:15:27.100
then required state as present.

00:15:28.200
00:15:30.500
I'm not ending the Playbook,

00:15:31.000
00:15:34.100
just simply I have written my playbook
in terms of variables

00:15:34.100
00:15:37.400
package and required state now if I
run that see the output

00:15:37.400
00:15:39.900
what you are getting working with in
genetics.

00:15:40.200
00:15:40.700
Yes, right.

00:15:40.700
00:15:44.300
We are passing that, and we are
installing present.

00:15:47.100
00:15:50.700
Right now, suppose if I want to
uninstall httpd.

00:15:50.700
00:15:53.000
I don't want to open my script simply.

00:15:53.000
00:15:54.100
I will modify here.

00:15:54.600
00:15:57.200
I mean while running your playbook on
the command line, I

00:15:57.200
00:16:02.500
will pass package as httpd and
required State as absent.

00:16:03.600
00:16:06.600
So that your same Playbook will also
useful to uninstall
00:16:06.600
00:16:10.500
your package, your required package,
right.

00:16:10.500
00:16:13.700
So, guys, this is simple usage of your
command line arguments

00:16:13.700
00:16:14.600
in your real time.

00:16:14.600
00:16:17.710
[no audio]

00:16:17.700
00:16:18.100
Right.

00:16:18.100
00:16:19.500
So, this is the way we are running.

00:16:20.100
00:16:22.400
So, let us suppose if you want to
install any other package

00:16:22.400
00:16:23.800
just provide your package name.

00:16:24.300
00:16:27.200
If you want to install write your present
or latest if you

00:16:27.200
00:16:30.700
want to uninstall just write your
package name and absent

00:16:30.700
00:16:34.600
so that this Playbook is working for
different scenarios.

00:16:34.800
00:16:38.400
So that is the usage of command line
arguments, right?

00:16:38.800
00:16:40.900
Okay guys, thank you for watching this
video.

00:16:40.900
00:16:43.900
[no audio]
Transcript
00:00:00.000
00:00:01.700
Friends, here

00:00:01.700
00:00:05.600
our concept is uses of gather facts or
simply how to collect

00:00:05.600
00:00:09.600
information about your remote nodes
or host with gather facts

00:00:10.100
00:00:14.500
see before going to discuss about this
gather facts Concepts.

00:00:14.500
00:00:18.400
I want to show you I want to write a
simple Playbook first.

00:00:19.000
00:00:22.400
So my playbook purpose is whenever
if I run my playbook it

00:00:22.400
00:00:25.400
has to display the way s name and
waste distribution of my
00:00:25.400
00:00:28.900
nodes. See before going to write your
playbook suppose if

00:00:28.900
00:00:31.700
we take Unix command you name
then you are going to get OS

00:00:31.700
00:00:39.600
name. and if we take simply This file if
you read this file

00:00:39.600
00:00:41.600
you are having waste distribution
name here.

00:00:42.000
00:00:44.000
So distribution name is simply sent
ways.

00:00:44.000
00:00:46.800
I want to get only this sent waves then
I'm modifying this

00:00:47.300
00:00:52.300
with the help of my awwk command
now see the result how I

00:00:52.300
00:00:54.700
am going to get only sent waves from
this.

00:00:56.300
00:00:58.600
You're getting entire line, but I don't
want to get entire

00:00:58.600
00:01:02.500
line. I want to get only sent ways then
let me take field

00:01:02.500
00:01:05.900
separator as equal and let me print
second field.

00:01:08.300
00:01:11.400
But here I want to get only sent ways
then again use one

00:01:11.400
00:01:12.200
more time.

00:01:12.200
00:01:16.600
You're a WK and simply apply printed
dollar one.
00:01:17.600
00:01:19.800
So where you are going to get first
field, but here you are

00:01:19.800
00:01:20.700
getting equals.

00:01:20.700
00:01:22.000
Sorry quotation symbol.

00:01:22.100
00:01:25.500
I want to remove that then use transfer
command and then

00:01:25.900
00:01:32.400
use This is now you're getting your OS
distribution name.

00:01:33.300
00:01:34.500
Now same command.

00:01:34.500
00:01:36.500
You can also run on other
distributions.

00:01:36.500
00:01:39.900
Let's say I have some Amazon Linux
distribution there.

00:01:39.900
00:01:42.400
I want to run this command and I want
to see the output.

00:01:43.200
00:01:46.000
Let me open My Amazon Linux box.

00:01:47.400
00:01:50.900
So here if you run you name you are
getting your OS name,

00:01:50.900
00:01:54.100
but if you run this command you're
getting your waist distribution

00:01:54.100
00:01:55.500
that is amazed on distribution.

00:01:56.400
00:02:00.200
Now to get your waist distribution and
wires name.

00:02:00.200
00:02:01.400
I want to write a play book.

00:02:01.500
00:02:03.200
Let me write that Playbook first.
00:02:03.600
00:02:08.500
So why is distribution and Os name
dot?

00:02:08.500
00:02:09.199
Yml.

00:02:10.199
00:02:11.800
So let me write a simple Playbook.

00:02:12.800
00:02:14.800
So I am giving name for my play.

00:02:15.500
00:02:22.900
So finding OS distribution and various
name then Target.

00:02:22.900
00:02:26.000
I am taking suppose all servers which
are there in my inventory.

00:02:26.200
00:02:30.500
File then as of now am disabling
gather facts, actually.

00:02:30.500
00:02:33.600
Our concept is gather facts will
discuss this first.

00:02:33.600
00:02:36.800
I will attend simple Playbook then we
will work with gather

00:02:36.800
00:02:42.500
facts for our requirement then tasks
section so here to find

00:02:42.500
00:02:44.000
out ways distribution.

00:02:44.100
00:02:45.700
I am going to Define one task.

00:02:45.800
00:02:49.900
So simply finding voice distribution.

00:02:51.400
00:02:55.500
See you have a command so we can
run our unix-like system

00:02:55.500
00:02:58.400
command with the help of your shell
module.

00:02:58.800
00:03:01.900
Then I want to capture that output into
a variable.
00:03:02.100
00:03:05.700
Let me take that variable as
distribution or simply waste

00:03:05.700
00:03:08.000
underscore distribution.

00:03:09.400
00:03:13.000
See here because we are using
multiple times quotations.

00:03:13.000
00:03:13.600
You have to take.

00:03:13.600
00:03:15.300
Yes / now, it's good.

00:03:16.400
00:03:20.100
Now next I want to Define one more
task Now by using this

00:03:20.100
00:03:22.900
task. I am finding only waste name.

00:03:23.400
00:03:27.100
So let me run one more command
with the help of shell module.

00:03:27.100
00:03:30.300
That is simply you name and let me
store the output of this

00:03:30.300
00:03:34.700
command result into one variable
called vs name now because

00:03:34.700
00:03:37.900
of these two tasks you are able to find
your waist distribution.

00:03:37.900
00:03:41.000
And your waist name now, I want to
display them.

00:03:41.000
00:03:44.200
Let me take simply debug module and
in debug module I am

00:03:44.200
00:03:46.000
taking message parameter.

00:03:46.300
00:03:51.600
And with the help of that I am
displaying The Voice distribution

00:03:51.900
00:04:03.100
name. is let me write your OS on the
score distribution variable.
00:04:04.000
00:04:05.900
Sorry, I already used quotations here.

00:04:05.900
00:04:06.100
Right?

00:04:06.100
00:04:07.500
Let me remove this quotation.

00:04:07.600
00:04:08.400
If that's fine.

00:04:09.000
00:04:09.100
Now.

00:04:09.100
00:04:13.200
Let me write one more message just
to display the OS name.

00:04:16.899
00:04:18.500
Now I am displaying this now.

00:04:18.500
00:04:22.800
Let me save it and run it say this is
your playbook and I'm

00:04:22.800
00:04:23.899
running this Playbook.

00:04:27.700
00:04:29.200
See the result what you are getting.

00:04:30.600
00:04:31.900
So we have two tasks.

00:04:32.000
00:04:34.900
These two tasks has to execute on
two servers because in

00:04:34.900
00:04:37.600
my inventory, I have two servers just
wait for some time.

00:04:38.400
00:04:40.500
So once our one node is my Local
Host.

00:04:40.500
00:04:43.100
One more node is my AWS server.

00:04:44.300
00:04:44.700
Right.

00:04:44.800
00:04:45.400
Just wait.

00:04:45.700
00:04:49.400
Yeah now see the result what you are
getting on This Server
00:04:49.400
00:04:52.200
you are getting some output but this
output consists of some

00:04:52.200
00:04:53.200
different informations.

00:04:53.200
00:04:57.700
I need only STD out.

00:04:57.800
00:05:01.100
Let's say where is yeah, this one I
want so instead of getting

00:05:01.100
00:05:02.800
this entire information.

00:05:02.800
00:05:05.400
I want display only STD out.

00:05:05.400
00:05:07.000
Let me modify my PlayBook.

00:05:08.100
00:05:11.600
See how much code you're writing to
find out your waist distribution

00:05:11.600
00:05:12.600
and waste name.

00:05:13.700
00:05:16.800
But this we can simplify if you know
the usage of gather

00:05:16.800
00:05:18.000
facts or set up module.

00:05:18.000
00:05:21.200
We will see that just wait now let me
rerun.

00:05:27.800
00:05:28.700
Just wait.

00:05:30.500
00:05:33.200
So first task it is executing on to
servers.

00:05:34.400
00:05:36.300
Then second task is executing.

00:05:37.000
00:05:39.400
So once it is done, then it will display
the information

00:05:39.400
00:05:41.600
about your two nodes see that.

00:05:42.900
00:05:44.600
So this is my Amazon server.
00:05:45.100
00:05:47.600
So imagine distribution OS name
Linux.

00:05:48.100
00:05:48.800
So localhost.

00:05:48.800
00:05:50.200
This is centralized distribution.

00:05:50.300
00:05:51.300
Which name is Linux.

00:05:51.500
00:05:52.200
That's fine.

00:05:52.600
00:05:55.600
Now simply to get your waist name on
distribution.

00:05:55.900
00:05:59.400
We have written a simple Playbook
with this lengthy code.

00:06:00.800
00:06:02.600
Now forget about this now.

00:06:02.600
00:06:05.400
I am going to work with set up module
or gather facts.

00:06:06.200
00:06:08.700
See if you remember while working
with Iraq commands.

00:06:08.700
00:06:11.500
We ran a module called.

00:06:13.500
00:06:14.100
Set up.

00:06:15.300
00:06:15.400
Now.

00:06:15.400
00:06:17.400
What is the output of your setup
module you are going to

00:06:17.400
00:06:21.200
get some information or facts about
your managed nodes that

00:06:21.200
00:06:26.400
facts also includes your custom facts if
you remember.

00:06:27.800
00:06:28.800
Just after the output.
00:06:30.100
00:06:33.300
It is going to give some information
now this information.

00:06:33.300
00:06:34.500
Let me go to top.

00:06:35.600
00:06:40.600
This information consists of different
values of your managed

00:06:40.600
00:06:45.800
nodes. right just observe from Top see
that.

00:06:45.800
00:06:47.900
What is the your IP addresses?

00:06:48.000
00:06:48.200
Right?

00:06:48.200
00:06:51.100
What is the architecture of your
manager node?

00:06:51.200
00:06:52.100
Anyway, I'm as of now.

00:06:52.100
00:06:53.800
I'm running this on only localhost.

00:06:54.700
00:06:54.900
Right?

00:06:54.900
00:06:56.000
What is the bias version?

00:06:56.000
00:06:59.500
What is the bias date and we'll ansible
means you are managed.

00:06:59.500
00:07:02.900
No, not your ansible and will bias date
means your manage

00:07:02.900
00:07:06.300
note bias data or your managed node
bias version the same

00:07:06.300
00:07:08.100
way you're having different values
here.

00:07:08.600
00:07:10.300
Just observe that all the values.

00:07:11.500
00:07:14.400
You just go to line by line because in
future you are going
00:07:14.400
00:07:17.800
to use or different values from your
setup module while we're

00:07:17.800
00:07:18.900
writing your playbooks.

00:07:19.200
00:07:20.400
See what is the distribution?

00:07:21.900
00:07:22.100
All right.

00:07:22.100
00:07:23.700
What is the distribution version?

00:07:23.800
00:07:27.500
I mean you are manager node OS
distribution version.

00:07:28.900
00:07:29.400
Right.

00:07:30.100
00:07:32.400
So likewise, if you go down you're
going to get different

00:07:32.400
00:07:35.100
values. What is the user home?

00:07:36.400
00:07:37.400
What is the logname?

00:07:37.400
00:07:39.600
I mean who logged into that server?

00:07:41.100
00:07:43.000
See, what is the shell right?

00:07:43.800
00:07:46.000
So likewise you're having different
values here.

00:07:47.700
00:07:48.200
No.

00:07:49.500
00:07:54.700
I want to write a simple Playbook
whatever the Playbook previously

00:07:54.700
00:07:59.200
we return that in terms of your setup
module.

00:07:59.500
00:08:03.400
First of all, let me write a simple
Playbook gather facts

00:08:03.400
00:08:05.300
dot yml see that.
00:08:05.300
00:08:06.300
I am running this.

00:08:07.900
00:08:10.200
Simply I'm taking Target as localhost.

00:08:11.300
00:08:16.800
Then tasks section simply I am writing
here debug.

00:08:18.000
00:08:18.700
One more thing.

00:08:19.000
00:08:22.000
If You observe in the output overall, I
mean after running

00:08:22.000
00:08:24.400
your setup module, whatever the
output you're going to get

00:08:24.400
00:08:28.800
that output is storing a way into a
variable called.

00:08:29.800
00:08:35.700
Let me run your Ansible facts.

00:08:35.799
00:08:37.200
Let me show you the output ones.

00:08:38.000
00:08:39.600
Just good top.

00:08:46.500
00:08:48.600
See that there is a ansible facts
variable.

00:08:49.200
00:08:49.700
Now.

00:08:49.700
00:08:54.500
What I am doing is Simply I am
displaying a variable value

00:08:54.500
00:08:55.900
called ansible facts.

00:08:56.400
00:08:57.600
See if you remember.

00:08:59.000
00:09:04.000
Whenever if you run your Playbook by
default set fact module

00:09:04.000
00:09:06.100
will be executed as one of the tasks.
00:09:06.100
00:09:09.900
That is the default task right see in this
Playbook.

00:09:09.900
00:09:11.500
We are having only develop tasks.

00:09:11.800
00:09:17.400
We are not having any setup module
task right by default

00:09:17.400
00:09:18.200
that will xq.

00:09:18.400
00:09:20.800
Let me run it this Playbook and see
the result.

00:09:23.200
00:09:26.400
So it is gathering facts means it is
running internally set

00:09:26.400
00:09:30.000
up module to gather facts and that
output will store into

00:09:30.000
00:09:33.000
by default and simple facts variable
that variable we are

00:09:33.000
00:09:35.500
displaying because of that you are
getting this output.

00:09:38.600
00:09:41.000
Just to go top once.

00:09:43.000
00:09:44.200
And see your playbook first.

00:09:44.200
00:09:45.500
This is your playbook in Playbook.

00:09:45.500
00:09:49.100
You have only one task but your play
book is running two

00:09:49.100
00:09:50.500
tasks one is gathering facts.

00:09:50.500
00:09:54.800
Second one is displaying your
Gathering gather facts, right?

00:09:54.900
00:09:58.900
So by default your setup module will
run and that is called
00:09:58.900
00:10:02.300
Gathering facts right now.

00:10:02.300
00:10:03.100
You're getting that.

00:10:04.100
00:10:06.100
Now one more thing just observe that.

00:10:08.400
00:10:11.500
Now, you know in your gather facts,
we have your waist distribution

00:10:11.600
00:10:14.100
OS name ways family-type, right?

00:10:14.700
00:10:16.800
See if You observe this entire output
you will you will come

00:10:16.800
00:10:20.200
to know that now what I am doing is
simply I am doing pipeline

00:10:20.200
00:10:23.900
graph and Sybil see the result what
you are getting.

00:10:25.600
00:10:28.100
See, these are the different variables
directly you can use

00:10:28.100
00:10:29.300
in your playbooks.

00:10:31.000
00:10:33.500
Right and one more thing before going
to use this.

00:10:34.300
00:10:38.700
Let me show you that suppose if I
write gather facts as false.

00:10:40.300
00:10:43.700
Your setup module won't run if your
setup model is not running

00:10:44.100
00:10:47.600
then you cannot get values for value
for your ansible facts.

00:10:50.700
00:10:53.700
See I disabled gather facts.

00:10:53.700
00:10:55.900
That's why ants will facts are empty.

00:10:56.900
00:10:58.800
So to get ants will fax value.
00:10:59.300
00:11:03.800
You should enable this gather facts
means simply you can

00:11:03.800
00:11:06.800
write it true or just simply remove this
line here.

00:11:06.800
00:11:09.600
You can write to true anyway by
default.

00:11:09.600
00:11:11.400
This gather facts is true.

00:11:14.300
00:11:17.300
See that now it is collecting your facts.

00:11:18.700
00:11:20.600
Right, so no need to write any extra
line.

00:11:20.600
00:11:23.600
If you want to collect a gather fact,
simply remove this

00:11:23.600
00:11:26.300
line so that you will set up module will
run as the first

00:11:26.300
00:11:28.300
task. That's fine.

00:11:29.600
00:11:34.200
now See this.

00:11:35.600
00:11:38.700
I am running simply setup module and
from that I am gripping

00:11:38.700
00:11:39.500
ansible. Now.

00:11:39.500
00:11:41.600
If You observe here, we are having
different values here.

00:11:42.000
00:11:44.900
So all these values directly can use as
a variable inside

00:11:44.900
00:11:48.300
of your playbook see ansible
distribution.

00:11:49.400
00:11:54.800
And one more thing is we need ansible
system type right?
00:11:55.400
00:11:58.000
You can search somewhere you have
here and we'll system.

00:11:58.900
00:12:01.100
I tangible distribution you have here.

00:12:04.300
00:12:08.400
Now see what I am doing is simply I
am writing a A playbook

00:12:08.400
00:12:11.600
to display my waist distribution and Os
name in this way

00:12:11.700
00:12:14.600
previously. We already written a
simple Playbook but compared

00:12:14.600
00:12:14.900
to that.

00:12:14.900
00:12:15.900
This is very simple.

00:12:17.100
00:12:21.200
So why it is simple means we are
using the setup module variable

00:12:21.200
00:12:22.500
values. That's it.

00:12:22.700
00:12:25.200
If you know the usage of set up from
that you can get some

00:12:25.200
00:12:29.200
variable values see the value the waist
distribution.

00:12:31.700
00:12:38.500
is Simply you can write ansible
distribution.

00:12:40.100
00:12:48.200
Then I want suppose the OS name is
simply a hard to write

00:12:48.200
00:12:50.200
ansible underscore system.

00:12:51.800
00:12:54.400
So from where you can get this
variable names, it's very

00:12:54.400
00:12:59.500
simple. Just simply run your Rock'em
and setup module then
00:12:59.500
00:13:01.800
just simply grip with ansible so that
you are going to get

00:13:01.800
00:13:02.800
some values.

00:13:02.800
00:13:05.500
Those are the variables directly can
use those variables.

00:13:07.100
00:13:07.300
Right.

00:13:07.300
00:13:08.900
What is the West Family see that?

00:13:10.200
00:13:14.000
Now if you if you know the uses of
setup module or gather

00:13:14.000
00:13:17.800
facts, it is very simple to collect some
information of your

00:13:17.800
00:13:18.700
manager nodes.

00:13:28.500
00:13:32.100
See previously we had written this
Playbook this much lengthy

00:13:32.100
00:13:35.300
Playbook to get simply your waist
distribution and waste

00:13:35.300
00:13:38.100
name and we done some your Unix
command suppose.

00:13:38.100
00:13:41.700
If you don't know how to manipulate
your output from this

00:13:41.700
00:13:44.400
file with the help of your unix
commands, then you don't

00:13:44.400
00:13:47.600
need to worry simply use set up
module to collect some information.

00:13:47.800
00:13:50.300
But of course you cannot get all the
informations, but you
00:13:50.300
00:13:53.200
will get maximum information about
your manager nodes with

00:13:53.200
00:13:54.500
the help of gather facts.

00:13:55.400
00:13:58.000
Right now I'm running simply ansible
Playbook.

00:13:59.900
00:14:00.700
See the result.

00:14:02.400
00:14:06.400
Simply are getting sent waves Linux
and redhat family.

00:14:07.100
00:14:10.100
So now let me run this for all servers.

00:14:10.400
00:14:11.700
So simply right here.

00:14:13.200
00:14:20.300
all run this now you're going to get for
all servers which

00:14:20.300
00:14:23.000
are there in your inventory for that you
are going to get

00:14:23.100
00:14:27.800
ways distribution ways name and
ways family just wait.

00:14:28.800
00:14:35.200
see that Amazon server Amazon
distribution Linux Red Hat

00:14:35.700
00:14:40.200
centralized distribution Linux OS Red
Hat family, right?

00:14:40.200
00:14:44.200
So here my intention is if you know the
usage of setup module,

00:14:44.500
00:14:47.700
then you can reduce the Playbook
length.

00:14:48.800
00:14:50.900
And you can use effectively or
variables which are there
00:14:50.900
00:14:55.200
in your setup module right the usage
of variables from your

00:14:55.200
00:14:57.000
setup module is very very important.

00:14:57.700
00:15:00.400
The only thing what you have to do is
just run simply.

00:15:03.400
00:15:06.100
This module ones and see the entire
output ones.

00:15:07.500
00:15:09.500
What are the orbit you're going to get
just go with line

00:15:09.500
00:15:10.100
by line?

00:15:11.200
00:15:14.300
So you can also get your remote
server Mount points.

00:15:18.400
00:15:21.100
See that I want to get my remote
server Mount points then

00:15:21.100
00:15:23.500
simply open your playbook.

00:15:26.900
00:15:28.000
You can right here.

00:15:32.700
00:15:34.800
You don't need to write any extra code
to get your Mount

00:15:34.800
00:15:37.200
points already ansible is fetching with
the help of setup

00:15:37.200
00:15:41.300
module or with the help of gather facts
the mount points

00:15:41.700
00:15:45.400
or simply use the variable which is
there in your hand.

00:15:48.300
00:15:48.800
That's it.

00:15:49.600
00:15:49.800
Now.
00:15:49.800
00:15:50.900
Let me run your playbook.

00:15:58.000
00:16:01.100
So just wait it is running against on
you are a w server

00:16:01.100
00:16:01.500
as well.

00:16:05.500
00:16:07.300
Yes, it has been done see the result.

00:16:08.300
00:16:12.600
These are the mount points on your
edible a server and these

00:16:12.600
00:16:14.300
are the mount points on my server.

00:16:15.900
00:16:16.300
Right.

00:16:16.700
00:16:17.100
So guys.

00:16:17.100
00:16:19.600
This is the usage of your gather facts.

00:16:20.100
00:16:22.700
It's very very important be clear with
this.

00:16:23.300
00:16:23.700
Okay?

00:16:23.900
00:16:24.300
Okay guys.

00:16:24.300
00:16:25.600
Thank you for watching this video.
Transcript
00:00:00.000
00:00:02.204
[no audio]

00:00:02.204
00:00:03.127
Friends here

00:00:03.127
00:00:07.100
our concept is working with inventory
hostname and hosts

00:00:07.100
00:00:08.199
versus variable.

00:00:08.500
00:00:11.200
Let me explain this with simple
Playbook.

00:00:11.700
00:00:13.600
Let me open my Ansible controller.

00:00:13.600
00:00:15.350
[no audio]

00:00:15.350
00:00:17.500
So here I have an inventory file.

00:00:18.800
00:00:21.900
So, in my inventory how to manage
your notes, of course, I
00:00:21.900
00:00:23.800
divide them into some of groups as
well,

00:00:24.800
00:00:25.400
right?

00:00:25.900
00:00:26.500
That's fine.

00:00:26.600
00:00:27.300
Now see that.

00:00:28.300
00:00:29.700
I am going to write a simple Playbook.

00:00:29.900
00:00:32.853
Let me write a play book named as

00:00:32.853
00:00:38.692
vi hostvars_inventory_hostname.yml

00:00:38.692
00:00:44.000
First, let me write this Playbook by
taking my target as only Local

00:00:44.000
00:00:48.500
Host and I'm writing a simple task
under your tasks section.

00:00:48.900
00:00:54.200
My task is simply displaying the
variable called inventory

00:00:54.500
00:00:57.700
hostname. So, this is the one default
variable.

00:00:58.000
00:01:00.600
But what is the value you are getting
into that variable?

00:01:00.900
00:01:06.400
So that is important and one more
thing, let me disable my

00:01:06.400
00:01:07.600
gathering facts.

00:01:07.600
00:01:09.600
[no audio]

00:01:09.600
00:01:14.000
Gather facts: false. Now

00:01:14.000
00:01:16.100
let me save it be clear.
00:01:16.800
00:01:21.700
You are having a Playbook with Target
as localhost right

00:01:22.000
00:01:23.100
Now, I'm running that.

00:01:23.100
00:01:26.710
[no audio]

00:01:26.700
00:01:28.000
See the output what you are getting.

00:01:29.200
00:01:32.800
The inventory host name variable
value you're getting localhost.

00:01:32.800
00:01:33.900
What is this localhost?

00:01:33.900
00:01:37.600
Actually, your target. So simply
whenever if you are running

00:01:37.600
00:01:41.200
a Playbook, your playbook will
execute on multiple servers

00:01:41.200
00:01:42.800
based on the target section.

00:01:43.700
00:01:47.900
So, whatever it may be your inventory
host name is your target

00:01:47.900
00:01:48.800
names as of now.

00:01:48.800
00:01:51.800
Our target is only one server that is
localhost.

00:01:51.800
00:01:54.200
You are getting your inventory host
them as that local host.

00:01:54.700
00:01:58.900
Now let me modify target section
target.

00:01:59.000
00:02:02.800
Suppose all you know; we have two
servers in our inventory

00:02:02.800
00:02:06.000
file. That's why if You observe the
output, you're getting
00:02:06.200
00:02:09.500
your inventory hostname as your
target names.

00:02:09.699
00:02:12.699
So, while working with this server
automatically your Ansible

00:02:12.699
00:02:14.500
store into this variable.

00:02:14.500
00:02:18.700
This has the name same way while
working with this server

00:02:18.700
00:02:21.000
your inventory host name is the target
server name.

00:02:21.400
00:02:22.000
That's it.

00:02:22.300
00:02:26.400
So simply inventory host name is
always your target name.

00:02:26.900
00:02:34.300
Now, let me go and work with your
hostvarse. Let me write

00:02:34.500
00:02:35.700
first, let me do one thing.

00:02:35.700
00:02:37.399
[no audio]

00:02:37.399
00:02:45.800
I will take my target section as local
host and let me write

00:02:45.800
00:02:49.209
[no audio]

00:02:49.200
00:02:52.700
a simple task to display a hosyvars,
see the output what

00:02:52.700
00:03:00.700
you are getting. Just go to top an
observer that see in first

00:03:00.700
00:03:04.100
task. You are displaying the inventory
hostname or target

00:03:04.100
00:03:06.100
name in second task.
00:03:06.100
00:03:10.400
You are displaying hostvars further
your hostvars if you

00:03:10.400
00:03:14.500
observe you're having this server, but
this is not your target

00:03:14.500
00:03:17.700
server, right. Your target server is on
localhost, but see

00:03:17.700
00:03:20.200
the output in the host wires by default

00:03:20.200
00:03:23.500
you are getting all the servers and
information which is

00:03:23.500
00:03:28.800
there in your inventory file see that
localhost and these

00:03:28.800
00:03:30.200
two servers are there in my inventory.

00:03:30.200
00:03:34.100
That's why host wires by default will
fetch the information

00:03:34.100
00:03:37.800
of your all the servers which are
stored in your inventory

00:03:37.900
00:03:40.700
along with the server's variable values
as well.

00:03:40.700
00:03:42.359
[no audio]

00:03:42.350
00:03:48.300
Right fine now, but if you observe in
the output in your

00:03:48.300
00:03:54.300
output, you are running you're
Playbook with target as localhost.

00:03:54.800
00:03:57.100
But in your host where you are getting
the information about

00:03:57.100
00:04:01.500
all the servers, but I want to get only
the target server
00:04:01.500
00:04:05.700
information from my inventory file then
in that case simply

00:04:06.800
00:04:11.200
very simple just provide here your
inventory.

00:04:12.300
00:04:14.600
See, any way in your hostvars you are
going to get all the

00:04:14.600
00:04:17.899
servers, but I want to get only the
target server information

00:04:18.100
00:04:21.500
then filtrate hostvar, your inventory
hostname.

00:04:21.500
00:04:24.000
That's it now see the result.

00:04:25.600
00:04:29.100
See, in the output previously you got
in this output both

00:04:29.100
00:04:29.900
the servers.

00:04:30.900
00:04:32.900
I mean all the servers which are there
in your inventory

00:04:32.900
00:04:36.200
file, but now you are getting only the
target server host

00:04:36.200
00:04:37.300
vars information.

00:04:37.800
00:04:38.300
That's it.

00:04:39.800
00:04:41.800
Right and be clear.

00:04:41.800
00:04:43.550
[no audio]

00:04:43.550
00:04:46.800
If you observe here your host was
information is this much

00:04:46.800
00:04:51.600
information right very less lengthy
information but suppose,
00:04:51.600
00:04:57.700
you know whenever if you enable
gather facts by default,

00:04:57.700
00:05:00.400
you know you are set up module will
run whenever if you write

00:05:00.400
00:05:03.300
gather_facts = true or simply if you
remove this line.

00:05:04.500
00:05:08.600
and that set up module output will
store into Ansible facts

00:05:08.600
00:05:13.100
variable and if you want to display that
you have to debug

00:05:13.100
00:05:18.700
with very close to ansible_facts, but
whenever

00:05:18.700
00:05:21.600
if you are collecting your facts and
whenever if you're trying

00:05:21.600
00:05:26.400
to display hostvars, then your gather
facts will also store

00:05:26.400
00:05:29.700
into this hostsvars variable only you
don't need to write

00:05:29.700
00:05:39.800
any suck extra debug module just to
do display Ansible facts

00:05:40.000
00:05:42.100
first let me disable this line.

00:05:43.600
00:05:46.200
Right now, I am running this see the
result.

00:05:46.200
00:05:50.210
[no audio]

00:05:50.200
00:05:53.000
Gathering facts and that gathered
facts will be displayed

00:05:53.000
00:05:55.200
by your ansible facts variable.
00:05:55.500
00:05:57.800
If you remember already, we
discussed that in our previous

00:05:57.800
00:06:03.800
video. But whenever if you do display
hostvars by default,

00:06:03.800
00:06:07.000
you are gathering facts will also store
into your host

00:06:07.000
00:06:10.800
where's you don't need to write any
separate variable to

00:06:10.800
00:06:13.200
display your ansible facts.

00:06:13.400
00:06:17.100
What I am saying is, now let me
disable lost line.

00:06:18.700
00:06:22.700
This value, these variable values are
also automatically stored

00:06:22.700
00:06:25.300
into this variable now see the result.

00:06:26.600
00:06:33.200
Now, as of now you are displaying
only host verse but whenever

00:06:33.200
00:06:36.800
if you have gathered facts is true that
ansible facts values

00:06:36.800
00:06:39.700
you are getting that value is
automatically will store into

00:06:39.700
00:06:41.700
this host verse variable only.

00:06:42.200
00:06:44.500
That's what I am saying now see the
result.

00:06:48.600
00:06:54.500
See, the output. See along with you
are hostvars information.

00:06:54.900
00:06:58.700
You're also having in your hostvars
ansible facts as well.
00:06:58.900
00:07:00.700
That's it, right.

00:07:00.800
00:07:07.400
So be clear whenever if you have
Gather facts as true or

00:07:07.400
00:07:11.400
that time you're going to get ansible
facts variable, right?

00:07:11.400
00:07:14.200
You can display that variable to do see
your gather facts,

00:07:14.400
00:07:18.300
but if you are going to display only
hostvars, then automatically

00:07:18.300
00:07:20.700
that gather facts also store into this
variable.

00:07:20.700
00:07:25.000
You need to write any extra syntax to
display your ansible

00:07:25.000
00:07:27.100
facts. Right.

00:07:27.100
00:07:30.800
So, guys that is the simple information
about your inventory

00:07:30.800
00:07:33.000
hostname on hostsvars variable.

00:07:33.400
00:07:36.400
So, these are very very important
while writing your playbooks.

00:07:37.000
00:07:40.670
So, we will see the usage of this
inventory hostname and hostvars

00:07:40.670
00:07:43.010
effectively while writing our real-time
scripts.

00:07:43.000
00:07:44.700
We will see them while going forward.

00:07:44.700
00:07:47.200
Okay, thank you for watching this
video.

00:07:47.200
00:07:50.200
[no audio]
Transcript
00:00:00.000
00:00:01.900
Friends, here

00:00:01.900
00:00:06.000
our concept is how to install and use
Visual Studio code

00:00:06.000
00:00:10.900
Editor to write and run and we'll play
books CT now simply

00:00:10.900
00:00:15.700
we used Vai ter to write our answer
will play books.

00:00:16.100
00:00:17.200
Now first.

00:00:17.200
00:00:18.500
Let me show you that suppose.

00:00:19.100
00:00:21.100
I have a some demo dot.

00:00:21.100
00:00:23.200
Yml Playbook suppose.
00:00:23.200
00:00:25.400
I am I used viateur to write this play
book.

00:00:25.500
00:00:29.100
And after that how we are running our
playbooks simply on

00:00:29.100
00:00:29.800
our answer will come.

00:00:30.000
00:00:33.299
Stroller terminal and Sybil Playbook
than demo dot.

00:00:33.299
00:00:35.500
Yml so that you are going to execute
your playbook.

00:00:36.500
00:00:37.100
That's fine.

00:00:37.900
00:00:42.700
But now my intention is I want to use
some GUI editors to

00:00:42.700
00:00:46.500
write my answer will play book and
using that GUI editor.

00:00:46.700
00:00:48.500
I want to run my aunt's will pay book.

00:00:49.100
00:00:50.000
Then in that case.

00:00:50.000
00:00:54.200
You can go and use Visual Studio
code editor and we were

00:00:54.200
00:00:57.100
going to use visual stood Visual Studio
code later.

00:00:57.400
00:01:00.600
You should have a GUI access for
your server suppose.

00:01:00.600
00:01:04.599
If You observe here I have my ansible
controller on my VM

00:01:04.599
00:01:06.300
Ware. So directly.

00:01:06.300
00:01:08.100
I have a Geo access for This Server.
00:01:08.300
00:01:12.400
That's why I am going to work with
Visual Studio code editor

00:01:12.600
00:01:16.600
GUI editor suppose if you are not
having GOI access just

00:01:16.600
00:01:20.400
open your terminal and write your
playbooks with virvla meters

00:01:20.500
00:01:24.100
then run your playbooks in this way
and Civil Life and Playbook

00:01:24.100
00:01:25.200
then your playbook name.

00:01:25.400
00:01:25.900
That's fine.

00:01:26.800
00:01:31.400
So those who are having GOI axis for
your ansible controller

00:01:31.700
00:01:34.800
so they can go and proceed with this
installation and this

00:01:34.800
00:01:37.600
procedure. To write and run as will
play books.

00:01:38.800
00:01:42.300
And before going to work before going
to install and you

00:01:42.600
00:01:45.700
install this Visual Studio code later,
you should have a

00:01:45.700
00:01:49.000
root privileges or you should be the
root user to proceed

00:01:49.000
00:01:49.800
with steps.

00:01:51.000
00:01:54.300
Now I am giving here the steps to
install your Visual Studio

00:01:54.300
00:01:57.400
code editor and these steps are valid
for your scent wires
00:01:57.400
00:01:57.700
as well.

00:01:57.700
00:01:58.900
As or HL server.

00:01:59.600
00:02:03.000
The very first step is you need to
import Microsoft GPZ key

00:02:03.200
00:02:06.200
for your Visual Studio code later then
first.

00:02:06.200
00:02:08.400
Let me execute this Step 1.

00:02:09.199
00:02:11.600
So guys, I am going to provide directly
these steps on the

00:02:11.600
00:02:12.600
below of this video.

00:02:12.800
00:02:16.000
We just go through that and by using
them you can install

00:02:16.000
00:02:18.700
your Visual Studio code editor on your
server.

00:02:19.100
00:02:20.500
So this is the first step I done.

00:02:21.600
00:02:26.100
Then Second Step, you need to create
some repo for your Visual

00:02:26.100
00:02:27.100
Studio coordinator.

00:02:27.100
00:02:29.100
So for that just create one file.

00:02:30.800
00:02:31.900
By using this step.

00:02:33.900
00:02:35.100
Let me copy it.

00:02:37.400
00:02:38.100
What happened?

00:02:38.100
00:02:42.700
Yeah now here instead of Nano you
can use simply v8r as well.
00:02:43.700
00:02:48.300
If you have VI then just open that file
and copy and paste

00:02:48.300
00:02:50.400
the content whatever we have here.

00:02:50.700
00:02:54.400
So we need to copy this entire content
and you have to paste

00:02:54.400
00:02:55.400
it into this file.

00:02:56.300
00:02:56.800
That's it.

00:02:57.300
00:03:02.400
So then save it so that is a second
step then after second

00:03:02.400
00:03:05.500
step. Third step is just you have to
install your Visual

00:03:05.500
00:03:06.400
Studio code later.

00:03:06.400
00:03:06.700
Bye.

00:03:06.700
00:03:07.100
Bye run.

00:03:07.200
00:03:11.700
Simply yum install code but I am from
ants admin user.

00:03:11.700
00:03:13.000
That's why I'm using sudo.

00:03:15.700
00:03:18.800
So already I have that that's why it is
not installing simply.

00:03:18.800
00:03:21.300
It is saying already installed and latest
version.

00:03:22.500
00:03:22.800
Right.

00:03:22.900
00:03:25.700
So in your case will take some time to
install your Visual

00:03:25.700
00:03:26.600
Studio code later.
00:03:27.000
00:03:29.200
So once it is done, then you have to
open it.

00:03:30.000
00:03:32.500
So suppose as of now am this
location.

00:03:32.600
00:03:36.000
So you can open your Visual Studio
code editor from any of

00:03:36.000
00:03:36.800
your location.

00:03:37.100
00:03:38.200
Let's say I'm here right?

00:03:38.200
00:03:42.700
So simply run code space dot then
enter Then it is going

00:03:42.700
00:03:44.600
to open your Visual Studio code editor.

00:03:46.900
00:03:47.100
Right.

00:03:47.100
00:03:50.200
Once it is open anyway in the current
location, whatever

00:03:50.200
00:03:51.400
the files you are having.

00:03:51.900
00:03:55.100
So as of now, I've opened this Visual
Studio code later from

00:03:55.100
00:03:55.900
this location.

00:03:56.300
00:03:58.100
And in this location, I have different
files.

00:03:58.100
00:04:01.000
So all these files will open
automatically in your Visual

00:04:01.000
00:04:01.900
Studio code later.

00:04:03.100
00:04:03.300
Right.

00:04:03.300
00:04:06.600
So while practicing while writing
scripts it is very easy
00:04:06.900
00:04:09.000
so directly you can open your required
file.

00:04:10.100
00:04:10.700
That's fine.

00:04:11.600
00:04:14.900
Now just now we install Visual Studio
code enter.

00:04:15.100
00:04:18.600
Now the next step is I how to use this
Visual Studio code

00:04:18.600
00:04:21.300
editor for my aunt's will play books.

00:04:21.500
00:04:25.800
That's why you need to add your
required ansible extension

00:04:25.800
00:04:28.399
or Plugin for your Visual Studio code
later.

00:04:28.700
00:04:32.100
So for that what you have to do is
simply If You observe

00:04:32.100
00:04:35.500
here in the left side you how some
symbols right?

00:04:36.300
00:04:38.600
So I'm clicking here extensions.

00:04:39.100
00:04:41.600
So they're simply search with and
Sybil.

00:04:42.800
00:04:45.300
So once if you search the very first
you are going to get

00:04:45.300
00:04:48.000
ansible. So in my case, I already
installed this.

00:04:48.300
00:04:51.100
So in your case, you are going to get
option here install.

00:04:51.300
00:04:55.700
Like if you have their here for others
language ansible.
00:04:56.100
00:04:59.000
So install option is the right likewise,
you will get for

00:04:59.000
00:05:01.900
ansible plug in here install option will
be there.

00:05:03.300
00:05:07.100
Right, then once if it is installed just
click on settings.

00:05:11.700
00:05:20.800
configure extension settings Just let
me yeah, just simply

00:05:20.800
00:05:23.400
click on this ansible plug-in.

00:05:23.900
00:05:26.900
So it is going to open some
information about your aunt's

00:05:26.900
00:05:30.100
will plug in just to go down you have
some information if

00:05:30.100
00:05:31.600
you have some time just go through
that.

00:05:31.700
00:05:34.000
Otherwise straightforward just go
down.

00:05:35.300
00:05:35.800
Somewhere.

00:05:35.900
00:05:40.100
So here you have some information
like AML ansible just to

00:05:40.100
00:05:40.900
copy it.

00:05:42.100
00:05:45.300
So you need to add this information in
your associations

00:05:45.500
00:05:46.900
settings dot Json file.

00:05:47.700
00:05:51.000
So first of all after installing, your
aunt's will plug-in
00:05:51.000
00:05:54.600
just click on that so that you are going
to get this window

00:05:54.700
00:05:57.800
there somewhere you how this option
just to copy it.

00:06:00.000
00:06:01.500
Now, let me copy this.

00:06:02.800
00:06:08.400
So after that just go to file then
preferences then settings.

00:06:08.900
00:06:13.300
So they're simply search with Let me
type it.

00:06:15.000
00:06:18.500
Associations then you're going to get a
settings dot Json

00:06:18.500
00:06:19.400
file open it.

00:06:20.500
00:06:24.100
Then here you know in your case that
you will get empty curly

00:06:24.100
00:06:29.700
braces. So between that you just copy
and paste I mean paste

00:06:29.700
00:06:32.600
whatever the content you copied from
your plug-in simply

00:06:32.600
00:06:34.400
this line then save it.

00:06:35.500
00:06:36.000
That's it.

00:06:36.000
00:06:36.900
Then close it.

00:06:38.400
00:06:40.100
Close everything now.

00:06:40.100
00:06:43.900
I want to write a one ansible Playbook,
right?

00:06:44.000
00:06:46.100
So, you know whenever if you are
going to write your answer
00:06:46.100
00:06:49.400
will play book you need inventory and
you need your ansible

00:06:49.400
00:06:50.500
configuration file.

00:06:50.800
00:06:54.200
So where we are we are in this
location.

00:06:55.000
00:06:59.600
So in this location, we have our
ansible DOT c f g and we

00:06:59.600
00:07:01.500
have some where our inventory file.

00:07:03.000
00:07:05.400
I'd in this location only I am going to
write because I opened

00:07:05.400
00:07:07.700
my visual studio code editor from this
location.

00:07:08.200
00:07:10.100
Then these are the preferences for my
code.

00:07:11.500
00:07:12.600
Right see that.

00:07:12.900
00:07:15.200
I am writing a let me save it first.

00:07:19.100
00:07:26.000
Visual Studio code let me write first
Playbook.

00:07:27.100
00:07:32.800
From Visual Studio code later dot yml
save it enter.

00:07:33.300
00:07:37.200
Now your playbook name has given
as in this way, then try

00:07:37.200
00:07:39.900
to write your code start with three
hyphens.

00:07:39.900
00:07:45.300
Then Enter space - then provide your
target section suppose.

00:07:45.300
00:07:48.300
I am going to give all then simply.
00:07:48.300
00:07:49.200
Let me right.

00:07:50.900
00:07:56.500
Gather facts, I'm disabling see auto-
completion automatically

00:07:56.500
00:08:00.300
whenever if you are typing a code
ansible core in your Visual

00:08:00.300
00:08:01.100
Studio core.

00:08:01.100
00:08:02.200
It is giving Solutions.

00:08:02.300
00:08:04.700
You can select your required option
from here.

00:08:06.000
00:08:09.300
Gather facts false then let me right.

00:08:13.500
00:08:17.000
Tas section, so I am going to add a
task called you can take

00:08:17.000
00:08:18.000
any task suppose.

00:08:18.000
00:08:22.700
I am going to give simply debug task
as simply inventory

00:08:22.800
00:08:25.500
hostname. You know, what is
inventory hostname?

00:08:26.800
00:08:28.700
If you want to write any type of
Playbook, you can write

00:08:28.700
00:08:34.500
it then save it after saving just in your
keyboard, press

00:08:34.500
00:08:36.100
control shift to pee.

00:08:37.100
00:08:42.000
Are directly you in your editor in your
window right?

00:08:42.000
00:08:47.100
Click, then go to Lost option control
shift to pee then here
00:08:47.799
00:08:49.900
you are having different options.

00:08:50.600
00:08:54.400
Now, I need to run my playbook on my
local host on my controller

00:08:54.400
00:08:56.100
controller means localhost.

00:08:56.200
00:08:59.300
That's why I just searched very first
option run ansible

00:08:59.300
00:09:00.800
playbook in localhost.

00:09:01.200
00:09:01.700
That's it.

00:09:02.000
00:09:04.800
So automatically it is going to pick
your playbook name.

00:09:05.500
00:09:10.700
See that then enter if you enter it is
going to display the

00:09:10.700
00:09:12.200
command line simply.

00:09:12.400
00:09:16.000
So now if You observe here instead of
you your Visual Studio

00:09:16.000
00:09:19.500
code editor is running simply or
Playbook the way how we

00:09:19.500
00:09:22.200
are running from our command line in
that way your play.

00:09:22.200
00:09:24.000
You are a visual studio code editor will
run.

00:09:24.100
00:09:24.500
That's it.

00:09:25.600
00:09:27.800
But the advantage is here itself.

00:09:27.800
00:09:31.000
You can see your code along with your
output.

00:09:31.400
00:09:31.800
Yes.
00:09:31.800
00:09:32.400
That's it.

00:09:33.900
00:09:37.800
So guys this is the way how we can
install Visual Studio

00:09:37.800
00:09:40.700
code editor and how to write some
simple playbooks and how

00:09:40.700
00:09:42.700
to run right?

00:09:42.800
00:09:44.100
So on the below of this video.

00:09:44.100
00:09:47.100
I am going to provide the steps to
install a war which is

00:09:47.100
00:09:49.800
to the equator just go through that so
that you can install

00:09:51.000
00:09:54.700
So after writing your code here and
one more thing is be

00:09:54.700
00:09:57.400
clear whenever if you are opening
your Visual Studio code

00:09:57.400
00:10:01.400
later just to go to your terminal and in
which location you

00:10:01.400
00:10:05.400
have your inventory and ansible Dot
CSV file.

00:10:05.400
00:10:09.900
They're simply typed code dot code
space dot or else you

00:10:09.900
00:10:12.000
can also while saving your file.

00:10:12.000
00:10:14.600
You can also select your required
location to save instead

00:10:14.600
00:10:18.100
of that first open your terminal go to
your required location,
00:10:18.100
00:10:21.800
then they're type code space Dot and
enter so that your playbook

00:10:21.800
00:10:25.100
you are visual studio code editor will
open and automatically

00:10:25.400
00:10:28.200
the files which are there under that
location you will get

00:10:29.500
00:10:30.000
That's it.

00:10:30.800
00:10:31.100
Okay.

00:10:33.800
00:10:35.700
Okay guys, thank you for watching this
video.
Transcript
00:00:00.000
00:00:01.500
Friends here

00:00:01.500
00:00:05.400
our concept is how to perform
Arithmetic Operations using

00:00:05.400
00:00:06.700
Ansible Playbooks.

00:00:07.000
00:00:11.800
So, before going to work with this see
while working with

00:00:11.800
00:00:15.200
your automatic operators, your ansible
is following Jinja

00:00:15.200
00:00:17.700
syntax. So simply Jinja syntax is
nothing.

00:00:17.700
00:00:21.100
But if you remember while working
with the debug module to
00:00:21.100
00:00:24.400
display our variable value in our
message parameter of your

00:00:24.400
00:00:28.300
debug, we use two curly braces to
display your variable value.

00:00:28.600
00:00:30.300
This is nothing but simply Jinja syntax.

00:00:31.000
00:00:33.400
So, in most of the cases your ansible
is going to follow this

00:00:33.400
00:00:34.300
Jinja syntax.

00:00:34.700
00:00:37.300
Don't worry about that while practicing
you will come to

00:00:37.300
00:00:41.000
know when to use and one more thing
somewhere

00:00:41.000
00:00:45.400
I showed you how to install and use
Visual Studio coordinator.

00:00:46.000
00:00:46.800
Now instead of that

00:00:46.800
00:00:50.500
you can also use atom Editor to write
your playbooks.

00:00:51.100
00:00:54.800
So simply I am using atom Editor just
to write your playbooks.

00:00:54.800
00:00:59.300
Anyway, I will run my playbook from
my thermal only so in

00:00:59.300
00:01:03.100
case if you are getting confusion with
atom editor or Visual

00:01:03.100
00:01:06.200
Studio coordinator forget about these
two editors just use

00:01:06.200
00:01:07.400
Simple editor called VI.
00:01:07.400
00:01:11.200
then go and write your playbooks with
you with your VI

00:01:11.200
00:01:16.700
editor, that's fine now suppose if you
want to use a to atom

00:01:16.800
00:01:20.000
as your GUI editor then just to follow
these steps If You

00:01:20.000
00:01:24.600
observe these all steps are similar to
how we installed Visual

00:01:24.600
00:01:29.000
Studio coordinator, just follow that But
commands are different,

00:01:29.200
00:01:30.100
procedure is same.

00:01:30.800
00:01:33.300
So I am going to provide this
document on the below of this

00:01:33.300
00:01:36.300
video just download and install so
once if you install you

00:01:36.300
00:01:39.800
need to add some required extensions
or plug-ins for your

00:01:39.800
00:01:41.400
ansible in your atom editor.

00:01:41.900
00:01:44.600
So how to install I will show you that
first just open your

00:01:44.600
00:01:49.100
controller, ansible controller go to your
required practice

00:01:49.100
00:01:50.400
directory. There

00:01:50.400
00:01:54.800
just write atoms space . then enter. It
is going to open

00:01:54.800
00:01:56.100
your HTML editor.

00:01:57.200
00:01:58.600
So once it is open
00:01:58.600
00:02:00.300
[no audio]

00:02:00.300
00:02:05.000
go to your packages then there just to
go with your settings

00:02:05.300
00:02:08.500
there just to go with install packages
or themes click on

00:02:08.500
00:02:11.699
that. Then such package name simply
ansible.

00:02:11.699
00:02:14.009
[no audio]

00:02:14.000
00:02:17.300
So whatever the plugins you're going
to get here or extension

00:02:17.300
00:02:19.000
you're going to get just install them.

00:02:20.000
00:02:21.200
You just install all of them.

00:02:23.000
00:02:23.400
Right.

00:02:23.700
00:02:27.900
So, once it is done just to close your
all files whatever

00:02:27.900
00:02:32.900
Windows opened in your editor, then
go to file new file or

00:02:32.900
00:02:34.600
directly you can if you click here.

00:02:37.300
00:02:41.800
Yeah, file, new file then just save it.

00:02:44.000
00:02:46.300
Now here just write some Playbook
name.

00:02:48.100
00:02:58.709
Let's say arithmetic_open.yml. Thats
it.

00:02:58.700
00:03:01.700
So just now we create is simply a yml
file name. Now,
00:03:01.700
00:03:05.700
let me write or to show you your Jinja
syntax.

00:03:06.400
00:03:07.900
Let me write a simple Playbook.

00:03:08.400
00:03:13.000
So, --- then Enter space - let me write
a simple

00:03:13.000
00:03:23.600
name for your playbook play for
arithmetic Operators then

00:03:23.600
00:03:27.200
select your target as as of now I am
selecting all but anyway,

00:03:27.200
00:03:31.500
you know need to know need to select
all as your host because

00:03:31.500
00:03:33.600
we just learning Arithmetic Co-
operators.

00:03:33.700
00:03:37.300
I will show you that. Then after that
just write gather facts

00:03:37.300
00:03:40.900
as false then let me define a vars
section.

00:03:40.900
00:03:44.200
So, here I am going to define one
variable called X some value

00:03:45.100
00:03:48.900
and be clear see spaces underwear
section.

00:03:48.900
00:03:51.600
I am defining X, so that's why I am
giving one extra.

00:03:51.800
00:03:56.000
Is compared to where section then
after that just write tasks

00:03:56.000
00:04:01.900
section. So under tasks, you can
provide the name for your

00:04:01.900
00:04:02.600
task. Simply.
00:04:02.600
00:04:04.900
I'm writing displaying.

00:04:06.200
00:04:10.000
Values now, let me define two
variables.

00:04:10.000
00:04:14.100
Then that's fine for our automatic
operation practice.

00:04:14.300
00:04:18.800
Let's say some 34 number now see
that first of all, simply

00:04:18.800
00:04:22.899
I am displaying the values debug
under debug module.

00:04:22.899
00:04:25.000
I am selecting message parameter.

00:04:25.399
00:04:30.200
So, under that I am going to write
sequence of values.

00:04:30.500
00:04:33.500
I mean messages because I want to
display XY will be done

00:04:33.500
00:04:35.500
by value then in quotations.

00:04:36.300
00:04:41.400
“The value of x is : }”

00:04:41.400
00:04:43.500
This is called simply Jinja syntax.

00:04:44.200
00:04:46.300
So, to display our value with the help
of curly braces,

00:04:46.300
00:04:47.700
we are using two curly braces.

00:04:48.000
00:04:52.100
That's nothing but Jinja syntax, then I
want to display

00:04:52.100
00:04:58.800
“The value of y is : }”

00:05:01.100
00:05:01.600
That's it.

00:05:01.900
00:05:07.900
Save it go to your terminal then simply
run ansible Playbook
00:05:08.400
00:05:10.759
then your arithmetic_oper.yml

00:05:10.759
00:05:11.500
just observe that.

00:05:11.500
00:05:13.350
[no audio]

00:05:13.350
00:05:17.000
See, your task is displaying two times
because in our inventory

00:05:17.000
00:05:18.700
we have servers, two servers.

00:05:19.800
00:05:22.600
But anyway, here we are not
executing any task on your server.

00:05:22.600
00:05:25.800
See debug is nothing but it is not
going to execute tasks

00:05:25.800
00:05:27.000
on your manager notes.

00:05:27.200
00:05:30.400
Simply it will always execute on your
localhost only because

00:05:30.400
00:05:32.300
the buggy just to print the result.

00:05:33.600
00:05:36.100
Right, so that's why it is it will always
execute on your

00:05:36.100
00:05:40.400
localhost. So here just we are
practicing our automatic operators.

00:05:40.400
00:05:44.300
That's why just please select host as
always localhost while

00:05:44.300
00:05:46.400
practicing with your arithmetic
operators.

00:05:47.100
00:05:50.000
Anyway, if you want to work with the
real-time scripts or

00:05:50.000
00:05:52.400
the time based on your task, you need
to select your required
00:05:52.400
00:05:57.100
number of nodes right guys, one more
thing before going to

00:05:57.100
00:05:58.600
write your real-time script.

00:05:58.600
00:06:01.900
First of all, you should be good with
basics of your ansible

00:06:01.900
00:06:04.500
playbooks. So those concepts we are
discussing here.

00:06:05.800
00:06:07.700
Right, now let me rerun.

00:06:11.300
00:06:14.200
See, that the value of x we are getting
the value of why you're

00:06:14.200
00:06:15.300
getting now.

00:06:15.300
00:06:17.800
I want to perform the addition of these
two values

00:06:17.900
00:06:20.802
let's say simply I'm writing

00:06:20.802
00:06:31.059
“ } + } = }”.

00:06:31.059
00:06:32.900
So, guys because of this curly braces

00:06:32.900
00:06:36.300
of x, x value will be displayed, y value
will be displayed,

00:06:36.300
00:06:40.900
X Plus y result will be displayed
because of this then let

00:06:40.900
00:06:43.500
me write subtraction as well.

00:06:50.800
00:06:54.000
simply } - }. That's it.

00:06:54.000
00:06:57.600
Now, Let me go to your journal and let
me run your playbook see

00:06:57.600
00:06:58.300
the result.
00:06:59.700
00:07:11.210
} + }, } - } suppose if you perform "} - }
= }"

00:07:11.200
00:07:13.500
That's it clear, right?

00:07:14.800
00:07:20.200
the same way you can perform your
Multiplication let me do

00:07:20.200
00:07:20.600
one thing.

00:07:20.600
00:07:21.900
I will copy this line.

00:07:25.400
00:07:25.800
Sorry.

00:07:33.000
00:07:37.800
So, now I want multiplication of these
two numbers just simply

00:07:37.800
00:07:41.800
right. So guys this operations are very
very useful while

00:07:41.800
00:07:48.600
working with our real transcripts Now
let me find.

00:07:50.900
00:07:51.400
That's it.

00:07:51.400
00:07:52.100
Save it.

00:07:52.900
00:07:54.200
Let me run your playbook.

00:07:55.700
00:08:00.500
see that so directly your getting your
result in terms of float

00:08:00.500
00:08:01.600
Point. That's it.

00:08:01.700
00:08:05.100
Now, in case if you want to find any
reminder value then you

00:08:05.100
00:08:09.200
know in case if you want to find a
remainder of any values

00:08:09.400
00:08:10.800
just simply do percentile.
00:08:10.800
00:08:11.200
That's it.

00:08:11.700
00:08:16.000
So these are the simply arithmetic
operators in your ansible.

00:08:20.200
00:08:20.800
That's it.

00:08:21.100
00:08:21.800
Save it.

00:08:22.800
00:08:24.300
Bring your playbook on your terminal.

00:08:25.100
00:08:25.500
That's it.

00:08:27.900
00:08:28.909
So be clear. Yes,

00:08:28.900
00:08:31.400
I am using atom editor to write your
play books.

00:08:31.800
00:08:35.100
You can also use Visual Studio code
editor and directly.

00:08:35.100
00:08:37.100
I'm running our Playbook from our
command line only.

00:08:39.900
00:08:40.299
Right.

00:08:41.000
00:08:42.710
Okay guys, thank you for watching this
video.

00:08:42.700
00:08:44.100
These are the simple

00:08:45.799
00:08:48.700
Automatic operators using your
ansible playbooks.

00:08:48.700
00:08:51.700
[no audio]
Transcript
00:00:00.000
00:00:04.500
Friends now, we know that how to
perform arithmetic operations

00:00:04.500
00:00:08.300
using your Ansible Playbooks with the
help of Ginger syntax.

00:00:08.300
00:00:11.600
Now, we do some practice on your
arithmetic operators.

00:00:11.600
00:00:14.800
See if you remember, we can define
our variables in different

00:00:14.800
00:00:21.200
places. Right now based on that, how
can we do your operations.

00:00:21.200
00:00:28.900
Now, let me open a new file. Just save
it.
00:00:28.900
00:00:39.684
Let me do a Playbook name
practice_on_arithmetic.yml

00:00:39.684
00:00:42.800
See that. I am going to write a simple
Playbook

00:00:42.800
00:00:56.500
so name simply Practice on Arithmetic
Operators. That's fine.

00:00:56.500
00:01:00.648
Now, let me take target as local host.

00:01:00.648
00:01:06.500
Then let me disable gather_facts.
Then I am

00:01:06.500
00:01:10.350
going to define a variable section
simply vars, and under that

00:01:10.350
00:01:16.600
I am defining a first variable called x, x
equal to 45.

00:01:16.600
00:01:24.900
Then, I want to define y value, just by
adding some value to x.

00:01:24.900
00:01:32.200
You can do in this way y: "}"

00:01:32.200
00:01:34.400
See what I am doing is, for x

00:01:34.400
00:01:37.800
I'm adding number 5 and that adds
into the sum into Y.

00:01:37.800
00:01:39.500
Yes, you can do it.

00:01:39.500
00:01:44.300
Now let me write a simple tasks
section.

00:01:44.300
00:01:51.800
So I am writing debug, and I am using
the message parameter of debug.

00:01:51.800
00:01:59.500
Then I'm writing "The value of x is: }".
That's it.
00:01:59.500
00:02:02.613
We know that. How to display, how to
write your value

00:02:02.613
00:02:04.500
by using Ginger syntax.

00:02:04.500
00:02:08.699
And the value of y is: So already we've
done the x plus y, x plus

00:02:08.699
00:02:12.000
number 5 operation and we assign
that result to

00:02:12.000
00:02:14.753
our y variable in the line number 7.

00:02:14.753
00:02:17.700
Now we are displaying the Y value.
Now see that.

00:02:17.700
00:02:24.601
Let me go to your terminal, then run
Ansible Playbook.

00:02:24.601
00:02:28.600
Practice on arithmetic.yml. See the
result.

00:02:28.600
00:02:33.500
See that x is 45, but why is 50. So in
that section also, you

00:02:33.500
00:02:35.000
can perform your operations.

00:02:35.000
00:02:38.600
But while we're doing that perform
operations,

00:02:38.700
00:02:41.144
we need to use curly braces. That's it.

00:02:41.144
00:02:50.000
This is one way. Now, I will keep this
as it is.

00:02:50.000
00:02:52.700
I will do one more thing.

00:02:52.700
00:02:57.300
Suppose I want to read a variables
from your command line.

00:02:57.300
00:02:58.700
I mean while running your Playbook,
00:02:58.700
00:03:01.800
I want to read variables. Then, if you
remember,

00:03:01.800
00:03:06.100
we have a vars prompt section.

00:03:06.100
00:03:09.600
Then under that, suppose I want to
read some variable value.

00:03:09.600
00:03:14.199
Let's say any number. Let's say a.

00:03:14.199
00:03:17.000
Then I am giving for your variable
name as ah.

00:03:17.000
00:03:21.400
You can read any number of variables.

00:03:21.400
00:03:25.878
Name is a, then prompt. What is the
message you want to display

00:03:25.878
00:03:29.347
on your command line to read your
value.

00:03:29.347
00:03:36.800
I'm writing Please enter a variable
value.

00:03:36.800
00:03:44.500
So, I will do one thing. Step by step.

00:03:44.500
00:03:50.100
I will save this to Playbook and I will
share all those Playbooks.

00:03:50.100
00:03:52.637
Let me copy this. This is the very first
Playbook

00:03:52.637
00:03:59.000
just simply to understand. Let me save
here. This is one Playbook.

00:03:59.000
00:04:02.900
So guys while practicing, just observe
this line, and

00:04:02.900
00:04:08.433
up to that it's one Playbook, just to
copy this Playbook and try practice.
00:04:08.433
00:04:11.200
Next, I am going to paste here one
more Playbook.

00:04:11.300
00:04:13.894
So before that, let me write a
Playbook.

00:04:13.894
00:04:19.899
Here let me remove, vars_prompt
section.

00:04:19.899
00:04:27.500
Suppose I want to read 2 variables.
So I will do one thing.

00:04:27.500
00:04:30.600
Of course, you can also keep your
vast section, no problem.

00:04:30.600
00:04:34.467
I will do name, I want to read X.

00:04:34.467
00:04:38.200
Then, prompt. What is the message
on your command line

00:04:38.200
00:04:42.000
you want to display while reading your
variable x.

00:04:42.000
00:04:46.800
So I am writing simply Please enter x
value.

00:04:46.800
00:04:50.300
So remember, you have to write
private as no, then only

00:04:50.300
00:04:54.000
you're value, while typing on your
terminal, that value will be displayed.

00:04:54.000
00:04:58.400
Otherwise, it will hide. Now that is for
your first variable.

00:04:58.400
00:05:01.300
Suppose if you want to read multiple
variables then, just

00:05:01.300
00:05:04.100
use as sequence of values first value

00:05:04.100
00:05:09.200
then -. Then second value, simply use
one more -. Then name.
00:05:09.200
00:05:14.400
I want to read y variable. Then write
some prompt message.

00:05:14.400
00:05:19.100
Now, instead of Enter, simply I'm
writing Enter y values.

00:05:19.100
00:05:26.400
Then, write private as no. Otherwise
this value won't be displayed.

00:05:26.400
00:05:33.700
You just execute without private no,
simply by writing private yes.

00:05:33.700
00:05:36.000
Now I am displaying all those values.

00:05:36.000
00:05:38.800
Let me save it first and go to your
command line.

00:05:38.800
00:05:42.000
Let me run your Playbook and see the
result.

00:05:42.000
00:05:56.900
[muttering]

00:05:56.900
00:06:01.900
Now that we need our practice. Yeah
this one.

00:06:01.900
00:06:04.300
See that, it is asking to enter your x
value.

00:06:04.300
00:06:08.500
Let's say some number, any number, y
value some number.

00:06:08.500
00:06:10.800
See the result. We are getting 5 and 9.

00:06:10.800
00:06:14.600
But here I am trying to find any one of
the arithmetic operator.

00:06:14.600
00:06:25.012
Let's say the addition of, I'm writing
"The addition of }

00:06:25.012
00:06:34.757
whatever the value you're providing
and } is }.
00:06:34.757
00:06:36.800
See the result that you are getting.

00:06:36.800
00:06:40.400
Let's say some number 4 and 5.
You're getting your value

00:06:40.400
00:06:46.400
is 45, x + y, 4 + 5. 9 you have to get,
but you're getting 45.

00:06:46.400
00:06:52.162
So actually, whenever you read a
value using prompt section,

00:06:52.162
00:06:55.500
by default, that is a string value.

00:06:55.500
00:06:58.300
That's why you're getting, whenever
you do concatenation

00:06:58.300
00:07:02.449
of 2 strings, you are going to get it like
this.

00:07:02.449
00:07:07.100
If you re-enter your value, let's say I'm
entering

00:07:07.100
00:07:12.589
x value as a and y value as b. See the
result, a b you're getting.

00:07:12.589
00:07:14.400
And we will discuss about string
operations separately.

00:07:14.400
00:07:18.800
So as of now, just remember that,
prompt is going to read always

00:07:18.800
00:07:22.800
your values as a string. But you need
them as, I suppose, integers.

00:07:22.800
00:07:27.200
Then, before going to perform your
arithmetic operations,

00:07:27.200
00:07:33.748
see that I am doing a pipeline integer
plus pipeline integer.

00:07:33.748
00:07:36.700
I'm converting our values into integers.
00:07:36.700
00:07:42.500
Now let me run it and see the result.

00:07:42.500
00:07:47.000
[muttering]

00:07:47.000
00:07:51.754
I'm entering numbers 5, 6, 11.

00:07:51.754
00:07:54.400
Right, so to be clear, whenever you
read your numbers with

00:07:54.400
00:07:57.300
the help of prompt and if you want to
treat them as numbers,

00:07:57.300
00:08:02.000
you need to convert them based on
your required type of data,

00:08:02.000
00:08:05.400
integer or float. So this is the way

00:08:05.400
00:08:08.600
you can read your numbers. And in
the same section,

00:08:08.600
00:08:10.800
you can also provide vars section. No
problem.

00:08:10.800
00:08:17.100
Vars, so I am writing here let's say a
value. A value as number 56.

00:08:17.100
00:08:24.613
I'm finding that just after the last output
in this case,

00:08:24.613
00:08:33.400
"The a - y }".

00:08:33.400
00:08:35.000
So, just for understanding purposes,

00:08:35.000
00:08:38.400
I am displaying a and y. If you want
display values,

00:08:38.400
00:08:42.261
then you can write it, curly braces of a
and curly braces of y.

00:08:42.261
00:08:46.958
Now let me run. So I am giving values
as 4 and 5.
00:08:46.958
00:08:49.900
Now see the result, something's
wrong.

00:08:49.900
00:08:53.053
[muttering]

00:08:53.053
00:08:55.700
So why is not an integer right. X is an
integer.

00:08:55.700
00:08:58.610
Sorry, a is an integer, y is not an
integer.

00:08:58.610
00:08:59.500
You are reading through prompt.

00:08:59.500
00:09:02.100
That means y will be treated as a
string.

00:09:02.100
00:09:05.900
So while performing you're operations,
you need to convert

00:09:05.900
00:09:12.000
that as integer. That's it. Now see the
result.

00:09:12.000
00:09:18.400
I'm going to give same values 4 and 5.
Now it is going to work.

00:09:18.400
00:09:21.232
[muttering]

00:09:21.232
00:09:24.500
We're getting 51. What is the a value?

00:09:24.500
00:09:28.252
Yeah, 56. 56 minus 5. 51 that's fine.

00:09:28.200
00:09:34.102
So just to get clarity. Let me write here
now.

00:09:34.102
00:09:41.220
So, please do practice the same
script, so you will get the idea.

00:09:41.220
00:09:47.400
That's it. 56 minus 2, result is 54.
That's it.

00:09:47.400
00:09:50.600
So this is the way of how you can read
your variables and how
00:09:50.600
00:09:54.100
you can define your variables inside of
your script itself,

00:09:54.100
00:09:56.200
or in your Playbook itself, right.

00:09:56.200
00:09:58.900
So, let's assume this is the second
Playbook.

00:09:58.900
00:10:02.000
Now, we know that we can also define
our variables in any

00:10:02.000
00:10:05.185
one of the files. Right.

00:10:05.185
00:10:08.000
That's why I'm going to take one extra
ml file.

00:10:08.000
00:10:16.500
So I am writing here 2 variables. Let's
say different variables.

00:10:16.500
00:10:23.321
Oh, yeah, we can keep it as x : 56 and
y : 90. That's it.

00:10:23.321
00:10:26.246
Now, let me save it. Save it as

00:10:26.246
00:10:32.048
my_vars. Already we have that, no
problem. Replace.

00:10:32.048
00:10:38.400
So we have my_vars.yml file. And in
that we 2 variables.

00:10:38.400
00:10:41.700
So, we are defining our variables in a
file.

00:10:41.700
00:10:45.400
So don't forget to write these 3
hyphens. And we define

00:10:45.400
00:10:49.900
2 variables. Now let me modify this
code and where we

00:10:49.900
00:10:54.350
have those variables, let me remove
them, this vars section.
00:10:54.350
00:10:55.800
Now, we don't have them right now.

00:10:55.800
00:11:00.400
Let me simply remove these 2 things.

00:11:00.400
00:11:04.900
Now, we need to read our variables
from a file my_vars.yml.

00:11:04.900
00:11:07.800
So if you want to read variables from
any file, we have

00:11:07.800
00:11:10.800
a section called vars file section.

00:11:10.800
00:11:16.500
So under that just enter, space,
hyphen. Then right where you are

00:11:16.500
00:11:23.500
my_vars.yml file. So, in case your

00:11:23.500
00:11:25.800
variable file is there, in the different ?
luggage?, just provide

00:11:25.800
00:11:28.428
the complete path. That's it.

00:11:28.428
00:11:29.700
Now I am going to run our Playbook.

00:11:29.700
00:11:33.600
So before we're going to run, see that
your variable values are 56 and 90.

00:11:33.600
00:11:36.228
Now, you have to get your values as
56 and 90.

00:11:36.228
00:11:41.445
Yes. You are getting them. What is the
type.

00:11:41.445
00:11:44.700
You know, somewhere we discussed
how to display type of your

00:11:44.700
00:11:52.967
variable. Simply pipeline type_debug.

00:11:52.967
00:11:57.306
Now, let me run this and see the
output, integer. That's it. Fine.
00:11:57.306
00:12:00.700
And we can also pass our variables
from command line, right.

00:12:00.700
00:12:05.984
Now, let me do one thing. I'm going to
come and do these 2 lines.

00:12:05.984
00:12:11.103
[muttering]

00:12:11.103
00:12:18.200
I will save this Playbook also. So that it
will be useful for you.

00:12:18.200
00:12:22.700
So, let's practice in this third Playbook.
Somewhere, in

00:12:22.700
00:12:27.177
any file name, as my_vars.yml.

00:12:27.177
00:12:33.600
In that file, just define your x and y
variables. All right, that's it.

00:12:33.600
00:12:37.400
Now let me go with the last Playbook,
just to get clarity on your

00:12:37.400
00:12:39.954
variables. So now what I am doing to
do is, I am going to

00:12:39.954
00:12:44.000
remove this vars file section.

00:12:44.000
00:12:47.500
Now, we don't have any variables.
Now I am going to run.

00:12:47.500
00:12:49.000
Anyway, you're going to get an error.

00:12:49.000
00:12:53.000
That is, your variables are not defined.

00:12:53.000
00:12:57.299
X is undefined and y is undefined. But
my intention is, I want to pass

00:12:57.299
00:13:01.500
these 2 variables from command line,
as a command line argument.

00:13:01.500
00:13:05.900
Then -e, x equals some number, then
y equals
00:13:05.900
00:13:08.300
some number. If you remember,
somewhere we discussed about

00:13:08.300
00:13:11.920
command line arguments. That's it.

00:13:11.920
00:13:15.600
These are the different ways to pass
your variables and to

00:13:15.600
00:13:18.300
work with your Playbooks. Okay.

00:13:18.300
00:13:23.200
So this is a simple practice with your
arithmetic operations

00:13:23.200
00:13:25.623
using your Ansible Playbooks. Okay.

00:13:25.600
00:13:29.000
Thank you for watching this video.
Transcript
00:00:00.000
00:00:04.700
Friends here or concept is filters and
methods of ansible

00:00:04.700
00:00:08.000
playbooks. See we have different
types of variables in our

00:00:08.000
00:00:10.900
ansible and we know that we can
store different types of

00:00:10.900
00:00:14.600
data into them and while working with
your playbook.

00:00:14.600
00:00:18.300
Sometimes you need to perform some
operations on your variables

00:00:18.300
00:00:22.100
and you need to get your required
result from them now to
00:00:22.100
00:00:27.000
perform operation operations on your
variables if we have

00:00:27.000
00:00:32.700
filters and methods so now simply
filters on methods of operations

00:00:32.700
00:00:36.700
on your variables But Here There is a
small difference between

00:00:36.700
00:00:41.400
filters and methods so filters or
operations from your ansible

00:00:41.600
00:00:48.300
or Ginger to syntax and methods or
from your python see sometimes

00:00:48.300
00:00:53.300
you can find your required operations
from your ansible syntaxes

00:00:53.300
00:00:57.700
itself, but if you are not able to find
your required operation

00:00:57.700
00:01:02.000
in your ansible or ansible sin taxes,
then we can also use

00:01:02.000
00:01:06.099
Python methods or python or A
chance that's it.

00:01:06.800
00:01:11.200
So filters or from your ansible inbuilt
and methods or from

00:01:11.200
00:01:12.000
your python.

00:01:13.200
00:01:16.100
So other than that, there is no
difference both are just

00:01:16.100
00:01:18.600
to perform some operations on your
variables.

00:01:19.400
00:01:22.200
But while using your filters and
methods you need to remember
00:01:22.200
00:01:26.300
these two points, if you are going to
use ansible filters

00:01:26.600
00:01:29.900
or Ginger 2 filters, then you have to
use Pipeline on your

00:01:29.900
00:01:32.500
variable. So how do you use I will
show you.

00:01:33.500
00:01:34.500
At the same time suppose.

00:01:34.500
00:01:38.100
If you are going to use Python
methods to perform your operation

00:01:38.200
00:01:39.000
on your variable.

00:01:39.000
00:01:40.900
Then you have to use dot now.

00:01:40.900
00:01:43.900
Let me explain them with the help of
simple examples.

00:01:45.800
00:01:48.600
So I am going to open a 2m editor.

00:01:51.900
00:01:54.200
What is going to open your HTML
editor?

00:01:58.100
00:02:00.900
Now, let me write a simple Playbook.

00:02:01.200
00:02:05.500
So let me close all these windows go
to file new file.

00:02:06.800
00:02:08.000
Just give some name.

00:02:10.699
00:02:16.500
Operations using filters and methods
Dot.

00:02:16.500
00:02:21.700
Yml So let me start writing our
Playbook.

00:02:22.000
00:02:27.000
So I am giving Target as simply
localhost then let me write
00:02:27.000
00:02:30.800
gather facts as false.

00:02:32.000
00:02:35.200
And then let me Define some variable.

00:02:35.300
00:02:39.200
Let's say how X variable and in this I
have information like

00:02:39.200
00:02:46.100
this. This is about.

00:02:47.400
00:03:00.200
and symbol filters and methods just I
have taken my x value

00:03:00.200
00:03:00.800
in this way.

00:03:01.400
00:03:01.700
Now.

00:03:01.700
00:03:05.300
I want to display this x then you can
go with your debug

00:03:05.600
00:03:09.400
module and just select your message
parameter from that and

00:03:09.400
00:03:14.600
I am writing here simply your variable
X so, you know in

00:03:14.600
00:03:17.400
curly braces if you write your ex then
that is simply Ginger

00:03:17.400
00:03:18.200
syntax, right?

00:03:19.600
00:03:23.300
Let me run this from your command
line simply ansible Playbook

00:03:23.600
00:03:26.500
operations using filters and methods
see the result what

00:03:26.500
00:03:27.100
you are getting.

00:03:30.100
00:03:30.900
Right second time.

00:03:30.900
00:03:32.500
Yeah, let me do one thing.
00:03:33.300
00:03:35.600
So I don't you gather facts Falls, right?

00:03:39.300
00:03:40.300
Now, let me run this.

00:03:41.700
00:03:46.200
Yeah, now see the result your variable
value X you're getting

00:03:46.200
00:03:49.900
in this way, but this is not in the proper
way, right because

00:03:49.900
00:03:54.200
it is the combination of capital small
and in the random

00:03:54.200
00:03:55.300
order, right?

00:03:55.500
00:04:01.100
I mean, I want to get this entire string
in lower case letters

00:04:01.600
00:04:03.700
then see that simply.

00:04:04.200
00:04:09.100
There is a operation from your ansible
or filter and there

00:04:09.100
00:04:14.300
is a ansible filter to You are string into
lower case now.

00:04:14.300
00:04:18.500
If I write in this way now, we can say
that on our X variable.

00:04:18.700
00:04:23.899
We applied an operation called Lower
by using lower filter.

00:04:24.000
00:04:24.500
That's it.

00:04:25.300
00:04:25.500
Now.

00:04:25.500
00:04:29.700
Let me save it and run it now see the
result you're getting

00:04:29.700
00:04:32.300
your entire string in lowercase now.
00:04:32.300
00:04:35.200
I want to get the same string in upper
case as well then

00:04:35.200
00:04:37.600
apply uppercase filter.

00:04:39.500
00:04:40.000
That's it.

00:04:40.000
00:04:40.100
Now.

00:04:40.100
00:04:42.900
This is called uppercase filter.

00:04:43.100
00:04:43.400
Nothing.

00:04:43.400
00:04:45.200
Is there simply simply sum operation?

00:04:46.100
00:04:46.600
That's it.

00:04:48.000
00:04:50.500
No, I want to get in the form of title
format.

00:04:50.900
00:04:55.700
Yes, you can see that X pipeline
tightly.

00:04:57.600
00:04:59.100
Now, let me run see the result.

00:05:00.600
00:05:02.300
Title means in each and every word.

00:05:02.300
00:05:04.200
The first letter is capital.

00:05:04.400
00:05:06.000
The first character is capital.

00:05:06.000
00:05:06.500
That's it.

00:05:08.100
00:05:11.100
Now suppose these are some of the
very simple operations

00:05:11.100
00:05:15.600
from your ansible or Ginger to
template now same operations.

00:05:15.600
00:05:19.400
I can also perform using python see
that x dot lower.
00:05:19.500
00:05:22.500
If you know python you can easily
understand this x dot lower.

00:05:24.700
00:05:28.000
See, I used her parentheses x dot
lower now.

00:05:28.000
00:05:29.600
Let me run this and see the result.

00:05:32.200
00:05:36.200
Now last output is x dot lower the
same way can apply x dot

00:05:36.200
00:05:37.300
lower parentheses.

00:05:37.600
00:05:41.600
But here these are python operations
see the difference in

00:05:41.600
00:05:42.900
first three operations.

00:05:42.900
00:05:46.200
I used pipeline, but here I use Dot and
then I provide here

00:05:46.500
00:05:47.600
parentheses symbol.

00:05:47.700
00:05:48.500
That is the difference.

00:05:48.500
00:05:52.000
There is the python syntax or python
method.

00:05:52.200
00:05:53.900
So there is an operation called
suppose.

00:05:53.900
00:05:54.800
Yeah upper.

00:05:56.800
00:05:57.200
That's it.

00:05:57.700
00:06:00.700
No, let me run and see the last output
you're going to get

00:06:00.700
00:06:03.400
a output in all are in capital letters.

00:06:03.600
00:06:04.100
That's it.
00:06:06.000
00:06:08.900
Right, and I will do one more thing
suppose.

00:06:08.900
00:06:10.700
I am going to Define a variable called.

00:06:11.900
00:06:13.300
Let's say 56.

00:06:15.200
00:06:17.900
Now suppose if I try to display the
value of your ex.

00:06:19.100
00:06:22.000
You know that is basically a number
but I provide inside

00:06:22.000
00:06:22.900
of a quotations.

00:06:22.900
00:06:23.500
That's why now.

00:06:23.500
00:06:24.800
Why data is a string.

00:06:26.100
00:06:28.300
But I want to convert that into.

00:06:29.700
00:06:32.600
Integer, then apply integer filter.

00:06:32.900
00:06:36.300
If you remember in our previous video
we use this filter

00:06:36.600
00:06:38.800
but there without saying filter concept
simply.

00:06:38.800
00:06:43.200
I told that you can convert your string
into integer by using

00:06:43.200
00:06:45.000
this NT operation.

00:06:45.200
00:06:47.700
Actually there is a filter filters of the
mode again operation

00:06:47.700
00:06:54.300
only. right now suppose let us say a
highway.

00:06:54.900
00:06:57.500
Yeah, let me run this first and see the
result.
00:06:59.000
00:07:00.400
Now what happened?

00:07:01.800
00:07:04.900
X sorry, that is why I write X is string.

00:07:07.600
00:07:08.000
Why?

00:07:09.900
00:07:10.900
Now see the result.

00:07:12.000
00:07:12.500
That's it.

00:07:12.500
00:07:12.600
Now.

00:07:12.600
00:07:14.000
This is a integer value.

00:07:15.300
00:07:16.100
Anyway, that's fine.

00:07:16.200
00:07:16.700
Now.

00:07:16.700
00:07:20.200
I am going to Define one more
variable called Z for that.

00:07:20.200
00:07:21.700
I am giving some values.

00:07:25.200
00:07:31.400
now suppose I want to find the
Minimum or maximum values

00:07:31.400
00:07:38.100
from your Z see that the Max from
your required variable

00:07:38.200
00:07:41.800
is just apply first of all in this way.

00:07:41.800
00:07:46.700
You are variable pipeline Max the
same we can find minimum

00:07:46.700
00:07:47.400
value as well.

00:07:49.100
00:07:55.100
The minimum from Z is pipeline
minimum.

00:07:55.600
00:07:58.600
So now I use minimum and maximum
filters on your variable
00:07:58.600
00:07:59.300
called Z.

00:08:00.300
00:08:00.400
Now.

00:08:00.400
00:08:02.600
Let me run this and see the result
what you are getting.

00:08:04.200
00:08:07.800
See in your entire variables are 38 is
the maximum number

00:08:08.000
00:08:11.800
you're able to find that and then 0 is
the minimum number?

00:08:11.800
00:08:15.100
Yes that we are able to find by using
your ansible filters

00:08:15.100
00:08:17.100
or inbuilt filters of your ansible.

00:08:18.100
00:08:18.500
Right.

00:08:18.700
00:08:22.500
So these are simply filters and
methods concept is nothing

00:08:22.500
00:08:23.000
is there.

00:08:24.400
00:08:28.300
Filters are methods or simply
operations to perform on your

00:08:28.300
00:08:32.799
variables based on your requirement
and guys first try to

00:08:32.799
00:08:36.500
go on use always your ansible filters in
case if you are

00:08:36.500
00:08:40.700
not able to find your required
operation from your ansible

00:08:40.700
00:08:44.700
or in build filters of your ansible, then
try to use your

00:08:44.700
00:08:46.299
python suppose.
00:08:46.299
00:08:50.900
Let us say x is there is a split reg ex
operation in your

00:08:50.900
00:08:54.700
ansible to split a string but directly
there is no split

00:08:54.700
00:08:57.800
operation in your ansible to split your
screen.

00:08:58.000
00:09:00.900
See my intention is I am trying to split
this.

00:09:02.900
00:09:04.200
I'll see the output last line.

00:09:05.000
00:09:06.000
You're getting somewhere else.

00:09:06.800
00:09:09.200
No filter name split.

00:09:09.800
00:09:13.200
Let me try with suppose just
parentheses as well.

00:09:16.400
00:09:19.800
Right, there is no filter that split but
you know in Python

00:09:19.800
00:09:24.300
we have split right then do dot x dot
split.

00:09:25.300
00:09:26.300
Now see the result.

00:09:28.200
00:09:32.200
You got your output in terms of a list,
you know whenever

00:09:32.200
00:09:34.800
if you split a string you're going to get
output as a list

00:09:34.800
00:09:35.500
in your python.

00:09:35.500
00:09:36.700
Same thing here also.

00:09:40.500
00:09:41.000
Right.
00:09:41.300
00:09:43.700
She actually directly there is no split
operation in your

00:09:43.800
00:09:45.300
default ansible filter.

00:09:45.400
00:09:46.900
That's why I use Python filter.

00:09:48.500
00:09:51.800
So guys if you know python very, well
not even I mean very

00:09:51.800
00:09:54.700
well just if you know the basics basic
operations from your

00:09:54.700
00:09:56.400
python, then ansible is very easy.

00:09:57.700
00:10:00.900
Okay, so in case if you don't know
python it's better to

00:10:00.900
00:10:02.900
concentrate on your python as well.

00:10:03.400
00:10:04.300
Okay, that's fine.

00:10:04.600
00:10:10.500
Now, let me show you some of the
You are the ansible in build

00:10:10.500
00:10:11.700
filters. See just now.

00:10:11.700
00:10:13.500
I have given very Basics.

00:10:14.400
00:10:18.500
Let me simply search with ansible
inbuilt.

00:10:19.700
00:10:21.000
Filters, that's it.

00:10:22.200
00:10:25.700
Just open very first link and if You
observe here you are

00:10:25.700
00:10:29.600
having different types of filters based
on your requirement.

00:10:29.800
00:10:32.700
So as of now, what you have to do is
just to open each and
00:10:32.700
00:10:37.000
every filter and see the list of
operations from each and

00:10:37.000
00:10:41.000
every filter and while working with the
real-time you will

00:10:41.000
00:10:44.400
get some idea based on your
requirement which filter we have

00:10:44.400
00:10:50.400
to use So guys for time being just go
with some of the or

00:10:50.400
00:10:52.800
if you have some time just go with one
by one filter.

00:10:53.500
00:10:56.800
See we use this minimum and
maximum, right?

00:10:56.800
00:11:00.400
If you want to create a single list from
this murder inside

00:11:00.400
00:11:01.800
a recursive list.

00:11:01.800
00:11:05.900
You can also use this operation to get
your list.

00:11:06.500
00:11:09.600
So likewise you have different types of
operations just go

00:11:09.600
00:11:10.600
through them one by one.

00:11:10.800
00:11:14.100
Don't try to learn them just have a look
on that so that

00:11:14.100
00:11:20.400
you will get idea how to use filters And
one more thing I

00:11:20.400
00:11:24.400
want to show you here see in the after
completion of your

00:11:24.400
00:11:25.600
list of filters here.
00:11:25.900
00:11:27.300
There is a built-in filter side.

00:11:27.300
00:11:28.200
Just click on this.

00:11:29.700
00:11:33.500
And see that you are going to get
some ginger 2 filters.

00:11:37.900
00:11:40.500
If there is a capitalized operation
nothing is there simply

00:11:40.500
00:11:44.200
it is going to make the first character in
to uppercase.

00:11:45.000
00:11:46.200
Just have a look on them.

00:11:47.500
00:11:49.500
Don't try to learn them just have a
look.

00:11:50.000
00:11:52.900
Anyway, you will learn while writing our
playbooks.

00:11:54.100
00:11:54.500
Okay?

00:11:54.700
00:11:55.200
Okay guys.

00:11:55.200
00:11:56.400
Thank you for watching this video.
Transcript
00:00:00.000
00:00:01.932
Friends, here our concept is

00:00:01.932
00:00:06.301
comparison or relationship operators
of Ansible Playbooks.

00:00:06.301
00:00:08.900
See, in this comparison or relationship
operators are

00:00:08.900
00:00:12.300
very very important to work with
conditional operators in

00:00:12.300
00:00:16.700
your Playbooks. And the result of
comparison or relationship

00:00:16.700
00:00:20.400
operators is always either true or
false.

00:00:20.400
00:00:24.200
First, let me give you the list of
comparison operators. And these
00:00:24.199
00:00:28.699
operators are very similar to your
Python comparison operators.

00:00:28.700
00:00:31.900
See like equal, not equal, greater
than, less than, greater than

00:00:31.900
00:00:35.000
or equal to, less than or equal to. And
one more important

00:00:35.000
00:00:36.600
point is, these same operators

00:00:36.600
00:00:40.300
you can use for your strings as well as
numbers.

00:00:40.300
00:00:45.300
Let me explain all these operators with
the simple Playbook.

00:00:45.300
00:00:51.399
So, let me log in into my Ansible
controller.

00:00:51.400
00:00:56.600
Let me open my terminal. So here I'm
going to move into my

00:00:56.600
00:01:01.000
practice directory.

00:01:01.000
00:01:06.599
And here I am going to open a simple
Playbook.

00:01:06.599
00:01:11.478
Yeah, I will do one thing. I will write a
code in your atom editor.

00:01:11.478
00:01:16.535
So, let me open your atom editor.
Simply write atom space dot

00:01:16.535
00:01:20.800
In the current location it is going to
open your atom editor. Just wait.

00:01:20.800
00:01:29.100
It will take some time. Yeah, it's
opening.

00:01:29.100
00:01:34.100
Now, let me create a new file here.
00:01:34.100
00:01:44.700
First close all my existing windows.
Let me save

00:01:44.699
00:01:53.300
it a name as
comparison_operators.yml

00:01:53.300
00:01:56.599
So, now we are writing a simple
Playbook to understand the

00:01:56.599
00:01:58.899
comparison operators.

00:01:58.899
00:02:03.022
Let me start with the name as

00:02:03.022
00:02:10.223
Working with comparison operators.
So I am selecting host as

00:02:10.223
00:02:13.699
localhost and I don't want to gather
facts.

00:02:13.699
00:02:21.399
So, I'm writing gather_facts as false.

00:02:21.399
00:02:26.500
Then let me write a simple variable. I
will define 2 variables.

00:02:26.500
00:02:31.999
Let's say x is some number and then
let's say y is 10.

00:02:31.999
00:02:34.399
Now, I am defining tasks.

00:02:34.399
00:02:37.300
So in my task I'm taking debug.

00:02:37.300
00:02:40.355
So in debug I am taking a message
parameter.

00:02:40.355
00:02:42.379
So in message parameter,

00:02:42.379
00:02:45.159
I am going to display the different
types of your

00:02:45.159
00:02:47.700
comparison operators results.
00:02:47.700
00:02:51.900
Let me take the very first one. I
suppose if you want to

00:02:51.900
00:02:55.400
check 2 variables are equal or not.
Right.

00:02:55.400
00:02:58.700
So we'll use equality comparison
operator.

00:02:58.700
00:03:02.100
But here we are not going to take a
decision.

00:03:02.100
00:03:06.200
We are printing the result of your
comparison operator, number

00:03:06.200
00:03:13.700
of operators. If you check x equals to
y. If your variables

00:03:13.700
00:03:18.572
both are equal, then actually this is the
operator x==y.

00:03:18.572
00:03:21.299
So that is simply just like a message.
And here we are checking

00:03:21.300
00:03:26.800
actually x equals to y. So in case both
x and y are equal,

00:03:26.800
00:03:29.300
then you are going to get the result as
true.

00:03:29.300
00:03:31.000
First, let me run this.

00:03:31.000
00:03:37.224
So let me go to my command line,
ansible-playbook.

00:03:37.224
00:03:40.999
So, here observe only the result that
you are getting.

00:03:40.999
00:03:43.700
I mean true or false, that's it.

00:03:43.700
00:03:48.100
So, while working with your conditional
operators, there we
00:03:48.100
00:03:51.100
will use this comparison operator, so
that you will understand

00:03:51.100
00:03:55.399
clearly how to use your comparison
operators in your Playbooks.

00:03:55.399
00:04:01.400
For time being only other the result of
your comparison operators.

00:04:01.400
00:04:06.500
So here I'm taking x = y. No, it is false,
because x value is 6

00:04:06.500
00:04:10.300
Y value is 10. That's it. So the same
way let me complete

00:04:10.300
00:04:15.400
all my remaining comparison
operators. Suppose if I want to

00:04:15.400
00:04:19.600
check x not equal to y, then you have
to take this comparison

00:04:19.600
00:04:24.714
operator. If you're values are not
equal,

00:04:24.714
00:04:36.299
then the result of your x not equal to y,
you will get an output as true.

00:04:36.299
00:04:39.099
Just let me format. That's it.

00:04:39.099
00:04:54.857
Now, I am checking. Suppose x < y,
then you have to take }.

00:04:54.857
00:04:58.272
The same way, if you want to check x
>y

00:04:58.272
00:05:00.399
in case if they are really greater than, I
mean x is

00:05:00.400
00:05:05.300
greater than y, the result of x greater
than y, you're going
00:05:05.299
00:05:14.699
to get as a true. That's it. Then let me
check.

00:05:14.699
00:05:18.800
Is x less than or equal to y.

00:05:18.800
00:05:24.400
Then you have to check in this way.

00:05:24.400
00:05:27.444
Then let me write the last comparison
operator,

00:05:27.444
00:05:33.099
"x >= y"

00:05:33.099
00:05:38.499
} . That's it.

00:05:38.500
00:05:43.000
If you observe here, only this part is
your comparison operator.

00:05:43.000
00:05:46.500
This is just like a message x equals y
is a message. But inside

00:05:46.500
00:05:49.300
of your curly braces, whatever is
there, that is going

00:05:49.300
00:05:52.900
to evaluate. Right. That's fine.

00:05:52.900
00:05:56.700
Let me run your Playbook and see the
result.

00:05:56.700
00:05:58.500
X equals y. First, let me do one thing.

00:05:58.499
00:06:01.199
I will print both your x and y values, so
you can understand

00:06:01.199
00:06:15.999
from the output itself. "The value of x
is: } and The value of y is: }

00:06:15.999
00:06:20.719
Let me print y value now. I am going to
run your Playbook.

00:06:20.719
00:06:25.600
See the result 6 and 10, x is 6 and y is
10.
00:06:25.600
00:06:28.379
So are they equal? No, false.

00:06:28.379
00:06:29.800
Are they not equally, as they are not
equal. That's why

00:06:29.800
00:06:34.811
we are getting output as true. x less
than y, yes, 6 is less than 10, true.

00:06:34.811
00:06:38.641
x greater than y, no, because x is 6
and y is 10.

00:06:38.641
00:06:40.300
It is not greater than, it is less than.
That's why are

00:06:40.300
00:06:44.300
getting the result as false. x less than
or equal to y. Yes.

00:06:44.300
00:06:48.500
Anyway as x is 6, it is less than or
equal to 10 only. That's it.

00:06:48.499
00:06:53.200
So this is the way how you can use
your comparison operators

00:06:53.200
00:06:57.700
to see the result of your comparison
operators. Right.

00:06:57.700
00:07:00.700
So, while working with conditional
statements we will

00:07:00.700
00:07:04.500
see the, I mean use case of your
comparison operators.

00:07:04.500
00:07:06.949
So after that you have to wait. And
you have to know only

00:07:06.949
00:07:09.599
the output of your comparison
operators, whether you are going

00:07:09.599
00:07:13.899
to get true or false. That's it. Okay.

00:07:13.899
00:07:20.504
Thank you for watching this video.
Transcript
00:00:00.000
00:00:02.400
[no audio] Friends here.

00:00:02.400
00:00:05.400
We are going to discuss about how
ansible works.

00:00:05.600
00:00:09.800
I mean whenever if you run ansible or
commands or playbooks

00:00:09.800
00:00:13.200
how they are going to execute on your
managed node through

00:00:13.200
00:00:14.100
your ansible.

00:00:15.400
00:00:19.400
So before going to work with that, let
me show you your ansible

00:00:19.400
00:00:21.000
simple architecture already.

00:00:21.000
00:00:24.900
We know this right now assume that
we are going to execute
00:00:24.900
00:00:29.300
one simple or Holcomb and then
whenever if you type this

00:00:29.300
00:00:34.200
on your command line, and if you
enter how your ansible is

00:00:34.200
00:00:38.600
going to execute this on your manager
nodes their subs are

00:00:38.600
00:00:43.000
here. So whenever if you run your ad
hoc command or Playbook

00:00:43.000
00:00:46.500
first, your ansible will look into ansible
dot CFG file.

00:00:46.700
00:00:49.400
And from this it will get some
configuration details.

00:00:49.400
00:00:52.500
Let's say one of the information is your
inventory file location.

00:00:54.000
00:00:57.600
Now after getting inventory file
location based on the servers,

00:00:57.600
00:01:00.800
which you are mentioning in your ad
hoc command or while

00:01:00.800
00:01:03.800
going forward in Playbook based on
that.

00:01:04.099
00:01:08.900
It will get respect to servers IPS from
your inventory file.

00:01:10.000
00:01:13.300
Then after getting inventory IPS from
your inventory file,

00:01:13.500
00:01:17.600
maybe eyepiece or host names or
fqdn names then immediately

00:01:17.600
00:01:22.800
your ansible will establish SSH
connection with your all
00:01:23.000
00:01:25.000
managing nodes parallelly.

00:01:27.100
00:01:30.300
So after that, whatever the command
you are passing here,

00:01:30.300
00:01:32.200
whatever the module you are passing
here.

00:01:32.800
00:01:38.300
Then that module will be copied to
Oliver managed nodes.

00:01:38.300
00:01:38.700
Again.

00:01:38.700
00:01:43.700
This is also parallel or this module will
push into your

00:01:44.000
00:01:45.200
remote nodes.

00:01:46.300
00:01:49.900
So after questioning your particular
tasks module into your

00:01:49.900
00:01:54.600
remote nodes your answer will
exclude them over SSH on your

00:01:54.600
00:01:59.900
managed nodes only be clear your
tasks or executing on your

00:01:59.900
00:02:06.200
manager nodes only then once the
task is completed then whatever

00:02:06.200
00:02:08.000
the module you push.

00:02:08.000
00:02:11.199
I mean your ansible engine push it into
your managed nodes

00:02:11.500
00:02:13.000
that will be removed.

00:02:13.699
00:02:16.500
So this is the way how your answers
will is going to work?

00:02:17.600
00:02:20.300
So, you know model is nothing but
simply a python script
00:02:21.200
00:02:24.200
that python script will push it into your
all managed nodes.

00:02:24.500
00:02:27.200
Then that script will exclude on your
managed node itself

00:02:27.300
00:02:31.700
over SSH then once it is done then
whatever The Pusher program

00:02:31.700
00:02:35.500
will be I mean module will be there on
your manager nodes

00:02:35.500
00:02:36.500
that will be removed.

00:02:37.700
00:02:41.700
Now you may get down whatever the
module we have that model

00:02:41.700
00:02:44.200
your ansible is going to push into all
your managed nodes

00:02:44.200
00:02:46.300
right then where it will store.

00:02:49.300
00:02:51.500
Now see that before going to that.

00:02:51.500
00:02:54.600
Let me open my ansible engine now.

00:02:54.600
00:02:58.000
I have different servers with a different
groups.

00:02:58.100
00:03:01.000
You can execute On All or maybe
anyone of that.

00:03:01.300
00:03:05.900
Let me execute on all and I am going
to suppose a shell module

00:03:06.300
00:03:08.000
to work suppose simply up time.

00:03:08.800
00:03:14.400
So before going to run these let me
open my One of the manager

00:03:14.400
00:03:18.500
node. Let me connect with that
because I want to show you
00:03:18.500
00:03:22.900
where the ansible modules are going
to copy to your remote

00:03:22.900
00:03:24.800
nodes. It's very very important.

00:03:28.800
00:03:33.800
now let me login into one of them.

00:03:33.800
00:03:34.700
I managed server.

00:03:34.700
00:03:37.200
You can also login into all manage
servers and we can see

00:03:37.200
00:03:42.800
that so we are running our playbooks
or a dog commands through

00:03:43.400
00:03:46.400
and submenus the right now, let me
enter into that.

00:03:47.800
00:03:51.900
Now see that as of now, these are the
directories under my

00:03:52.700
00:03:58.700
answered mean home be clear home
answered mean home or with

00:03:58.700
00:04:02.000
what user you're running your rock
commands that user home

00:04:02.700
00:04:05.900
now. I am coming to our ansible
engine and here I am going

00:04:05.900
00:04:06.300
to run.

00:04:07.500
00:04:12.400
so once if you run it is going to
execute your tasks on your

00:04:12.400
00:04:13.600
respect to notes.

00:04:14.000
00:04:19.100
Just come back here and let let's say
LS - A seedot ansible

00:04:19.100
00:04:20.300
has been created.
00:04:21.000
00:04:21.200
Now.

00:04:21.200
00:04:23.800
Let me see the that is structure of your
ansible.

00:04:24.500
00:04:28.100
We have temp in that see by default.

00:04:28.100
00:04:29.700
Your ansible has been created.

00:04:31.100
00:04:33.800
And in that Temple has been created.

00:04:33.800
00:04:37.200
Anyway, as of now, you don't have any
content into this actually

00:04:37.200
00:04:41.000
whenever if you run your auto
commands or Playbook those

00:04:41.700
00:04:44.700
Playbook or Rock'em and they are
depending on modules.

00:04:44.700
00:04:49.400
So that model will be pushed into this
location by default.

00:04:49.400
00:04:51.100
It will be pushed into this location.

00:04:51.300
00:04:52.800
Of course, you can also change this.

00:04:52.800
00:04:56.000
But as of now we are going to work
with this default location.

00:04:57.100
00:05:00.800
So under user home, there will be Dot
ansible.

00:05:00.900
00:05:05.800
Be created into that template directory
will be created in

00:05:05.800
00:05:10.100
that your models will be copied and
those models are python.

00:05:11.100
00:05:13.900
That's why we need actually python on
remote nodes in case
00:05:13.900
00:05:17.200
if you don't have python how to work
we will see for timing

00:05:17.200
00:05:19.100
assuming that all servers are having
python.

00:05:19.700
00:05:21.600
I mean all manage servers fine.

00:05:22.400
00:05:26.700
So once if modules are copied into
this location, then you

00:05:26.700
00:05:30.300
are ants will exclude them and once
task is done then they

00:05:30.300
00:05:34.400
are removing but in case if you want to
see there is a one

00:05:34.400
00:05:39.600
flag you can set that flag so that your
modules won't delete

00:05:39.600
00:05:40.800
on your manager.

00:05:41.000
00:05:45.700
notes Now let me run this ansible
keep remote files equals

00:05:45.700
00:05:48.500
to 1 I am enabling this option and I am
running.

00:05:50.600
00:05:54.400
Now go to your manager node now
see that.

00:05:55.600
00:06:00.300
Based on your task directory will be
created then move into

00:06:00.300
00:06:05.700
that. So you guys where we are
answerable them based on suppose.

00:06:05.700
00:06:07.900
If you run two three tasks through two
three directories

00:06:07.900
00:06:13.300
will be created now in this there is a
module python script.
00:06:13.700
00:06:15.100
So whatever the module you are
pushing.

00:06:15.100
00:06:18.100
No, I mean your hands will Union is
pushing to manager nodes

00:06:18.200
00:06:21.900
that is this module and this module will
exclude here and

00:06:21.900
00:06:24.700
that result will send back to your
control node.

00:06:25.600
00:06:27.900
So guys, this is very very important.

00:06:30.400
00:06:33.700
So if you want to delete them by
default, don't use this

00:06:33.700
00:06:39.400
option. And simple keep remote files
equals to 1 but just

00:06:39.400
00:06:44.100
for our Clarity in which location your
modules or push how

00:06:44.100
00:06:49.000
they are going to keep that files that is
structure for that.

00:06:49.000
00:06:51.300
I mentioned this so that you can able
to see them.

00:06:53.600
00:07:00.200
Right now so our clear idea is ansible
engine is pushing

00:07:00.200
00:07:05.300
pushing modules to your remote
nodes based on your task that

00:07:05.300
00:07:07.900
model nothing but simply a Python
program that program will

00:07:07.900
00:07:09.600
execute on your remote nodes.

00:07:10.000
00:07:14.300
But from which location it is executing
under user home dot
00:07:14.300
00:07:19.100
ansible under the temp based on that
one directory into that.

00:07:19.200
00:07:21.000
It will push your module.

00:07:23.600
00:07:28.300
Fine and one more thing whenever
you are answerable is pushing

00:07:28.500
00:07:31.500
your modules or whenever it is
executing your push through

00:07:31.500
00:07:33.200
modules on your managed nodes.

00:07:33.700
00:07:35.400
Everything is a parallel process.

00:07:36.800
00:07:38.400
Is it really parallel or serial?

00:07:39.500
00:07:42.900
How we can understand that let me
show you with an example

00:07:42.900
00:07:45.700
so that you will get clearer idea
suppose.

00:07:45.700
00:07:50.600
I am running simply ansible all - em
some shell argument.

00:07:51.000
00:07:53.800
I am writing simply sleep five seconds.

00:07:54.600
00:07:58.500
Then Echo High just for our
understanding purpose.

00:07:58.500
00:07:59.800
I am taking just run it.

00:08:02.100
00:08:06.300
See you are going to get your output
at a time for all servers.

00:08:06.400
00:08:08.000
Just observe your thermal output,
right?

00:08:10.100
00:08:12.600
You're going to get your entire output
3 servers or briquette.
00:08:12.600
00:08:14.900
I'm that's why this is parallel.

00:08:15.900
00:08:19.200
Maybe you're not believing this but if
you want to see that

00:08:20.100
00:08:23.200
in your ants Bill Dot CFG file, right?

00:08:23.800
00:08:25.200
There is a Forks Valium.

00:08:26.100
00:08:28.400
So by default you don't have this I
added this.

00:08:30.100
00:08:32.700
In your suppose, if you go with your
answer will installation

00:08:32.700
00:08:33.799
with the m command.

00:08:33.799
00:08:36.100
You can see in our ansible DOT CFG
file.

00:08:36.100
00:08:36.900
Let me show you.

00:08:39.299
00:08:45.400
ansible CFG sample so that you can
understand.

00:08:51.000
00:08:52.200
sample ansible.

00:08:52.200
00:08:56.400
CFG file Okay, whoops.

00:09:08.300
00:09:09.200
Yeah, see here.

00:09:10.200
00:09:13.900
So in our in our sin to A7, we have
seen that there are some

00:09:13.900
00:09:16.700
default values which they commented
right now.

00:09:16.700
00:09:19.500
One of the value is for Subs over here.

00:09:20.800
00:09:25.900
Folks it goes to Phi that means by
default ansible will execute
00:09:25.900
00:09:28.500
a task on Phi servers at a time.

00:09:29.500
00:09:30.900
That means parallely.

00:09:30.900
00:09:35.100
It will execute on Phi servers suppose
if you have some tools

00:09:35.100
00:09:38.300
are worse then how your answer is
going to execute.

00:09:38.800
00:09:43.200
So it will execute in one go on fi
servers in second go on

00:09:43.200
00:09:46.000
file servers and you have two more
servers.

00:09:46.000
00:09:49.400
So in three goes it is going to
complete your task on your

00:09:49.400
00:09:50.200
to all servers.

00:09:50.700
00:09:54.500
But if you want to execute on all to all
servers at a time,

00:09:54.500
00:09:58.700
what you have to do is you need to
make this value as to

00:09:58.700
00:10:01.600
all. So when you have to make it as a
two ball if you have

00:10:01.600
00:10:04.000
to all servers and if you want to
execute your tasks and

00:10:04.000
00:10:05.500
all tools are worse at a time.

00:10:05.600
00:10:09.100
They need to make this as a tool
suppose if I make it as

00:10:09.100
00:10:12.900
a 1 means even though if your
hundred servers are one server
00:10:12.900
00:10:16.300
or two servers it is going to execute
serially one by one

00:10:16.800
00:10:19.300
now. Let us assume that if you have
some threes are words

00:10:19.500
00:10:22.600
it is going to execute in first go on one
server in second

00:10:22.600
00:10:25.600
go on second server in third go on one
more server.

00:10:25.700
00:10:29.100
So it is going to execute a complete
your task on three goes.

00:10:31.500
00:10:33.400
Now, let me show you this now.

00:10:33.400
00:10:35.900
If you want to execute your task
parallely.

00:10:35.900
00:10:38.800
Now, you need to make it as a value
for x value equals to

00:10:38.800
00:10:44.100
1. If you delete this entire line by
default ansible will

00:10:44.100
00:10:48.200
execute in case if you don't see this
value in your configuration

00:10:48.200
00:10:51.900
file by your ansible ansible will
execute on file servers

00:10:51.900
00:10:52.400
at a time.

00:10:53.300
00:10:54.400
Now same command.

00:10:54.400
00:10:58.400
I am running now see the result you
are going to get your

00:10:58.400
00:11:00.900
output first on one server after 5
Seconds.
00:11:02.700
00:11:06.000
Then you're going to get your output
on next server after

00:11:06.000
00:11:10.200
5 seconds, but previously with Force
equals to Phi or even

00:11:10.200
00:11:13.500
if you delete that by default you are
getting output on all

00:11:13.500
00:11:14.000
server socket.

00:11:14.000
00:11:16.800
I'm but now you are not getting see
that now one by one you

00:11:16.800
00:11:19.300
are getting that means your answer
will is executing now

00:11:19.300
00:11:21.400
your task on your managed node C.

00:11:21.400
00:11:21.900
Really?

00:11:24.900
00:11:30.900
Right and one more thing see we are
saying that ansible is

00:11:30.900
00:11:34.700
pushing modules into your managed
nodes.

00:11:36.000
00:11:38.900
Right and you are managed nodes or
not trying to connect

00:11:38.900
00:11:39.700
with your engine.

00:11:39.700
00:11:42.200
Your engine only is going to connect
with your manager nodes.

00:11:44.600
00:11:45.000
Right.

00:11:45.300
00:11:50.400
So your engine is pushing that way
ansible follows push mechanism.

00:11:50.400
00:11:53.700
If you go with the chef that is following
pull mechanism
00:11:53.900
00:11:55.200
managed nodes itself.

00:11:55.200
00:11:58.400
They are trying to pull your modules in
chef.

00:11:59.300
00:12:02.900
But in ansible ansible is engine is
going to push them.

00:12:03.100
00:12:05.100
That's why this is called push
mechanism.

00:12:06.400
00:12:09.900
And one more thing if it is a pull
mechanism, you shouldn't

00:12:09.900
00:12:12.800
you should have some agent here or
some software here to

00:12:13.300
00:12:15.900
pull this modules into their manager
nodes.

00:12:17.000
00:12:18.500
Right, but we don't have that.

00:12:18.700
00:12:20.600
Our answer will engine will take care
everything.

00:12:20.800
00:12:24.300
That's why we are not installing any
software or agent on

00:12:24.300
00:12:25.600
your remote nodes.

00:12:25.800
00:12:29.500
That's why this is called Agent less
architecture.

00:12:32.300
00:12:35.700
Right, so guys you need to understand
here.

00:12:37.200
00:12:51.200
simply ansible follows push
mechanism then ansible is a key

00:12:51.200
00:12:53.900
agent less architecture.
00:12:58.200
00:13:02.300
Right and one more thing if you want
to make it as a serial

00:13:02.300
00:13:06.100
execution basically ansible executes.

00:13:08.100
00:13:26.200
ask on managed nodes parallelly but
you can make it as serial

00:13:26.500
00:13:37.700
by be clear by keeping folks value
equals to 1 in ansible

00:13:37.700
00:13:43.100
dot CFG file And while going forward
in case if you're going

00:13:43.100
00:13:46.200
to work with playbooks in playbooks
itself, we can mention

00:13:47.300
00:13:49.700
for its value instead of parallel.

00:13:49.700
00:13:51.000
You can exclude in cereal.

00:13:52.600
00:13:53.000
Right.

00:13:54.200
00:13:57.700
Okay guys, this is the way how your
ansible is going to work

00:13:57.700
00:13:59.500
with your managed nodes.

00:13:59.500
00:14:01.200
It's very very important thing.

00:14:02.800
00:14:03.100
Right.

00:14:03.100
00:14:06.100
So finally from this concept you have
to understand that

00:14:06.100
00:14:10.900
ansible follows push mechanism and it
is agentless and by

00:14:10.900
00:14:15.900
default ansible will execute a task on
five servers parallely,
00:14:16.500
00:14:19.900
but if you want to execute your tasks
on number of servers

00:14:19.900
00:14:22.500
require number of servers parallel at a
time, you need to

00:14:22.500
00:14:26.300
make it even more Force value new
ansible DOT CSV file.

00:14:28.100
00:14:28.600
That's it.

00:14:29.300
00:14:29.600
Okay.

00:14:30.000
00:14:30.500
Okay guys.

00:14:30.500
00:14:31.800
Thank you for watching this video.
Transcript
00:00:00.000
00:00:03.100
[no audio]

00:00:03.100
00:00:08.100
Our concept is logical operators of
ansible Playbooks.

00:00:08.199
00:00:11.100
Like your other programming or
scripting languages, here

00:00:11.100
00:00:15.000
also, we are having different types of
logical operators.

00:00:15.000
00:00:21.100
They are like or, and, and not. So
these are the 3 logical

00:00:21.100
00:00:24.100
operators in your Ansible Playbooks.

00:00:24.100
00:00:27.100
First, let me go with the first 2 logical
operators. That
00:00:27.100
00:00:33.900
is or and and operator. See these 2
either or, or and, logical

00:00:33.900
00:00:39.500
operators or useful to club multiple
results.

00:00:39.500
00:00:43.100
Let me show you that with the help of
Playbook.

00:00:43.100
00:00:47.600
Let me open my Ansible controller.

00:00:47.600
00:00:50.900
So here let me enter into my practice
directory.

00:00:50.900
00:00:54.200
So I am going to open atom editor.

00:00:54.200
00:01:00.200
So just wait it will take some time.

00:01:00.200
00:01:05.099
Yes, it's opening.

00:01:05.099
00:01:09.500
Fine, now let me create a new file.

00:01:09.500
00:01:15.900
So I'm going to save it as, let me take
a new file first.

00:01:15.900
00:01:22.900
Let me close all other windows.

00:01:22.900
00:01:33.500
Save it. So I'm going to take it as
logical_operators.yml. So here

00:01:33.500
00:01:38.400
I am starting with 3 hyphens, then let
me take the name

00:01:38.400
00:01:47.500
of your Playbook or play is, Working
with logical operators.

00:01:47.500
00:01:51.400
Then let me take target as localhost.

00:01:51.400
00:01:58.100
And let me disable gather_facts.

00:01:58.100
00:02:04.200
Then, let me define 2 variables,
maybe 2 or 3.
00:02:04.200
00:02:07.700
It's your wish, let me take 5 and
suppose I am going to

00:02:07.700
00:02:18.132
take here number 7, and take p as list
of values.

00:02:18.132
00:02:22.500
Let me take only 4 5 6. No problem
just for practice I'm taking this.

00:02:22.500
00:02:24.381
Let me write a tasks section.

00:02:24.381
00:02:33.300
So here first of all, I am displaying all
your variables.

00:02:33.300
00:02:36.400
I'm going to display with the help of
message parameter

00:02:36.400
00:02:55.816
of your debug module "The value of x
is : }, The value of y is : }"

00:02:55.816
00:03:00.641
y value will be displayed if you write
your y in terms of curly braces.

00:03:00.641
00:03:09.400
and a list, p list of sequence is : }.

00:03:09.400
00:03:13.200
Let me save it, and go to command
line and run your

00:03:13.200
00:03:24.900
ansible_logical_operators.yml. See
the output.

00:03:24.900
00:03:27.609
Yes, you're getting your values.

00:03:27.609
00:03:32.900
What I am doing is, I am going to take
2 comparison operators

00:03:33.000
00:03:36.100
and I want to print the result of those
2.

00:03:36.100
00:03:40.300
The comparison operators result is
always either true or false.
00:03:40.300
00:03:45.700
What I am checking is, suppose x less
than, or x less than y or not.

00:03:45.700
00:03:47.500
I want to check this result.

00:03:47.500
00:03:50.900
So, you know how to check the result
in message, simply

00:03:50.900
00:04:08.432
x less than y, right. And I'm going to
check one more thing, y in p.

00:04:08.432
00:04:15.400
y is there in p. y is 7, p 4 5 6. So y
value is there in a p list.

00:04:15.400
00:04:17.891
So if it is there, it is going to give true.
If it is not there,

00:04:17.891
00:04:23.600
it is going to give false. Right, that's
fine.

00:04:23.600
00:04:29.200
Now instead of and here, just simply
let me write y in p.

00:04:29.200
00:04:32.000
That is our message.

00:04:32.000
00:04:35.500
This is a message only, which is there
in curly braces that

00:04:35.500
00:04:41.300
will be validated or that will give the
result of your

00:04:41.300
00:04:43.400
comparison operators.

00:04:43.400
00:04:48.100
Now, let me run this and see the
result. x less than y, yes,

00:04:48.100
00:04:52.767
x value is 5 and y value is 7, x value is
5

00:04:52.767
00:04:55.375
and y value is 7, 5 less than 7, yes.
00:04:55.375
00:05:01.200
why in P. No, y is not in p. That's why
we are getting false.

00:05:01.200
00:05:05.400
What I want to check is, I want to club
these two conditions,

00:05:05.400
00:05:09.700
this result and this result. Then if you
want to club, not

00:05:09.700
00:05:13.800
only 2, you can club any results with
the help of any number

00:05:13.800
00:05:18.469
of results with the help of or and and.
Now let me club these 2.

00:05:18.469
00:05:24.800
So, clubbing is not there, see that. I'm
checking

00:05:24.800
00:05:30.922
simply and. First I am taking x less
than y, and then y in p.

00:05:30.922
00:05:34.508
Then these 2 results I am clubbing
with and. What will happen.

00:05:34.508
00:05:42.500
What is the result. So we are doing x
less than y and y in p.

00:05:42.500
00:05:45.200
See the result, you're going to get
result as false.

00:05:45.200
00:05:50.100
The reason is, whenever you club any
conditions and in

00:05:50.100
00:05:55.600
that, if any one of the results is false,
then the complete

00:05:55.600
00:06:03.000
output is going to get a false. I mean,
let me explain here.

00:06:03.000
00:06:05.086
Just after that I am going to get some
results.
00:06:05.086
00:06:12.200
Let's say 4 less than 5, this is true.

00:06:12.200
00:06:15.100
And I am going to club that with under
operator.

00:06:15.100
00:06:22.000
Then I am going to compare 5 less
than 1, mode is false

00:06:22.000
00:06:31.100
and 5 less than 2 is true. No it's false.

00:06:31.100
00:06:45.500
Let me write 5 greater than 2 and any
values you can take, 9 equals 0.

00:06:45.500
00:06:49.000
So if you observe, the first result 4
less than 5 is true,

00:06:49.000
00:06:53.300
5 greater than 1 true, 5 greater than 2
true, but this is not true.

00:06:53.300
00:06:57.500
So if we club multiple results with the
help of under operator,

00:06:57.500
00:07:00.600
and while clubbing, if any one of the
results is false, then the

00:07:00.600
00:07:05.400
complete output is also going to be
false. See that.

00:07:05.400
00:07:09.800
I can take it in this way also.

00:07:09.800
00:07:14.400
Let me write in the next result.

00:07:14.400
00:07:17.300
These are the operators. So you have
to write inside of the curly

00:07:17.300
00:07:25.100
braces. Now, let me save it and run it.

00:07:25.100
00:07:27.100
See the result that you are going to
get. You're going to

00:07:27.100
00:07:28.966
get false, last output.
00:07:28.966
00:07:32.500
The reason is, only in all the
combinations,

00:07:32.500
00:07:33.700
this combination is false.

00:07:33.700
00:07:36.900
That's why we are going to get a false.
Suppose,

00:07:37.000
00:07:39.400
if all are true, then only are you going
to get result as true.

00:07:39.400
00:07:47.000
Let's say I'm writing, not equal to 0.
Now see the result.

00:07:47.000
00:07:48.786
You're going to get a true.

00:07:48.786
00:07:52.100
So, whenever you club multiple results
with the

00:07:52.100
00:07:55.700
help of under operator, in that case
you are going to get

00:07:55.700
00:08:01.695
output as true, if all the results are
true. That's it.

00:08:01.695
00:08:14.605
So, and operator, useful to club
multiple results.

00:08:14.605
00:08:18.100
But output is true,

00:08:18.100
00:08:22.500
if all results are true. That's it. And
usually if all results

00:08:22.500
00:08:27.600
are true, then only are you going to
get your result as true.

00:08:27.600
00:08:30.839
Then next one. We are having or
operator,

00:08:30.839
00:08:34.500
this is useful to club,
00:08:34.500
00:08:50.200
or combine multiple results. And here
output is true if at

00:08:50.200
00:08:58.800
least one result is true.

00:08:58.800
00:09:04.100
See now suppose here all are true.
That's where are going to get the

00:09:04.100
00:09:06.700
result as true whenever you club with
under operator.

00:09:06.700
00:09:10.800
But now I modified it into false.

00:09:10.800
00:09:13.800
So because the last one is false and if
you club all

00:09:13.800
00:09:16.700
the results, then you're going to get
result as false.

00:09:16.700
00:09:20.500
But same thing if you go with under
operator, sorry or operator,

00:09:20.500
00:09:23.900
then you are going to get result as
true.

00:09:23.900
00:09:29.155
Let me show you that.

00:09:29.155
00:09:31.900
So, here parentheses are optional. If
you want to use it

00:09:31.900
00:09:36.000
you can use your parentheses, but it's
better to use parentheses.

00:09:36.000
00:09:43.900
I am going to replace this and with or.
See the first 3 results

00:09:43.900
00:09:47.800
are true, but last result is false, but no
problem.

00:09:47.800
00:09:51.300
If at least one result is true, then in
your final result
00:09:51.300
00:09:52.600
you're going to get true,

00:09:52.600
00:09:58.400
if you club all the results with the help
of or operator. That's it.

00:09:58.400
00:10:00.600
I'll see that I'm going to run it. And
you're going to get

00:10:00.600
00:10:02.600
output as... something wrong?

00:10:02.600
00:10:07.500
Yeah, I missed ending with the
quotation on starting with

00:10:07.500
00:10:18.600
quotation. That's fine. Now let me run.

00:10:18.600
00:10:21.700
See that you're getting the result as
true.

00:10:21.700
00:10:24.841
The reason, this is true. This is true.

00:10:24.841
00:10:26.406
This is true. Only this thing is false.

00:10:26.406
00:10:29.500
If all are false, then you are going to
get result as

00:10:29.500
00:10:32.200
false in your or operator. That's it.

00:10:32.200
00:10:36.500
Let me make it as all are false.

00:10:36.500
00:10:41.900
4 greater than 5. You can take any

00:10:41.900
00:10:47.400
operator to get your result. 5 less than
1 I'm writing.

00:10:47.400
00:10:52.600
5 less than 2 I'm writing. Now all are
false, all are false.

00:10:52.600
00:10:56.800
The result is also going to be false.
Right.

00:10:56.800
00:10:59.800
So in under operator, if you want to
get result as true, whenever
00:10:59.800
00:11:02.600
you club multiple operations all should
be true. Then

00:11:02.600
00:11:06.700
only are you going to get result as true.
But in or operator,

00:11:06.700
00:11:10.900
you are going to get a true, if at least
one of the result is true, that's it.

00:11:10.900
00:11:13.609
If all are false, in both the cases you
are going to get false.

00:11:13.609
00:11:19.000
I mean in and as well as or operator.
Now among all those things

00:11:19.000
00:11:21.900
I am going to make it as any one of the
condition as true.

00:11:21.900
00:11:24.758
5 greater than 1, is true.

00:11:24.758
00:11:27.700
Now, whenever you club multiple
results with the help of

00:11:27.700
00:11:31.800
or operator, if at least one result is
true, then the

00:11:31.800
00:11:34.200
complete combination result

00:11:34.200
00:11:35.200
you're going to get is a true.

00:11:35.200
00:11:39.300
So if you busy here, this is true,
remaining all are false. That's okay.

00:11:39.300
00:11:44.342
But this is true. That's why you're
going to get result as true. That's it.

00:11:44.342
00:11:49.409
So that is the simple usage of your and
and or operators.

00:11:49.409
00:11:51.100
Now finally, we are having not
operator.
00:11:51.200
00:11:53.785
It's very simple.

00:11:53.785
00:12:00.435
Suppose first let me display the value,
4 for greater than 1.

00:12:00.435
00:12:01.100
What is the result?

00:12:01.100
00:12:04.800
You know, you're going to get result as
true. Last one.

00:12:04.800
00:12:11.500
Yes. But I can make it as a false by
applying not on this result. That's it.

00:12:11.500
00:12:15.400
So, if you're having result as true, and
if you want

00:12:15.400
00:12:19.800
to modify it as a false, then go on use
not.

00:12:19.800
00:12:22.700
If you are already having some true
result, then I want to

00:12:22.700
00:12:26.805
make it as a false. Then I can use not
operator. That's it.

00:12:26.805
00:12:32.200
So, these are the simple logical
operators in your Ansible Playbooks.

00:12:32.200
00:12:34.000
Okay. Thank you for watching this
video.
Transcript
00:00:00.000
00:00:02.800
[no audio] Friends, here

00:00:02.800
00:00:06.300
we are discussing about the required
settings for Ubuntu

00:00:06.300
00:00:11.200
server to consider it as a node for
ansible see suppose.

00:00:11.200
00:00:15.200
You are having some ansible controller
here and we are managing

00:00:15.200
00:00:16.600
some number of nodes.

00:00:17.300
00:00:20.000
So this node may be any distribution
suppose.

00:00:20.000
00:00:21.800
The first one is rhl distribution.

00:00:21.800
00:00:25.000
Just assume that the second one is
Amazon Linux.
00:00:26.600
00:00:30.100
And third one is open to Linux see
already.

00:00:30.300
00:00:34.500
We worked with the nodes like
Amazon or distribution and

00:00:34.500
00:00:35.900
then Orajel distribution.

00:00:35.900
00:00:39.800
Now, I am going to work with your
managed node as a Ubuntu

00:00:39.800
00:00:45.600
server. See compared to your original
or Amazon distribution.

00:00:45.700
00:00:48.800
There is one extra step you need
whenever if you want to

00:00:48.800
00:00:52.800
work with the Ubuntu Server as a
node using your ansible.

00:00:53.600
00:00:56.300
So that setting is simply on your
managed node.

00:00:56.300
00:00:56.500
Only.

00:00:56.500
00:00:59.500
I mean on Auburn to server only let
me show you that first.

00:00:59.500
00:01:02.600
Let me launch my Ubuntu Server.

00:01:02.900
00:01:07.800
So let me go to so I'm going to take
my Ubuntu server from

00:01:07.900
00:01:09.000
AWS cloud.

00:01:09.800
00:01:11.700
So this I am going to select.

00:01:13.000
00:01:15.800
Let me simply launch with simple
configurations.

00:01:18.900
00:01:20.600
Just give me some time so that I will.
00:01:22.100
00:01:23.200
Launch This Server.

00:01:27.500
00:01:30.700
So now it is going to launch once it is
launched then I will

00:01:30.700
00:01:31.500
work with that.

00:01:32.600
00:01:44.300
So let me take this as an Ode to just
right.

00:01:49.600
00:01:51.100
So first, I need to connect with this
road.

00:01:51.200
00:01:54.000
And one more thing is we know that
whenever if you want to

00:01:54.000
00:01:56.600
work with your managed nodes, right?

00:01:56.600
00:01:58.400
We are creating same.

00:01:59.500
00:02:03.700
Username across all servers, then we
are providing some root

00:02:03.700
00:02:05.000
privileges, right?

00:02:05.200
00:02:09.400
So let's say we are taking the user as
ants admin user across

00:02:09.400
00:02:16.500
all servers including your Ansible
controller right see who

00:02:16.500
00:02:18.100
am I answered been user.

00:02:18.500
00:02:20.800
So actually this is my ansible
controller.

00:02:20.800
00:02:23.600
We know that the same user we are
creating across all the

00:02:23.600
00:02:26.500
server's the service which we are
going to manage with our
00:02:26.500
00:02:29.400
ansible that name may be anything in
our case.

00:02:29.400
00:02:32.800
We are taking as ants admin user right
you can also work

00:02:32.800
00:02:35.800
with the root user right fine.

00:02:36.000
00:02:38.300
Now, let me it has been running.

00:02:38.300
00:02:40.000
Let me connect with the server first.

00:02:41.800
00:02:46.700
so if you remember, what is the very
first step 2 I mean

00:02:47.300
00:02:51.300
to do configuration settings on your
managed nodes to consider

00:02:51.300
00:02:54.500
as an node for your controller first.

00:02:54.500
00:02:57.500
We have to create a user on that
server first.

00:02:57.500
00:02:59.000
Let me log in with this server.

00:03:03.800
00:03:06.200
Now let me enter into route first.

00:03:08.300
00:03:12.200
Now first of all, I am creating a user
called user ad and

00:03:12.200
00:03:13.500
admin that's it.

00:03:14.800
00:03:19.100
Right, then next up is under VI pseudo
file.

00:03:19.100
00:03:20.300
We have to provide.

00:03:23.500
00:03:24.900
Just give me a second.

00:03:29.200
00:03:31.600
Yeah VI sudo file.

00:03:31.900
00:03:33.300
Just go to last.
00:03:34.600
00:03:42.900
then here let me add your aunt's
admin then all equals to

00:03:42.900
00:03:57.100
all. Right then no password all so if
you remember, this

00:03:57.100
00:03:59.900
is the line we are sorry.

00:04:00.000
00:04:01.500
This is nano a turd is opening.

00:04:01.500
00:04:04.400
Let me control X then.

00:04:04.400
00:04:05.000
Yes.

00:04:06.400
00:04:07.000
That's it.

00:04:09.100
00:04:12.400
Syntax error in line 1 what is that?

00:04:15.000
00:04:21.300
edit Yeah, very first line by mistake.

00:04:21.500
00:04:23.000
I has been included.

00:04:26.700
00:04:27.200
That's fine.

00:04:28.000
00:04:29.000
Now on one more thing.

00:04:29.000
00:04:32.000
If you remember we need to open
etcs.

00:04:32.000
00:04:36.100
Sh under sssss Judy config file there.

00:04:36.600
00:04:41.600
We need to search for password
authentication and we need

00:04:41.600
00:04:44.800
to make it as a yes, right?

00:04:45.900
00:04:46.400
That's it.

00:04:46.800
00:04:46.900
Now.

00:04:46.900
00:04:51.400
Let me restart this systemctl raised
Trot sshd.
00:04:52.000
00:04:52.600
That's fine.

00:04:53.400
00:04:57.700
So guys just now what I did on you are
managed node 4 I created

00:04:58.300
00:05:04.900
create a user called and admin then
we have given root privileges

00:05:05.100
00:05:09.000
by including the information about
your answered mean user

00:05:09.100
00:05:14.600
in VA sued over file or we ISO file,
then after that we enable

00:05:14.700
00:05:17.500
password authentication.

00:05:19.800
00:05:25.300
As yes in your Rudy TCS sh sh D
config file.

00:05:29.000
00:05:31.700
So after enabling it we restarted.

00:05:31.800
00:05:36.500
You are sshd systemctl restart sshd.

00:05:36.500
00:05:37.000
That's it.

00:05:37.100
00:05:42.300
Now after that go to your answer will
controller on a on

00:05:42.300
00:05:43.500
your answer will controller.

00:05:43.500
00:05:47.400
We need to exchange our keys from
ansible controller to your

00:05:47.400
00:05:49.400
node right now.

00:05:49.400
00:05:52.900
Let me login with your my hands will
controller before going

00:05:52.900
00:05:53.100
to that.

00:05:53.100
00:05:56.100
Let me take the IP of your server.
00:05:56.300
00:05:59.300
I mean public IP, so I have taken that
now.

00:05:59.300
00:06:00.600
Let me open My Controller.

00:06:00.600
00:06:05.000
So guys if you Remember already we
created our SSH keys in

00:06:05.000
00:06:10.400
our previous sessions at very initial
videos, right?

00:06:11.500
00:06:11.900
Okay, fine.

00:06:11.900
00:06:16.700
Simply I'm copying my SSH key and
said Min at the rate.

00:06:17.700
00:06:19.600
You are remote server IP.

00:06:21.300
00:06:21.900
Yes.

00:06:22.400
00:06:24.000
See the result what it showing.

00:06:25.600
00:06:28.600
So it is going to ask password for your
ants admin user on

00:06:28.600
00:06:30.000
your open to note.

00:06:30.000
00:06:30.200
Now.

00:06:30.200
00:06:32.100
I am going to provide and submission.

00:06:32.200
00:06:35.000
Yeah, I think I did not provide the
password here.

00:06:35.000
00:06:35.500
Right?

00:06:36.400
00:06:39.500
I mean I did not create a password on
your manager node.

00:06:39.500
00:06:41.500
Let me create already.

00:06:41.500
00:06:43.400
We added an certain user now.
00:06:43.400
00:06:45.800
We need to set password for and said
mean.

00:06:47.400
00:06:51.400
So simply I am writing ands admin or
the red one, two, three

00:06:52.300
00:06:54.600
and admin or the red one, two three.

00:06:56.000
00:06:56.600
That's fine.

00:06:57.100
00:07:03.100
Now what I am doing is Yeah now on
your controller now, I

00:07:03.100
00:07:08.000
am going to provide and admin at the
rate 1 2 3 so that I

00:07:08.000
00:07:10.700
can exchange my keys, but see the
error what you are getting.

00:07:12.400
00:07:17.700
Can't cd2 home and said men user
see in your other distributions

00:07:17.700
00:07:20.700
like Amazon distribution or Oracle
distribution of Linux,

00:07:21.000
00:07:25.000
whenever user is created by default
user of home also creates,

00:07:25.700
00:07:29.800
but whereas in Ubuntu distribution see
that on now I am in

00:07:29.800
00:07:34.900
my open to actually we created
answered mean user then we

00:07:34.900
00:07:38.800
have a path like home and submenus
a right that is not there.

00:07:39.200
00:07:42.400
That means by default whenever if
you create a There are

00:07:42.400
00:07:43.500
no one to servers.
00:07:43.900
00:07:46.800
It won't create user home for your
user.

00:07:46.900
00:07:50.300
That's why whenever if you are adding
user let me first remove

00:07:50.300
00:07:52.000
my user.

00:07:53.300
00:07:58.800
And said mean now I am adding user
ad simply with - M if

00:07:58.800
00:08:03.300
you create and submit in now see that
home.

00:08:04.100
00:08:06.100
There is a user home has been
created.

00:08:07.400
00:08:08.000
That's it.

00:08:08.600
00:08:11.500
So this is the only important Point
whenever if you are creating

00:08:11.500
00:08:14.200
a user on your Ubuntu servers.

00:08:14.500
00:08:17.100
So for this point only I am grading this
video.

00:08:18.300
00:08:21.200
So if you want to work with Ubuntu
servers while creating

00:08:21.200
00:08:24.400
user and open to server, right, you
need to create your user

00:08:24.400
00:08:26.000
with user ad.

00:08:27.700
00:08:29.700
- mm then your username.

00:08:29.800
00:08:32.400
Yeah, let me provide password for that
user.

00:08:32.600
00:08:34.000
Just now we recreated right?
00:08:34.000
00:08:34.600
That's why.

00:08:37.500
00:08:43.000
Password and set Min so I am going
to provide and set Min

00:08:43.100
00:08:47.400
or the rate 1 2 3 and set Min or the
right one, two, three.

00:08:48.400
00:08:50.799
That's it now see the result.

00:08:52.100
00:08:58.800
and admin at the rate 1 2 3 That's it.

00:08:58.900
00:08:59.100
Now.

00:08:59.100
00:09:02.000
We exchanged our keys with your
manager node.

00:09:02.400
00:09:06.200
So guys, let me do the or notes Here.

00:09:07.400
00:09:13.400
So create a user called answered Min
with user ad - em and

00:09:13.400
00:09:16.400
submit. So this command is important.

00:09:16.400
00:09:19.400
That's it and remaining steps are
same if you want to work

00:09:19.400
00:09:23.000
with Linux or I mean Amazon Linux or
Oracle Linux or Ubuntu

00:09:23.000
00:09:26.500
Linux. They making steps are same
Only We Know them only

00:09:26.500
00:09:27.700
concentrate on this command.

00:09:27.700
00:09:31.700
That's it right now see that.

00:09:32.500
00:09:33.700
Let me add this.

00:09:35.200
00:09:40.300
In my inventory, so let me move into
my practice directory.
00:09:40.300
00:09:42.500
Let me open inventory.

00:09:43.500
00:09:44.900
Let me remove all these things.

00:09:47.900
00:09:50.700
Save it and now ansible.

00:09:53.000
00:10:01.800
all - m-pin Now it has to work then
only our setup is correct.

00:10:05.900
00:10:06.600
Just wait.

00:10:10.000
00:10:14.800
So it will take some time because our
controller is on something.

00:10:16.100
00:10:21.000
Connection time without fail to connect
to the host via SSH

00:10:21.800
00:10:25.600
connect to the host Port 22 connection
timeout unable to

00:10:25.600
00:10:27.200
reach. What is the problem?

00:10:28.400
00:10:34.800
4.20 a DOT 5.68 Let me check it.

00:10:35.200
00:10:39.600
Yeah, sorry it is 54 right so I have
taken invalid IP.

00:10:40.400
00:10:44.800
But while working here we have taken
correct IP only in inventory

00:10:45.200
00:10:51.000
how taken Let me walk in my
inventory.

00:10:51.000
00:10:53.900
It is 54 so it's my typo.

00:11:07.400
00:11:08.000
Just wait.

00:11:08.000
00:11:10.300
Yeah now it's working you're getting
the result as pain,

00:11:10.300
00:11:16.500
right? And the found python path on
your remote server is
00:11:16.500
00:11:17.000
this one?

00:11:17.800
00:11:22.400
So guys this is the simple way to work
with your Ubuntu Server.

00:11:23.000
00:11:27.800
So you need some settings on your
Ubuntu know so the important

00:11:27.800
00:11:29.100
point is this one user.

00:11:29.100
00:11:30.500
I phone him and said mean that's it.

00:11:31.800
00:11:32.200
Right.

00:11:32.900
00:11:33.400
Okay.

00:11:33.400
00:11:35.000
Thank you for watching this simple
video.
Transcript
00:00:00.000
00:00:05.500
[no audio] Here our concept is
conditional statements of Ansible

00:00:05.500
00:00:09.000
Playbooks. So, these conditional
statements are very very important

00:00:09.000
00:00:12.900
to execute your tasks based on some
condition.

00:00:12.900
00:00:15.600
And here we are having different types
of conditional statements.

00:00:15.600
00:00:20.200
They are when, failed when, and
changed when. So you

00:00:20.200
00:00:25.500
can club any of your modules with
this, anyone of your conditional
00:00:25.500
00:00:31.300
statements. How can we club any of
your modules with conditional

00:00:31.300
00:00:36.000
statements? We will see that while
writing your Playbooks.

00:00:36.000
00:00:38.200
And among all these 3 here,

00:00:38.200
00:00:41.800
we are going to work with when
conditional statement. See

00:00:41.800
00:00:46.300
this when conditional statement is very
similar to if conditional

00:00:46.300
00:00:49.200
statement in your other languages.

00:00:49.200
00:00:52.000
So, if you go with like python or shell
languages right, there

00:00:52.000
00:00:55.300
we have some if condition or even
with C also, we have if

00:00:55.300
00:01:00.900
condition. So the same functionality
we can perform by using

00:01:00.900
00:01:04.700
when conditional statement in your
Playbooks.

00:01:04.700
00:01:10.200
Simply it will work or execute any task
if the condition is true.

00:01:10.200
00:01:13.000
So, let me write a simple thing here.
Suppose you have some

00:01:13.000
00:01:14.530
debug module.

00:01:14.530
00:01:17.600
You are going to exclude some tasks
with the debug module.

00:01:17.600
00:01:21.400
So this debug module you can club
with when condition, by
00:01:21.400
00:01:24.400
writing some condition here, some
expression here.

00:01:24.400
00:01:28.100
So, if this expression result is true,
then only this when

00:01:28.200
00:01:32.100
will allow to exclude this debug
module. Suppose if this expression

00:01:32.100
00:01:35.800
result is false, then your when
condition is going to

00:01:35.800
00:01:40.300
skip your task or module. That's it.
Very simple.

00:01:40.300
00:01:43.800
I will show you while writing your
Playbooks. And one more

00:01:43.800
00:01:47.200
thing, whatever the expression you
are writing in your when

00:01:47.200
00:01:51.400
conditional statement, those
expressions we can create with

00:01:51.400
00:01:56.400
the help of comparison or membership
or test or logical operators.

00:01:56.400
00:02:00.300
So, let me expand with a simple
example by opening my

00:02:00.300
00:02:02.500
ansible controller.

00:02:02.500
00:02:04.400
So, this is my ansible controller.

00:02:04.400
00:02:06.400
Let me read a simple Playbook so that
you can understand

00:02:06.400
00:02:11.500
the usage of when. So let me reopen
my atomater.

00:02:11.600
00:02:14.800
Let me create a new file first.
00:02:14.800
00:02:20.100
So, I'm going to give you the Playbook
name as let's say

00:02:20.100
00:02:25.896
conditional_statements.yml.

00:02:25.896
00:02:27.900
So I am starting with 3 hyphens.

00:02:27.900
00:02:34.300
Then I'm giving a name for your play.

00:02:34.300
00:02:41.800
You can provide I am simply writing
Working with when conditional

00:02:41.800
00:02:49.100
statement. Let me take as of no target
as simply localhost.

00:02:49.100
00:02:55.300
And I'm writing gather_facts as false.
For the time being.

00:02:55.300
00:02:57.700
And I am defining your variables, you
can define any

00:02:57.700
00:02:58.800
number of variables. Suppose.

00:02:58.800
00:03:03.900
I am defining x, y, right. And then I am
defining some my_list

00:03:03.900
00:03:08.500
or my_sequence.

00:03:08.500
00:03:13.200
So, I am writing something called 5 6
7. That's it.

00:03:13.200
00:03:21.066
First of all, let me simply display your x
and y values. See that.

00:03:21.066
00:03:31.900
Now I am writing, under tasks section,
something called debug.

00:03:31.900
00:03:38.956
So here I am displaying, with the help
of message,

00:03:38.956
00:03:43.007
you can also right here itself, no
problem.
00:03:43.007
00:03:59.100
"The value of x is: } and y value is: }".
Right.

00:03:59.100
00:04:01.600
Let me run this Playbook and see the
result that you are

00:04:01.600
00:04:05.500
getting. After that I will club that, with
the help of

00:04:05.500
00:04:08.600
your when conditional statement.

00:04:08.600
00:04:13.926
So, you're getting the value of x is 5
and y value is 67. Right.

00:04:13.926
00:04:17.000
See I'm simply writing a condition.

00:04:17.100
00:04:20.399
I am adding a condition to your debug
module.

00:04:20.399
00:04:24.000
So, if you want to add a condition,
when condition, simply

00:04:24.000
00:04:28.200
write when. See that, how much
indentation or space is there

00:04:28.200
00:04:32.000
for debug, that much indentation you
have to provide for when.

00:04:32.000
00:04:34.400
That means you are clubbing your
module, any module.

00:04:34.400
00:04:36.000
It may be any module in our case.

00:04:36.000
00:04:37.600
Now we are using debug module.

00:04:37.600
00:04:39.700
It may be any module for that module.

00:04:39.700
00:04:44.000
You can write one condition. Now,
what I am writing is

00:04:44.000
00:04:50.900
x equals to y, so what is the meaning
for this? To execute your
00:04:50.900
00:04:57.900
debug module or debug task. If x and
y both are equal.

00:04:57.900
00:05:02.400
So, if you observe x value is 5 and y
value 67. But we are

00:05:02.400
00:05:05.200
comparing right, equal to operator is,
operation is nothing

00:05:05.200
00:05:06.800
but comparison operator.

00:05:06.800
00:05:09.200
So, x equals to y, is it true?

00:05:09.200
00:05:13.100
No, false. x is not equal to y, right. So
that's why this is

00:05:13.100
00:05:15.600
false. We are comparing for equality.

00:05:15.600
00:05:16.700
This is false.

00:05:16.700
00:05:19.700
So, if it is false, you're one condition

00:05:19.700
00:05:24.600
is skipping, is going to skip. Your when
condition is going

00:05:24.600
00:05:29.300
to skip this task, means it won't
execute. That's it.

00:05:29.300
00:05:39.000
Let me run this and see the result.
What is happening?

00:05:39.000
00:05:42.900
I removed it by mistake. Now, see
that.

00:05:42.900
00:05:48.000
Skipping why. Is skipping means the
result of this expression

00:05:48.000
00:05:49.400
is false.

00:05:49.400
00:05:53.300
Now here, you can write any
expression by using your comparison
00:05:53.300
00:05:58.200
or your memberships or test or logical
operators.

00:05:58.200
00:06:02.700
And when condition is going to
execute the task,

00:06:02.700
00:06:07.500
which is combined with that when. If
the result of this expression

00:06:07.500
00:06:11.400
is true, if this is false, this task will
skip.

00:06:11.400
00:06:13.500
I am writing one more task.

00:06:13.500
00:06:17.200
Let me write one more task like
debug.

00:06:17.200
00:06:25.500
I am writing in that message x is
present in y.

00:06:25.500
00:06:30.100
So, now I want to take a condition, if it
is really x is in y,

00:06:30.100
00:06:32.000
then only I want to execute this task.

00:06:32.000
00:06:37.200
That's why I'm checking x in y.

00:06:37.200
00:06:47.811
Anyway, we're not in y. Let's see
my_list.

00:06:47.811
00:06:51.900
See that, it says that x is 5 and 5 is
there in 5 6 7.

00:06:51.900
00:06:55.800
I mean in my_list. That's why the
result of this expression is

00:06:55.800
00:07:01.400
true. If it is true then the condition it's
going to execute with

00:07:01.400
00:07:04.100
I mean, whatever the module you club
with that when condition.
00:07:04.100
00:07:08.300
So, this module or this task we club
with when. Now this is

00:07:08.300
00:07:11.000
true. That's why it is going to execute
that's it.

00:07:11.000
00:07:15.700
So you are taking a decision. If that
result.

00:07:15.700
00:07:17.800
true, whatever the expression you're
having here.

00:07:17.800
00:07:19.300
If that is true, then execute this task.

00:07:19.300
00:07:22.800
Otherwise skip that. Now, let me run
this and see the result.

00:07:22.800
00:07:28.200
So, first task is keeping, but second
task is executing.

00:07:28.200
00:07:33.000
Because here this result is false, but
here this result is true. That's it.

00:07:33.000
00:07:36.100
So that is the simple usage of your
when condition.

00:07:36.100
00:07:40.300
Now, let me write a simple real-time
Playbook.

00:07:40.300
00:07:52.470
Let me give this Playbook name as
install_httpd_apache.yml.

00:07:52.470
00:07:56.000
See that first of all in my inventory I
have some servers.

00:07:56.000
00:08:00.800
Let's say 1 2 3, I'm including my
ansible controllers

00:08:00.800
00:08:02.500
here also. No problem.

00:08:02.500
00:08:06.100
You can take your ansible controller
also one of the nodes.
00:08:06.100
00:08:11.500
Right now, see that what I am doing is,
I want to install httpd

00:08:11.500
00:08:14.200
on all of these servers.

00:08:14.200
00:08:19.200
So, let me read a simple Playbook. So
I am writing

00:08:19.200
00:08:29.800
play name as simple play to install
httpd. Now, I am writing

00:08:29.800
00:08:35.400
target as, I'm going to give target
name as, if you observe

00:08:35.400
00:08:37.000
web servers is the target.

00:08:37.000
00:08:41.299
So I want to provide this target name
in my Playbook.

00:08:41.299
00:08:45.937
Just observe that web servers, then I
want to take

00:08:45.900
00:08:48.700
gather_facts as true.

00:08:48.700
00:08:54.700
Why, you will come to know, just wait.
Then I have to write

00:08:54.700
00:08:56.000
a simple task.

00:08:56.000
00:09:03.100
The purpose of your task is installing
httpd. That's it.

00:09:03.100
00:09:08.000
Now if you want to install httpd
package on your Linux

00:09:08.000
00:09:11.100
servers, maybe Amazon Linux or RHA
Linux.

00:09:11.100
00:09:12.800
Then you have to take yum.

00:09:12.800
00:09:18.500
Now yum name of my package is
httpd.
00:09:18.500
00:09:23.900
Then state I want to provide it as latest
or present.

00:09:23.900
00:09:25.800
That's it. Let me save it.

00:09:25.800
00:09:28.800
Anyway, you know that. If you want to
install any package,

00:09:28.800
00:09:30.800
you should have a root privileges now.

00:09:30.800
00:09:33.200
Anyway, we know that for our name
user, already

00:09:33.200
00:09:36.300
we provided root privileges. But we
need to mention that

00:09:36.300
00:09:39.700
while executing your task, saying that,
please excuse this

00:09:39.700
00:09:41.100
with root privileges.

00:09:41.100
00:09:44.800
So, for then you need to add an option
called become: yes.

00:09:44.800
00:09:46.561
So here we are adding become: yes

00:09:46.561
00:09:50.300
in the task level. For all tasks, if you
want to mention become: yes,

00:09:50.300
00:09:52.600
You can also write here.

00:09:52.600
00:09:56.000
If right here become yes, you're going
to provide for all

00:09:56.000
00:09:57.900
tasks sudo privileges.

00:09:57.900
00:09:59.800
So as of now, I have only one task.

00:09:59.800
00:10:02.600
I'm writing in the task level become:
yes.
00:10:02.600
00:10:08.200
Now, let me run this Playbook and see
the result it is giving.

00:10:08.200
00:10:12.100
So, our Playbook name is
install_httpd_apache.yml

00:10:12.100
00:10:15.900
just after the output. That's it

00:10:15.900
00:10:20.000
See, we are having this as 1 task, you
know by default

00:10:20.000
00:10:22.300
setup module. Set up module will
execute there, is nothing but

00:10:22.300
00:10:27.000
gather facts. Then the second task is
our defined tasks.

00:10:27.000
00:10:30.500
The first task has been executed, now
the second task is executing

00:10:30.500
00:10:44.800
installing httpd. See that if we observe
in the output for

00:10:44.800
00:10:49.300
this server and last server, it has been
changed. Means your

00:10:49.300
00:10:53.400
httpd has been installed. But while
working with this server

00:10:53.400
00:10:58.800
there's something wrong, that is that it
could not find aptitude.

00:10:58.800
00:11:04.800
Using apt-get instead. It means on this
server yum is not working.

00:11:04.800
00:11:09.700
Please use apt-get. That means you
know that, if your server

00:11:09.700
00:11:13.300
is Amazon Linux or RHL Linux or Stent
ways, then you can install
00:11:13.300
00:11:17.200
any package with yum. If it is open to
distribution you have

00:11:17.200
00:11:25.000
to use apt-get. That's why your task is
failing here.

00:11:25.000
00:11:30.000
So now see your manager notes,
maybe combination of any distribution.

00:11:30.000
00:11:32.200
That's why, while writing your
Playbooks,

00:11:32.200
00:11:35.300
you have to write a condition. If so-
and-so distribution use

00:11:35.300
00:11:40.000
yum, if so-and-so distribution use apt,
right. If you

00:11:40.000
00:11:43.100
remember. Let me do one thing.

00:11:43.100
00:11:50.900
First of all. Let me write debug.

00:11:50.900
00:11:56.300
So, if you remember, there is a default
variable called

00:11:56.300
00:12:00.400
from your ansible facts, ansible
distribution.

00:12:00.400
00:12:07.192
It is going to give you the remote node
OS distribution. Let me write.

00:12:07.192
00:12:15.800
The distribution of .... I will do one
thing.

00:12:15.800
00:12:21.100
Node is:. If you remember, by default
you can

00:12:21.100
00:12:25.300
get your node with the help of
inventory hostname.

00:12:25.300
00:12:27.200
And for this hostname.
00:12:27.200
00:12:32.440
What is the distribution, I want to see.

00:12:32.400
00:12:36.700
So, if you remember, there is a
variable called ansible distribution.

00:12:36.700
00:12:40.300
This variable is going to view the
distribution type.

00:12:40.400
00:12:44.000
I mean your voice type, ways
distribution type. Now, let me

00:12:44.000
00:12:46.300
save it and run it.

00:12:46.300
00:12:52.000
The 54.165.97.91 you are getting
failed, your task is getting fail.

00:12:52.000
00:12:55.400
The reason is, you have to use apt for
that instead of yum,

00:12:55.400
00:12:57.200
because that is open to distribution.

00:12:57.200
00:13:02.300
Let me find them through your
Playbook.

00:13:02.300
00:13:09.200
Just after the output.

00:13:09.200
00:13:11.800
Gathering facts, there is a default task
you are excluding.

00:13:11.800
00:13:15.700
Once it is done, see that.

00:13:15.700
00:13:21.550
One node is Ubuntu. This is Amazon.
This is Centos.

00:13:21.550
00:13:24.800
Your task failed on this server only,
right. 68 see that.

00:13:24.800
00:13:27.000
Because that is open to server. If it is
open, you have

00:13:27.000
00:13:33.400
to use apt. So that's why that you have
to do is, see that,
00:13:33.400
00:13:39.900
while writing your Playbooks to install
your httpd or Apache.

00:13:39.900
00:13:45.500
See how I'm going to do that now.

00:13:45.500
00:13:55.600
Name: Installing httpd using yum. Why
I am saying yum means,

00:13:55.600
00:14:00.400
let me write first syntax for your yum,
name httpd, then state

00:14:00.400
00:14:04.200
present. But I need to write a condition
here, when this task

00:14:04.200
00:14:10.200
has to be executed if, ansible
distribution is, if when means,

00:14:10.200
00:14:16.368
if with ansible distribution, if it is equal
to Ubuntu.

00:14:16.368
00:14:19.900
Let me take that distribution name
exactly.

00:14:19.900
00:14:25.819
Sorry not open to write.

00:14:25.819
00:14:32.300
Amazon or CentOS or Linux, or simply
if it is not equal to.

00:14:32.300
00:14:37.700
As of now in our case, based on our
managing notes.

00:14:37.700
00:14:40.700
If it is not equal to 1 to use yum, if it is
open 2 then

00:14:40.700
00:14:47.700
write one more task. Name: Installing
apache2 using apt.

00:14:47.700
00:14:53.700
Nice for Ubuntu to take your web
server name as apache2.

00:14:53.700
00:14:59.900
Using apt package, apt module. Now
see that, apt options are,
00:14:59.900
00:15:07.600
parameters are same, name is
apache2 and state is present.

00:15:07.600
00:15:09.800
But here we need to write a condition.
When we have to execute

00:15:09.800
00:15:15.100
this task if, if ansible distribution
means operating system

00:15:15.100
00:15:17.700
distribution is open to, then here I
have to write equal

00:15:17.700
00:15:28.400
condition. I will explain that clearly so
that you can understand.

00:15:28.400
00:15:30.300
That's it.

00:15:30.300
00:15:33.600
So before going to run this Playbook,
let me explain this

00:15:33.600
00:15:37.800
with a simple diagram. Just wait.

00:15:37.800
00:15:47.800
I'm going to explain that with simple
diagram.

00:15:47.800
00:15:52.600
Let me save it as something called
install http.yml.

00:15:52.600
00:15:59.237
Install_httpd.apache.yml.

00:15:59.237
00:16:04.400
on my local server. Now just wait.

00:16:04.400
00:16:08.300
See that, you are running this
Playbook from your ansible

00:16:08.300
00:16:12.600
controller and in your web servers
group, we have 3 servers,

00:16:12.600
00:16:14.800
one is localhost, no problem.

00:16:14.800
00:16:18.300
Then one is Amazon Linux and one
more is Ubuntu. This is
00:16:18.300
00:16:22.100
Amazon, this is Amazon Linux and
this is CentOS.

00:16:22.100
00:16:26.300
Whenever you run this Playbook, this
Playbook is going

00:16:26.300
00:16:29.800
to copy for each and every server.

00:16:29.800
00:16:32.900
And your Playbook is going to run on
your remote server

00:16:32.900
00:16:35.800
on your manage server, right,

00:16:35.800
00:16:39.600
So, while executing your ansible, we'll
find out by default

00:16:39.600
00:16:42.200
ansible distribution.

00:16:42.200
00:16:47.400
If it is open to, then this task is going

00:16:47.400
00:16:51.300
to execute, and this is going to skip.
Because if it is open

00:16:51.300
00:16:54.600
to ansible distribution, is open too,
then this one condition

00:16:54.600
00:16:59.861
is going to get true.

00:16:59.861
00:17:01.600
This one condition is going to get a
true.

00:17:01.600
00:17:04.300
This condition is going to be true. If it
is true

00:17:04.300
00:17:07.500
then is going to allow to execute this
task. But on

00:17:07.500
00:17:11.900
open to server, this value, the result of
this value is false.

00:17:11.900
00:17:15.300
That's why this task is going to skip.
But on remaining two
00:17:15.300
00:17:19.098
servers Amazon Linux and CentOS,

00:17:19.098
00:17:21.598
the first condition is going to become
true.

00:17:21.598
00:17:24.300
That's why the first task is going to
execute on your

00:17:24.300
00:17:28.200
remaining 2 servers. But on your
remaining two servers,

00:17:28.200
00:17:31.599
the second when condition result, is
going to get false. If

00:17:31.599
00:17:36.599
it is false, then this task is going to
skip. That's it.

00:17:36.599
00:17:43.200
Right, now let me open your Playbook
and let me save it.

00:17:43.200
00:17:45.700
I am going to run this now.

00:17:45.700
00:17:50.400
Now be clear how it is going to
execute.

00:17:50.400
00:17:57.100
So, first task is going to skip for
Ubuntu server, and second

00:17:57.100
00:18:01.200
task is going to skip for non open to
distribution.

00:18:01.200
00:18:06.600
See that, skipping. For what service is
skipping. 68 is open to server.

00:18:06.600
00:18:09.500
We know that. That's why the first task
is skipping for that

00:18:09.500
00:18:12.000
and on remaining 2 services it has
been executed.

00:18:12.000
00:18:18.000
The second task installing apache2, is
skipping for your first 2 servers.
00:18:18.000
00:18:23.900
Right. You got an error because, you
have to provide root

00:18:23.900
00:18:26.100
privileges. So anyway already
installed.

00:18:26.100
00:18:28.600
That's why it is not giving any error.

00:18:28.600
00:18:32.200
So I can provide based on task level.

00:18:32.200
00:18:36.300
I mean task level become yes. And
here also for this task

00:18:36.300
00:18:38.987
also I can write become: yes.

00:18:38.987
00:18:41.500
Yes, but instead of writing into place
has become yes. Because

00:18:41.500
00:18:44.800
I have only 2 tasks and for these 2
tasks, I need become.

00:18:44.800
00:18:48.900
That's why for all tasks, if you want to
mention by default become

00:18:48.900
00:18:53.400
yes, you have to write here. Before
starting your task

00:18:53.400
00:18:55.662
if you write become yes, for all tasks

00:18:55.662
00:18:58.300
you are executing with sudo
privileges. That's it.

00:18:58.300
00:19:07.477
Let me rerun. Now see the result.

00:19:07.477
00:19:13.100
Just wait, you're going to get your
result here.

00:19:13.100
00:19:17.900
So httpd using yum is going to skip
Ubuntu server, but the task

00:19:17.900
00:19:19.600
is installing for your first 2 servers
00:19:19.600
00:19:23.200
I mean, remaining 2 servers. Apache2
using apt skipping for

00:19:23.200
00:19:26.000
your 2 servers. But it is going to work
for your Ubuntu

00:19:26.000
00:19:32.400
server. So that is the usage of your
yum condition statement.

00:19:32.400
00:19:36.708
Right, so ok equals 2, but changed 0
on these 2 servers.

00:19:36.708
00:19:38.700
Because previously we installed our
HTTP.

00:19:38.700
00:19:41.500
Now, let me remove them.

00:19:41.500
00:19:44.600
So, if you want to remove, just simply
write

00:19:44.600
00:19:53.400
state as absent. Be clear.

00:19:53.400
00:19:58.000
I have written this logic when your
remote server distribution

00:19:58.000
00:20:01.200
is not equals to Ubuntu. Other time on
that server

00:20:01.200
00:20:04.590
this task will execute, right. In case it
is open,

00:20:04.500
00:20:06.200
this task will execute.

00:20:06.200
00:20:09.800
So if this is executing your first task, is
going to skip.

00:20:09.800
00:20:12.500
If your first task is going to execute on
your manager node,

00:20:12.500
00:20:14.800
then definitely second task is going to
skip. That's what we need.
00:20:15.400
00:20:19.000
That's why when condition are very
very important to write

00:20:19.000
00:20:23.400
your tasks based on some condition.
Right.

00:20:23.400
00:20:26.800
So, we will write a different Playbook
for your real

00:20:26.800
00:20:29.178
time. So you can understand
effectively the uses

00:20:29.178
00:20:30.800
of your when. For the time being,

00:20:30.800
00:20:35.400
these are the simple uses of your
when condition statement.

00:20:35.400
00:20:38.400
Right, now let me remove them. Did I
save all this?

00:20:38.400
00:20:40.300
Let me save it now.

00:20:40.300
00:20:44.400
While running, it is going to uninstall
you're

00:20:44.400
00:20:47.300
Apache or HTTP on your managing
nodes.

00:20:47.300
00:20:50.800
So, while displaying your task, if you
want to change the name,

00:20:50.800
00:20:55.300
you can write simple play to uninstall
httpd. Uninstalling

00:20:55.300
00:20:58.600
httpd, uninstalling httpd.

00:20:58.600
00:21:00.800
If you want to write you can just start
the name, it will write.

00:21:00.800
00:21:07.700
You can write it. No problem.
00:21:07.700
00:21:13.200
That is going to uninstall on our
Ubuntu Server.

00:21:13.200
00:21:17.400
So, these 2 tasks have been executed
on Ubuntu distribution.

00:21:17.400
00:21:20.300
And this task has been executed on
Ubuntu distribution.

00:21:20.300
00:21:23.726
That's it. So far that I have taken on
condition

00:21:23.726
00:21:27.304
and try to understand this one. Right.

00:21:27.304
00:21:32.500
This is a simple way to use your when
conditions when

00:21:32.500
00:21:34.250
in your Playbooks. Okay.

00:21:34.200
00:21:41.000
Thank you for watching this video.
Transcript
00:00:00.000
00:00:02.600
Friends, here

00:00:02.600
00:00:07.210
our concept is in line conditional
statement of ansible playbooks.

00:00:07.200
00:00:10.800
See this concept is very simple, but
very useful while writing

00:00:10.800
00:00:14.400
your playbooks. See first of all in line
conditional statement

00:00:14.400
00:00:18.400
is nothing but simply if/else. So, you
know, the functionality

00:00:18.400
00:00:22.410
of if/else from your other programming
or scripting languages.

00:00:22.400
00:00:26.010
So that is called here simply inline
conditional statement
00:00:26.000
00:00:31.510
and this is useful for debug or to
define your variable values.

00:00:31.500
00:00:36.100
Let me use the simple example or
usage of your if/else with

00:00:36.100
00:00:37.900
help of a playbook now.

00:00:37.900
00:00:41.510
Let me open my ansible controller.

00:00:41.500
00:00:44.210
Let me open my Atom meter.

00:00:44.200
00:00:48.200
So here I opened my atom meter by
navigating into my practice

00:00:48.200
00:00:49.309
directory there.

00:00:49.300
00:00:54.309
I ran the command called "atom ."

00:00:54.300
00:00:56.400
Now, let me take a simply new
playbook.

00:00:56.400
00:00:58.610
[no audio]

00:00:58.600
00:01:08.410
So, let me save it as "inline_condi.yml"

00:01:08.400
00:01:10.610
See very simple.

00:01:10.600
00:01:14.310
Let me write a simply name

00:01:14.300
00:01:21.600
"simple usage of inline conditional
statement if else"

00:01:21.624
00:01:32.510
[no audio]

00:01:32.500
00:01:33.310
That's it.

00:01:33.300
00:01:33.400
Now.

00:01:33.400
00:01:40.500
Let me take my target as localhost
and let me disable gather
00:01:40.500
00:01:43.510
facts then.

00:01:43.500
00:01:45.300
Let me write define some variables.

00:01:45.300
00:01:51.610
Let's say I want to define a variable x:
5, y:9

00:01:51.600
00:01:52.500
Now guys here,

00:01:52.500
00:01:57.100
my requirement is: I want to display x
value if x is greater

00:01:57.100
00:02:01.200
than y or I want to display y value if y
is greater than

00:02:01.200
00:02:04.310
x or simply

00:02:04.300
00:02:07.500
for your given x and y, whatever the
largest number, whatever

00:02:07.500
00:02:11.410
the higher number than that number, I
want to print.

00:02:11.400
00:02:16.010
See first forget about your if/else or
inline condition statement.

00:02:16.000
00:02:19.010
Now, let me write simply your tasks.

00:02:19.000
00:02:25.510
I mean to get the higher value or
largest value for

00:02:25.500
00:02:27.209
x and y.

00:02:27.200
00:02:30.800
So if you remember we have a when
conditional statement. See

00:02:30.800
00:02:34.109
I am doing simply debug.

00:02:34.100
00:02:41.209
Let me write a simply message "The
larger

00:02:41.200
00:02:51.700
number of x and y is: so here.
00:02:51.700
00:02:54.700
I am displaying x without checking
condition and displaying

00:02:54.700
00:02:56.800
x, but it to execute this, simply

00:02:56.800
00:03:01.500
I'm writing when condition when so I
want to execute this

00:03:01.500
00:03:05.100
task if x is greater than y, so that's why
I'm writing in

00:03:05.100
00:03:08.209
this way.

00:03:08.200
00:03:10.900
So in case if x is greater than y I want
to execute this

00:03:10.900
00:03:16.300
task, maybe x is less than y or y
greater than x so to check

00:03:16.300
00:03:18.800
y greater than x, I am going to write
one more task.

00:03:18.800
00:03:21.910
Let's say debug.

00:03:21.900
00:03:33.910
so message "The larger number of
your x and y

00:03:33.900
00:03:38.300
is: y". But I want to exclude this
second task if y greater

00:03:38.300
00:03:43.111
than x. Right? Now first, let me run
simply this playbook.

00:03:43.111
00:03:47.109
[no audio]

00:03:47.100
00:03:51.000
inline just after the output what you
are getting.

00:03:51.024
00:03:54.709
[no audio]

00:03:54.700
00:03:56.200
Just after the output.
00:03:56.224
00:04:00.010
[no audio]

00:04:00.000
00:04:08.410
Why it's taking time. Yeah, see that.

00:04:08.400
00:04:10.810
Oh, sorry.

00:04:10.800
00:04:14.609
We need to display the x or y values,
right?

00:04:14.600
00:04:16.800
So whenever if you want to display the
value you have to write your

00:04:16.800
00:04:20.510
variable inside of your curly braces.

00:04:20.500
00:04:23.510
Now, let me run and see the result.

00:04:23.500
00:04:25.110
See what you are getting.

00:04:25.100
00:04:29.409
The first task is skipping. It is not
executing. Skipping means

00:04:29.400
00:04:31.210
that task is not executing.

00:04:31.200
00:04:34.900
What is the reason to skip this means
see the first task

00:04:34.900
00:04:38.700
is, I have to execute this task. Be
clear.

00:04:38.700
00:04:44.300
I have to execute this task if when or if
or when x greater

00:04:44.300
00:04:48.600
than y. So that we can check with the
help of when condition.

00:04:48.600
00:04:51.700
So I am attaching when condition for
this task.

00:04:51.700
00:04:55.600
So execute this task if this condition is
satisfied x greater
00:04:55.600
00:04:59.000
than y no as per your five and nine
values x greater than

00:04:59.000
00:04:59.700
y is false.

00:04:59.700
00:05:03.010
So that's why it is skipping.

00:05:03.000
00:05:06.200
y greater than x, yes . 9 > 5? The 5
second task

00:05:06.200
00:05:09.400
is executing. In case if we change
your x and y values now

00:05:09.400
00:05:12.710
first task is going to execute because I
am taking x as 15

00:05:12.700
00:05:15.310
now see the result.

00:05:15.300
00:05:16.700
First task is executing.

00:05:16.700
00:05:20.510
But second task is skipping. Now in
this case,

00:05:20.500
00:05:24.500
I don't want to write two tasks to get
the higher value or

00:05:24.500
00:05:27.510
larger value for your given values.

00:05:27.500
00:05:30.000
I want to write only one task, but I
want to get a maximum

00:05:30.000
00:05:32.200
number or larger number for

00:05:32.200
00:05:34.810
you're given two numbers.

00:05:34.800
00:05:42.310
Very simple first, let me I will remove
this.

00:05:42.300
00:05:46.100
See simply I am writing because
otherwise I will take this

00:05:46.100
00:05:48.500
code. I will do one thing.
00:05:48.500
00:05:51.010
I will take a backup.

00:05:51.000
00:05:52.700
Because I want to share this code as
well.

00:05:52.724
00:05:57.409
[no audio]

00:05:57.400
00:06:02.810
Now see here I am removing this.

00:06:02.800
00:06:06.900
Now simply while defining here,

00:06:06.900
00:06:15.000
what I am doing is, see that? Display x
value if, be clear,

00:06:15.000
00:06:22.600
if x greater than y very simple one.
Else y in case if x

00:06:22.600
00:06:24.900
is greater than y then it will display this
value.

00:06:24.900
00:06:28.409
I mean in place of this curly braces.

00:06:28.400
00:06:32.300
Let me write curly braces ending so
concentrate on last curly

00:06:32.300
00:06:36.200
braces value - last in the syntax.

00:06:36.224
00:06:38.210
[no audio]

00:06:38.200
00:06:41.800
Get x if x greater than y in case if x is
not greater than

00:06:41.800
00:06:44.900
y then you are going to get in place of
this entire syntax

00:06:44.900
00:06:48.700
y value. See very simple. Now, let me
run this and see the

00:06:48.700
00:06:49.801
result.

00:06:49.801
00:06:55.500
[no audio]
00:06:55.524
00:06:57.010
So what is the number I'm getting 9,
15 and 9. 15.

00:06:57.000
00:07:00.510
Now, let me modify second number I
suppose 19.

00:07:00.500
00:07:04.300
See instead of two tasks now with the
help of inline conditional

00:07:04.300
00:07:07.600
statement without having been
conditioned or without having

00:07:07.600
00:07:10.400
two tasks. Right?

00:07:10.400
00:07:13.200
We are getting our required output
with the help of inline

00:07:13.200
00:07:15.510
condition statement.

00:07:15.500
00:07:15.800
That's it.

00:07:15.800
00:07:16.200
See now.

00:07:16.200
00:07:19.200
You're getting 15 and 19. 19 is the
highest number, larger

00:07:19.200
00:07:27.900
number. Now not only this instead of
this you just delete

00:07:27.900
00:07:33.500
it. See I am writing a variable called
larger, but here I

00:07:33.500
00:07:36.110
am defining this syntax.

00:07:36.100
00:07:36.200
Now.

00:07:36.200
00:07:40.400
What is the larger number means: get
x if x greater than y

00:07:40.400
00:07:45.210
else y. So get larger number as x if x
greater than y else
00:07:45.200
00:07:46.909
y number. That's it.

00:07:46.900
00:07:49.409
Very simple, no?

00:07:49.400
00:07:52.909
Now. Here just print with the larger.

00:07:52.900
00:07:54.510
That's it.

00:07:54.500
00:07:58.900
So you can also write your y inside of
parentheses.

00:07:58.900
00:08:01.500
No problem. Now see the result.

00:08:01.500
00:08:03.500
[no audio]

00:08:03.500
00:08:04.800
You're getting 19. Now.

00:08:04.800
00:08:05.400
Let me modify.

00:08:05.400
00:08:05.900
First number.

00:08:05.900
00:08:07.900
I suppose some 155.

00:08:07.900
00:08:09.900
[no audio]

00:08:09.900
00:08:14.300
Save it. Now previously got output as
19, 15 and 19.

00:08:14.300
00:08:19.010
Now you are going to get result as
155.

00:08:19.000
00:08:20.210
That's it.

00:08:20.200
00:08:24.100
So guys, this is the simple usage of
you are inline condition

00:08:24.100
00:08:28.800
statement. Maybe this is simply
generalized example, but

00:08:28.800
00:08:30.900
while writing your playbooks you will
use effectively this
00:08:30.900
00:08:32.010
syntax.

00:08:32.000
00:08:32.510
Okay.

00:08:32.500
00:08:36.799
So first I am going to give you only
concepts. Once we are

00:08:36.799
00:08:39.610
good with some minimum concept
then we will try to write

00:08:39.600
00:08:42.010
our real-time scripts.

00:08:42.000
00:08:49.702
Okay guys, thank you for watching this
video.
Transcript
00:00:00.000
00:00:01.700
Friends, here

00:00:01.800
00:00:04.099
our concept is ansible handlers.

00:00:04.400
00:00:07.700
See this ansible handlers are just like
regular tasks in

00:00:07.700
00:00:11.400
your ansible playbook see first
assume that you're having

00:00:11.400
00:00:16.200
two tasks and you want to execute the
second task.

00:00:16.300
00:00:22.500
If the first task is changed simply if the
first task is

00:00:22.500
00:00:26.500
changed then only one run the second
task the in that case
00:00:26.500
00:00:31.000
how we can write a play book and
what is the Help from your

00:00:31.000
00:00:32.700
handlers in that case.

00:00:33.100
00:00:36.000
Let me explain this concept with the
simple Playbook.

00:00:36.300
00:00:38.800
So I am going to open my ansible
controller.

00:00:39.400
00:00:41.500
So here I am going to write a play
book.

00:00:41.900
00:00:44.000
So my playbook consists of two tasks.

00:00:44.500
00:00:48.500
So the second task depends on the
first task and that second

00:00:48.500
00:00:52.100
task will execute if the first task
changed first.

00:00:52.100
00:00:55.900
Let me write a play book without using
handlers concept see

00:00:55.900
00:00:57.100
that I am writing.

00:00:58.500
00:01:02.100
A playbook so I'm taking name as
Handler underscore concept

00:01:02.100
00:01:02.900
dot yml.

00:01:03.500
00:01:06.400
So here I am going to write two tasks
in my playbook.

00:01:07.200
00:01:11.300
So the first task is installing httpd, and
the second task

00:01:11.300
00:01:13.700
is starting your httpd.

00:01:14.200
00:01:20.000
Now, let me take Target as simply my
local host and here
00:01:20.000
00:01:23.000
I don't want to collect gather facts.

00:01:25.800
00:01:28.800
So let me disable my gather facts.

00:01:30.300
00:01:33.900
Simply with the false installing httpd.

00:01:33.900
00:01:38.000
I want to execute the task with root
privileges.

00:01:38.000
00:01:39.300
That's why I am writing here become.

00:01:39.300
00:01:39.900
Yes.

00:01:40.900
00:01:42.600
Then I am writing under tasks section.

00:01:42.700
00:01:51.300
The first task is simply installing httpd,
then let me install

00:01:51.300
00:01:52.300
my httpd.

00:01:52.300
00:01:56.300
So as of now my local his my Local
Host is send ways distribution

00:01:56.300
00:01:58.800
that I am taking a module as IAM.

00:01:59.000
00:02:01.100
So let me take name as httpd.

00:02:01.800
00:02:04.300
Then provide state is simply present.

00:02:04.700
00:02:05.300
That's it.

00:02:05.500
00:02:07.200
So this is the task.

00:02:07.700
00:02:10.900
This is the task to install your httpd.

00:02:11.400
00:02:15.300
But now I want to start that httpd as
well.

00:02:15.700
00:02:20.700
Then let me write one more task start
httpd then see if you

00:02:20.700
00:02:22.100
want to start any service.
00:02:22.100
00:02:24.500
You have to take service module then
for that.

00:02:24.500
00:02:27.700
You have to provide name your
required service name then

00:02:27.700
00:02:30.500
State as like, you know, if you want to
start you have to

00:02:30.500
00:02:35.400
write started if you want to stop stop if
you want to restart

00:02:35.400
00:02:37.200
your service, you have to write
restarted.

00:02:37.800
00:02:42.600
So now if we observe we are having
two tasks in our Playbook.

00:02:43.600
00:02:47.700
But If You observe here there is no
dependency of your second

00:02:47.700
00:02:50.600
task on your first task now I need to
create a dependency

00:02:50.600
00:02:54.000
of your second task, I mean on your
for your second task

00:02:54.000
00:02:59.200
on your first task that is let me capture
the output result

00:02:59.200
00:03:05.900
of your first tasks by using simply
register register out

00:03:06.200
00:03:09.600
now I am writing for your second task
a condition what is

00:03:09.600
00:03:13.200
that is when from your first task what
is what is whatever

00:03:13.200
00:03:17.700
the output you are getting in that I am
checking change if
00:03:17.700
00:03:19.100
that change it is true.

00:03:20.700
00:03:22.600
Then only X good second task.

00:03:22.700
00:03:27.900
So simple thing is one task is just
simply installing httpd,

00:03:28.500
00:03:32.200
then while installing the result, you
know, the status of

00:03:32.200
00:03:36.500
your executed tasks will store into this
out variable with

00:03:36.500
00:03:37.500
the help of register.

00:03:38.100
00:03:42.100
Now in this out there is a key called
change if that is equal

00:03:42.100
00:03:42.800
to true.

00:03:43.700
00:03:47.200
Means because of this something has
been changed then only

00:03:47.200
00:03:48.300
I want to execute this.

00:03:48.700
00:03:53.100
So I have created a dependency of
your second task on your

00:03:53.100
00:03:57.200
first task by using simply this one
condition right now.

00:03:57.800
00:04:01.600
So first, let me check there is no HTTP
service on my host.

00:04:01.900
00:04:02.100
Now.

00:04:02.100
00:04:05.300
We have a play book called Handler
underscore concept dot

00:04:05.300
00:04:07.600
yml. Let me run that Playbook.

00:04:09.000
00:04:10.000
Now see the result.
00:04:12.500
00:04:15.000
Just observe the output installing
httpd.

00:04:18.700
00:04:22.300
So it is installing our httpd that means
it is changing something

00:04:22.300
00:04:24.100
on your host change it true.

00:04:24.500
00:04:26.700
First task changed value is true.

00:04:28.399
00:04:32.300
That's why it is going to execute the
second task.

00:04:32.400
00:04:33.000
Just wait.

00:04:33.000
00:04:34.500
Once the installation is completed.

00:04:34.500
00:04:36.500
Then it will execute the second task.

00:04:36.500
00:04:38.800
That is starting your httpd.

00:04:39.400
00:04:40.400
Yes, see that.

00:04:40.800
00:04:43.600
If You observe in the output of your
first tasks change.

00:04:43.900
00:04:44.900
Yes, it's true.

00:04:46.700
00:04:53.200
Right then second task change why
second task changed because

00:04:53.900
00:04:55.200
this condition is true.

00:04:55.900
00:04:57.700
That's why it is executing second task.

00:04:57.800
00:05:01.600
Now if I rerun see the result you are
going to skip the second

00:05:01.600
00:05:05.800
- no because already we have httpd
know even if you try to
00:05:05.800
00:05:07.900
install with your playbook, it won't
install that means it

00:05:07.900
00:05:08.900
is not changing.

00:05:09.400
00:05:11.800
So the Task 1 changed is false.

00:05:11.800
00:05:13.900
That's why it is going to skip the
second task.

00:05:14.700
00:05:17.300
Be clear for your first task.

00:05:17.300
00:05:20.300
Now you are getting okay not change
change.

00:05:20.300
00:05:23.800
It means if you install httpd if your
playbook is going to

00:05:23.800
00:05:27.600
install your httpd then only it would be
changed but already

00:05:27.600
00:05:31.600
httpd is there because just now
previously we install our

00:05:31.600
00:05:32.700
HTTP, right?

00:05:32.700
00:05:35.800
That's why if we rerun your playbook it
is not going to install

00:05:35.800
00:05:38.400
that means it is not going to change
that means first task

00:05:38.400
00:05:40.900
is it is first task is not changing.

00:05:41.700
00:05:43.400
That's why second task is skipping.

00:05:44.200
00:05:44.800
That's fine.

00:05:45.500
00:05:49.200
No, my requirement is your first of all
our basic requirement.

00:05:49.200
00:05:51.900
We reach in case if it is skipping.
00:05:51.900
00:05:53.300
Why should we display this?

00:05:54.700
00:05:58.800
If it is skipping, why should we display
this you guys one

00:05:58.800
00:05:59.100
more thing?

00:05:59.100
00:06:00.400
You may get confused here.

00:06:00.900
00:06:08.600
You just check the value of your out
Dot changed so that

00:06:08.600
00:06:09.400
it can understand.

00:06:09.400
00:06:12.500
What is the value you're getting let me
rerun that first.

00:06:17.600
00:06:18.100
What happened?

00:06:18.300
00:06:19.000
Yeah, sorry.

00:06:20.600
00:06:24.900
y equals two or you can go also go
with message.

00:06:24.900
00:06:25.400
No problem.

00:06:28.500
00:06:32.500
See the result installing httpd means it
is not installing

00:06:32.500
00:06:35.200
actually it just checking whether
already it is there or

00:06:35.200
00:06:38.600
not in case if it is not there then only it
will install

00:06:38.700
00:06:39.400
but already there.

00:06:39.400
00:06:43.200
We know that that's why what is the
value of out change false

00:06:43.900
00:06:46.500
if it is false then you are going to skip
this because we
00:06:46.500
00:06:48.900
have create a condition where your
second task.

00:06:50.300
00:06:53.000
Right now anyway guys, this is just for
our understanding

00:06:53.000
00:06:56.400
of return this debug module task forget
about that.

00:06:57.200
00:07:01.900
Now if first task is not changing then
you're skipping second

00:07:01.900
00:07:05.400
task. If you are skipping then why
should be displayed I

00:07:05.400
00:07:06.200
don't want display.

00:07:09.700
00:07:15.200
basically You are executing second
task if first task change.

00:07:16.200
00:07:18.000
Right for that you're writing your
condition.

00:07:19.200
00:07:22.400
Now the same thing you can achieve
with the help of handlers.

00:07:23.000
00:07:25.800
Now how we can write handlers
means nothing.

00:07:25.800
00:07:29.200
Is there even in order to register your
out also automatically

00:07:29.200
00:07:32.400
you are Playbook will take care with
the help of handlers

00:07:32.400
00:07:36.500
section. First of all handlers are
exactly equal to your

00:07:36.500
00:07:38.400
tasks the way how you are writing.

00:07:38.400
00:07:40.400
You are task the same way.
00:07:40.400
00:07:42.800
You have to write your handlers then
first.

00:07:42.800
00:07:45.900
Let me write my second task under my
Handler name.

00:07:46.300
00:07:48.700
Simply I'm giving start httpd.

00:07:50.900
00:07:53.300
Then I want to service.

00:07:53.300
00:07:56.700
I want to start my service right then go
with service module

00:07:57.100
00:07:59.600
service then provide the name.

00:07:59.900
00:08:04.900
What is the name httpd then provide
the state I want to start.

00:08:05.000
00:08:09.500
So you have to write started then it will
start that's fine.

00:08:10.300
00:08:14.600
Now as of now, we have one task
under your Tas section and

00:08:14.600
00:08:16.800
one task under your Handler section.

00:08:17.300
00:08:20.200
Always your tan section tasks will
execute.

00:08:21.500
00:08:24.300
And Handler sections, whatever the
task you are having under

00:08:24.300
00:08:25.100
Handler section.

00:08:25.100
00:08:26.700
They won't execute by default.

00:08:26.700
00:08:27.800
You need to call them.

00:08:29.000
00:08:34.000
Right now see to call my the task
which is there and you

00:08:34.000
00:08:35.000
are Handler section.
00:08:35.000
00:08:38.299
So guys, this is also a task right into
start with - sorry.

00:08:38.299
00:08:39.799
I forgot to give that.

00:08:42.600
00:08:44.900
- name yeah, that's fine.

00:08:48.799
00:08:53.900
See my requirement is if this first task
has been changed

00:08:53.900
00:08:57.500
then only I want to execute this task
then other time.

00:08:57.600
00:09:03.700
You can do very simple syntax notify
notify under that just

00:09:03.700
00:09:07.300
mention the name of your task, which
is there under your

00:09:07.300
00:09:12.400
Handler section or the task which you
want to execute if

00:09:12.500
00:09:15.800
your current task modifying something
on your host or if

00:09:15.800
00:09:18.400
your current task change while
running your playbook.

00:09:19.500
00:09:23.100
Now how it will work means by default
the tasks, which are

00:09:23.100
00:09:24.400
there under Handler section.

00:09:24.400
00:09:27.800
They won't exclude, you know that
tasks section will execute

00:09:27.800
00:09:30.600
one by one, but Handler section one
takes good by themselves.

00:09:31.300
00:09:32.400
We need to call them.
00:09:32.400
00:09:36.400
So how to call means from your Tas
section any one of from

00:09:36.400
00:09:39.900
you any one of your tasks based on
your requirement now,

00:09:39.900
00:09:44.400
I need to execute this task if this task
change that means

00:09:44.400
00:09:47.000
suppose if you are going to install if
we are going to install

00:09:47.000
00:09:48.400
fresh installation of your HTTP.

00:09:48.500
00:09:50.500
D then only I want to start it.

00:09:50.600
00:09:53.100
Then you have to write this notify
section here.

00:09:53.400
00:09:58.100
See that e m and notify indentations or
same be clear and

00:09:58.100
00:10:01.600
for TAS section and for Handler
sections indentations or

00:10:01.600
00:10:04.400
same. Right, that's it.

00:10:05.000
00:10:05.200
Now.

00:10:05.200
00:10:07.800
Let me run this see the result.

00:10:08.200
00:10:10.800
Anyway already httpd is there that's
why Handler section

00:10:11.500
00:10:12.100
what happened?

00:10:24.300
00:10:24.700
Yeah.

00:10:26.800
00:10:28.900
So indentations are very very
important.
00:10:28.900
00:10:31.500
How much space is there for tasks
section that much space

00:10:31.500
00:10:32.800
you need 400 section.

00:10:33.400
00:10:34.000
That's it.

00:10:39.300
00:10:43.100
Now see the result installing httpd, it is
not installing

00:10:43.100
00:10:46.800
because already is there so if it is
there it is not changing.

00:10:47.800
00:10:50.400
If you install then only it is going to
change you are not

00:10:50.400
00:10:52.300
installing. I mean your playbook is not
installing.

00:10:52.300
00:10:53.800
That's why okay.

00:10:53.900
00:10:55.000
Okay me is not change.

00:10:55.000
00:10:59.300
That's why it is not calling your
Handler section under Handler

00:10:59.300
00:11:02.500
section. You have a one task that is
not calling by this

00:11:02.500
00:11:05.300
notify section now, let me do one thing.

00:11:05.300
00:11:05.700
I will.

00:11:08.400
00:11:15.000
remove first rebar httpd then just wait.

00:11:15.000
00:11:18.600
I'm going to remove my httpd apps and
right.

00:11:21.800
00:11:26.600
Now once if you remove we don't have
our history, but on
00:11:26.600
00:11:30.200
your host right after completion of this
Playbook it is going

00:11:30.200
00:11:32.000
to remove your httpd on your host.

00:11:32.000
00:11:32.400
Right?

00:11:33.100
00:11:33.800
Just wait.

00:11:37.300
00:11:40.400
Yeah now just check the status of your
httpd.

00:11:40.400
00:11:43.800
Anyway, it is not there right assume
that we are going to

00:11:43.800
00:11:46.700
run our Playbook at very first time or
you are going to install

00:11:46.700
00:11:48.500
your httpd through your playbook.

00:11:49.600
00:11:53.100
If you are going to install then definitely
the result the

00:11:53.100
00:11:57.400
changed status of this task is true,
right if it is true

00:11:57.400
00:12:02.500
then only this task will execute this
notify section or this

00:12:02.500
00:12:07.300
notify will allow to execute this Handler
Handler task.

00:12:08.700
00:12:13.900
The status of change the status of this
task he changed through

00:12:14.200
00:12:17.900
then only notify will allow to call this
Handler section

00:12:17.900
00:12:21.700
this Handler task that is nothing but
this one now see the
00:12:21.700
00:12:24.200
result. I am going to run at very first
time just assume

00:12:24.200
00:12:27.000
that because we removed our httpd
we are going to install

00:12:27.000
00:12:30.600
your httpd installing means R is
changing it is changing

00:12:30.600
00:12:32.100
then we'll call notify section.

00:12:32.300
00:12:35.100
That's it or not if the task which is
there an or even notify

00:12:36.600
00:12:40.900
See tasks which are there under
handlers intersection all

00:12:40.900
00:12:41.400
are same.

00:12:42.300
00:12:43.500
Okay for sub build output.

00:12:49.400
00:12:56.100
installing httpd just wait and see the
result.

00:13:02.100
00:13:03.500
Change through change.

00:13:03.500
00:13:06.500
That's why running Handler start httpd.

00:13:07.000
00:13:07.400
That's it.

00:13:08.800
00:13:11.400
Did he change that's why he's calling
but previously right

00:13:11.400
00:13:15.100
see that not changing that side is not
calling any hand or

00:13:15.100
00:13:18.400
section. But now it is calling handle
section because the

00:13:18.400
00:13:22.100
task which is there in your tasks
section has been changed
00:13:22.400
00:13:23.200
now see the status.

00:13:23.300
00:13:24.400
It is running up and running.

00:13:24.400
00:13:24.900
That's it.

00:13:25.900
00:13:29.800
So guys, simply the code how we are
writing under your Tas

00:13:29.800
00:13:33.600
section and I will handle section that is
same the only thing

00:13:34.400
00:13:37.700
whatever the task you are having
under your Handler section.

00:13:38.100
00:13:42.400
That would execute if you mention that
under notify.

00:13:42.900
00:13:47.200
But before executing your notify will
check whether the current

00:13:47.200
00:13:49.600
task is changing something on your
host or not.

00:13:49.800
00:13:53.200
If it if it is changing then only this notify
allowed to

00:13:53.200
00:13:54.400
execute this task.

00:13:54.400
00:13:54.900
That's it.

00:13:56.200
00:13:57.100
Right, very simple.

00:13:57.900
00:13:58.300
Okay guys.

00:13:58.300
00:13:59.600
Thank you for watching this video.
Transcript
00:00:00.000
00:00:01.900
Friends here.

00:00:01.900
00:00:04.410
Our concept is ansible loops.

00:00:04.400
00:00:07.300
So before going to discuss about
ansible loops. First, let

00:00:07.300
00:00:09.110
me write a simple playbook.

00:00:09.100
00:00:12.400
So my requirement is: write a
playbook to install multiple

00:00:12.400
00:00:15.500
packages. Let me take a simple task.
Suppose

00:00:15.500
00:00:17.710
I want to install git on my host.

00:00:17.700
00:00:22.610
So suppose if you search for "git
install on hrel"
00:00:22.600
00:00:26.410
There are some prerequisites to install
your git on your

00:00:26.400
00:00:27.910
or hrel servers.

00:00:27.900
00:00:31.100
So what are those steps you need to
install some required

00:00:31.100
00:00:34.200
packages before going to install your
git. You have to install

00:00:34.200
00:00:35.900
these packages.

00:00:35.900
00:00:39.200
Let me take at least this one, because
our concept is loops.

00:00:39.200
00:00:41.510
[no audio]

00:00:41.500
00:00:41.800
Right?

00:00:41.800
00:00:43.910
Now we need to install all these
packages.

00:00:43.900
00:00:47.700
So if you want to install all these
packages how we can write

00:00:47.700
00:00:49.110
a playbook for this.

00:00:49.100
00:00:51.400
So, you know, if you want to install any
package on your

00:00:51.400
00:00:54.600
host suppose, let us assume that you
are manage node is

00:00:54.600
00:00:58.500
supposed sent waves or rhel Amazon
Linux, then you have to

00:00:58.500
00:01:02.210
take your module to install all these
packages, right?

00:01:02.200
00:01:04.709
Let me open my ansible controller.
00:01:04.700
00:01:06.910
So let me open a simple playbook.

00:01:06.900
00:01:11.310
So I have taken a playbook name as
"install_multiple_pkgs.yml"

00:01:11.300
00:01:15.310
So you have to take target first.

00:01:15.300
00:01:18.010
So target, I am taking as of now
localhost.

00:01:18.000
00:01:21.600
Anyway, while working with real-time
scripts will take different

00:01:21.600
00:01:23.610
groups and different hosts.

00:01:23.600
00:01:24.710
That's fine.

00:01:24.700
00:01:25.000
Now.

00:01:25.000
00:01:27.000
I want to collect "gather_facts" then.

00:01:27.000
00:01:32.210
Let me take "false" or disable it. Then I
need to run your

00:01:32.200
00:01:34.700
tasks with root privileges because
you're going to use your

00:01:34.700
00:01:36.310
module, right?

00:01:36.300
00:01:38.600
Of course, you can also provide
"become: yes" in a task level

00:01:38.600
00:01:39.000
as well.

00:01:39.000
00:01:41.210
I will show you that. Then let me write
a "tasks"

00:01:41.200
00:01:44.300
section. So I need to write it. How
many tasks sections I need

00:01:44.300
00:01:45.610
to write?
00:01:45.600
00:01:50.210
I mean, how many tasks I have to
write? See that? First package,

00:01:50.200
00:01:56.600
second package, then third, fourth,
then fifth. Five packages

00:01:56.600
00:02:00.500
you are having, right? Just simply take
all these packages

00:02:00.500
00:02:04.000
names. Now, you have to write a
playbook which consists

00:02:04.000
00:02:07.410
of under tasks section, 5 tasks.

00:02:07.400
00:02:09.100
So first task is for suppose.

00:02:09.100
00:02:14.310
I am writing simply "yum" and "name".
What is the name?

00:02:14.300
00:02:15.709
This is the first package name.

00:02:15.700
00:02:18.609
I need to install this package first.

00:02:18.600
00:02:22.900
Then "state" I have to provide that as
simply "present". Then.

00:02:22.900
00:02:25.010
[no audio]

00:02:25.000
00:02:28.700
So guys if you are getting confusion
see I need to run I

00:02:28.700
00:02:30.510
need to write a task,

00:02:30.500
00:02:34.100
I mean, yum module 5 times because
I need to install then

00:02:34.100
00:02:38.709
just simply take in sequence

00:02:38.700
00:02:41.609
Third, fourth, then five.

00:02:41.600
00:02:45.100
So the I mean if you write in this way,
you don't get any
00:02:45.100
00:02:46.100
indentation errors.

00:02:46.100
00:02:53.510
Let's say "name", then provide simply
"state=present".

00:02:53.500
00:02:54.410
Right?

00:02:54.400
00:02:56.500
So simply take the copy of this.

00:02:56.500
00:03:00.310
[no audio]

00:03:00.300
00:03:03.400
We'll modify the name later. So
second task,

00:03:04.400
00:03:13.900
third task, fourth, fifth. So first package
we have given. Then

00:03:13.900
00:03:14.800
second package

00:03:14.800
00:03:16.709
is this one?

00:03:16.700
00:03:21.410
Let me provide here name for the
second package.

00:03:21.400
00:03:25.900
Just observe that. So this is the basic
way to install your

00:03:25.900
00:03:31.510
multiple packages with your yum
module.

00:03:31.500
00:03:36.500
We're done with the three then we
have fourth. Let me write here

00:03:36.500
00:03:37.800
Fourth package name.

00:03:37.800
00:03:39.810
[no audio]

00:03:39.800
00:03:42.410
Then fifth package name.

00:03:42.400
00:03:46.510
Yes, just now we done a simple
playbook to install five packages.
00:03:46.500
00:03:47.200
Right? First,

00:03:47.200
00:03:48.910
let me run this playbook.

00:03:48.900
00:03:53.500
So playbook is simply "ansible
playbook install_multiple_pkgs.yml"

00:03:53.500
00:03:56.510
Let me run this and see the result.

00:03:56.500
00:04:00.310
So it is going to install your first
package.

00:04:00.300
00:04:02.109
So first task is executing.

00:04:02.100
00:04:04.900
If you want to get some information
while running your task,

00:04:04.900
00:04:07.600
you can also write here for each and
every task you can write

00:04:07.600
00:04:11.709
some name, you know that? How to
write a name, right?

00:04:11.700
00:04:15.609
Just wait, so it is going to install first
package.

00:04:15.600
00:04:19.200
So once it is done, then I will tell you
how to simplify

00:04:19.200
00:04:21.310
that task

00:04:21.300
00:04:26.100
with the help of loops concept. So it is
going to install

00:04:26.100
00:04:28.010
second package.

00:04:28.000
00:04:28.900
So it may take some time.

00:04:28.900
00:04:29.600
Just wait.

00:04:29.600
00:04:32.810
[no audio]
00:04:32.800
00:04:35.010
Second task has been done.

00:04:35.000
00:04:37.900
That means this package has been
installed. Then it is installing

00:04:37.900
00:04:38.900
third package.

00:04:38.900
00:04:51.310
[no audio]

00:04:51.300
00:04:53.510
Third then it is going to install forth.

00:04:53.500
00:04:57.210
It is already there and my host then
fifth then done.

00:04:57.200
00:05:00.110
So total five task among that three
changes.

00:05:00.100
00:05:03.710
So maybe last two packages were
already there with my host.

00:05:03.700
00:05:05.110
That's fine.

00:05:05.100
00:05:09.200
Now guys just observe this all five
tasks. In this all five

00:05:09.200
00:05:13.409
tasks except to package name, except
a package name.

00:05:13.400
00:05:16.510
Every remaining syntax is same no?

00:05:16.500
00:05:20.000
That means you are repeating same
task for five times for

00:05:20.000
00:05:21.810
different packages.

00:05:21.800
00:05:24.300
So in that case, you know need to
write this much.

00:05:24.300
00:05:27.100
I mean five tasks, you know, you know
need to write five
00:05:27.100
00:05:30.400
tasks. You can write only one task and
you can repeat that

00:05:30.400
00:05:34.409
for five times each time a different
package name, right?

00:05:34.400
00:05:35.909
See that how I am going to do that.

00:05:35.900
00:05:37.500
So first I am not taking yum package.

00:05:37.500
00:05:37.800
Simply.

00:05:37.800
00:05:40.310
I'm taking some debug.

00:05:40.300
00:05:41.300
For our understanding.

00:05:41.300
00:05:42.400
I am writing a message.

00:05:42.400
00:05:47.610
[no audio]

00:05:47.600
00:05:54.500
Now the package name is simply don't
worry about this.

00:05:54.500
00:05:54.900
Whatever.

00:05:54.900
00:05:55.400
I'm writing.

00:05:55.400
00:05:56.300
Just observe that.

00:05:56.300
00:05:58.510
[no audio]

00:05:58.500
00:06:02.200
I will do one thing is I will keep this
playbook as this

00:06:02.200
00:06:05.810
so that I will share both the playbooks.

00:06:05.800
00:06:08.000
Just give me a second.

00:06:08.000
00:06:14.110
[no audio]

00:06:14.100
00:06:15.600
Let me write one more playbook.
00:06:15.600
00:06:20.710
[no audio]

00:06:20.700
00:06:34.409
That mean you the name as
"install_multiple_pkgs_with_loops.yml"

00:06:34.400
00:06:37.700
So for that first of all, I am copying
these things.

00:06:37.700
00:06:40.610
[no audio]

00:06:40.600
00:06:43.200
Now see that what I am doing is first I
am writing a for

00:06:43.200
00:06:46.400
our understanding purpose debug
then in the time writing

00:06:46.400
00:06:48.200
is simply message parameter.

00:06:48.200
00:06:50.710
[no audio]

00:06:50.700
00:06:56.010
"The current pkgs is: }"

00:06:56.000
00:06:56.800
Don't worry about that.

00:06:56.800
00:07:00.909
I will explain you that. Then I am
taking simply here loop

00:07:00.900
00:07:02.100
then in that.

00:07:02.100
00:07:05.700
I am giving list of values you can take
either square brackets

00:07:05.700
00:07:09.010
or let me show you all the ways.

00:07:09.000
00:07:09.800
It's better first.

00:07:09.800
00:07:11.409
Let me take in this way.

00:07:11.400
00:07:13.500
So what is the first package name this
one, right?

00:07:13.500
00:07:20.110
[no audio]
00:07:20.100
00:07:21.000
Then second one.

00:07:21.000
00:07:30.909
[no audio]

00:07:30.900
00:07:32.000
Let me take third one.

00:07:32.000
00:07:36.710
[no audio]

00:07:36.700
00:07:38.300
Let me take fourth one.

00:07:38.300
00:07:44.810
[no audio]

00:07:44.800
00:07:46.600
Then last one fifth one.

00:07:46.600
00:07:48.909
[no audio]

00:07:48.900
00:07:51.909
Just observe how this playbook is
going to work.

00:07:51.900
00:07:53.909
That is important.

00:07:53.900
00:07:58.700
So guys my task is: this is the task but
in that I have taken

00:07:58.700
00:08:02.300
some variable called item that is the
default variable for

00:08:02.300
00:08:06.400
this loop. So what is the purpose of
this task suppose if

00:08:06.400
00:08:10.400
you are going to display something but
this task you

00:08:10.400
00:08:13.700
are repeating for this number of
packages so whenever it

00:08:13.700
00:08:16.500
is going to exclude first time it will take
automatically

00:08:16.500
00:08:20.100
item name as this one, then second
time this one, third time
00:08:20.100
00:08:23.710
this one, fourth time this one, fifth time
this one. So that this

00:08:23.700
00:08:27.510
per task is going to repeat for five
times.

00:08:27.500
00:08:30.000
So whenever if it is going to repeat,
each time, it is going

00:08:30.000
00:08:34.500
to pick packages one by one. First
time, the second time, this

00:08:34.500
00:08:39.610
side. Let me run this and see the
result so "ansible playbook

00:08:39.600
00:08:45.110
install_multiple_pkgs_withloops.yml"
See? The output.

00:08:45.100
00:08:45.700
What happened?

00:08:45.700
00:08:54.210
[no audio]

00:08:54.200
00:08:59.210
Yeah, I'm missing with quotations.

00:08:59.200
00:09:02.210
Now, let me run this on see the result.

00:09:02.200
00:09:07.110
See that? Your debug task is repeating
for five times.

00:09:07.100
00:09:09.900
So whenever it is executing first time
automatically, it

00:09:09.900
00:09:13.400
is fetching the, I mean, taking first
package name, second time

00:09:13.400
00:09:16.510
second package, third time third
package for time.

00:09:16.500
00:09:20.700
So now if you observe this it task
same task you are repeating.
00:09:20.700
00:09:23.110
The only thing is package name is
different, right?

00:09:23.100
00:09:27.900
That's why what I can do is see very
simple now instead of

00:09:27.900
00:09:31.010
this debug now you can take simply
yum package.

00:09:31.000
00:09:35.810
So instead of name. So automatically
whenever if we take loop

00:09:35.800
00:09:38.600
in here, we are having some list of
values, right? So

00:09:38.600
00:09:43.300
that item will be taken in terms of a
variable called item.

00:09:43.300
00:09:45.210
That's it.

00:09:45.200
00:09:48.700
Now if I run this anyway, already
installed that but through

00:09:48.700
00:09:54.010
playbook we are repeating a task with
the concept of loop.

00:09:54.000
00:09:55.410
That's it.

00:09:55.400
00:09:58.100
See there? First task is checking.

00:09:58.100
00:09:59.300
Anyway, that is there.

00:09:59.300
00:10:00.800
That's why it is simply saying.

00:10:00.800
00:10:01.100
Okay.

00:10:01.100
00:10:01.910
Okay means you are

00:10:01.900
00:10:02.800
not installing already

00:10:02.800
00:10:07.110
it was there. That's it. Now suppose if I
want to uninstall
00:10:07.100
00:10:09.700
then simply write absent.

00:10:09.700
00:10:12.210
[no audio]

00:10:12.200
00:10:13.800
Just run this and see the result.

00:10:13.800
00:10:17.500
It is going to change one by one. First
is going to uninstall

00:10:17.500
00:10:20.000
the first package. Just observe that.

00:10:20.000
00:10:23.410
[no audio]

00:10:23.400
00:10:24.210
That's it.

00:10:24.200
00:10:24.700
Likewise.

00:10:24.700
00:10:27.600
It will take one by one and same task
is repeating for this

00:10:27.600
00:10:31.710
many number of this main number of
packages.

00:10:31.700
00:10:32.200
Right.

00:10:32.200
00:10:34.800
So whenever it is going to execute first
time automatically

00:10:34.800
00:10:38.610
it will pick this as the first package
name.

00:10:38.600
00:10:42.000
I mean in place of item and again, it is
going to execute

00:10:42.000
00:10:44.000
second time. While executing second
time

00:10:44.000
00:10:47.110
this item will be automatically changed
to second value.

00:10:47.100
00:10:49.110
That's it.
00:10:49.100
00:10:49.400
Right.

00:10:49.400
00:10:52.700
So it is somewhat simple right?
Compared to your previous

00:10:52.700
00:10:54.300
playbook. Unnecessarily

00:10:54.300
00:10:58.900
we're writing our same task 5 times.
Now you are not writing

00:10:58.900
00:11:01.300
same task 5 times, you're writing only
one time. But you are

00:11:01.300
00:11:04.700
saying "repeat" this with final five times
each time different

00:11:04.700
00:11:05.400
package name.

00:11:05.400
00:11:06.510
That's it.

00:11:06.500
00:11:10.900
Not only for this see suppose if I want
to install on any

00:11:10.900
00:11:12.100
number of servers, right?

00:11:12.100
00:11:16.010
Let me write one more playbook.
Suppose

00:11:16.000
00:11:19.510
let's say I want to install some different
packages on my

00:11:19.500
00:11:24.110
targets. Let's say as of now target is
localhost.

00:11:24.100
00:11:26.810
Let me save it.

00:11:26.800
00:11:32.610
Some "demo_install" something.

00:11:32.600
00:11:38.500
Okay "gather_facts: false". Then.

00:11:38.500
00:11:41.810
Let me write "become: yes"
00:11:41.800
00:11:44.900
So with route priveledge, I want to run
each and every task.

00:11:44.900
00:11:48.210
But anyway, we are going to write our
task in terms of loops,

00:11:48.200
00:11:53.410
so I'm writing a simply name for your
task installing multiple

00:11:53.400
00:11:58.300
packages. Let's say I want to install
suppose like git then

00:11:58.300
00:12:03.300
tomcat, then httpd, nginx. Any
packages you can install

00:12:03.300
00:12:05.110
with the single task.

00:12:05.100
00:12:09.500
So as of now, our manage server or
target is simply send

00:12:09.500
00:12:12.210
ways so I can install package with
yum.

00:12:12.200
00:12:15.710
So let me take name as first take item.

00:12:15.700
00:12:16.700
So what is this item?

00:12:16.700
00:12:19.410
We need to mention right?

00:12:19.400
00:12:23.510
So "state=present".

00:12:23.500
00:12:28.500
Then I am taking loop we clear your
loop and yum, both should

00:12:28.500
00:12:32.700
have same indentation. Then under
that you can mention suppose

00:12:32.700
00:12:38.810
first one is git then second one is
tomcat ,third one is

00:12:38.800
00:12:43.510
httpd, then fourth one in gnix.
Something like that.
00:12:43.500
00:12:46.010
That's it.

00:12:46.000
00:12:49.210
Right now, suppose if I run this

00:12:49.200
00:12:52.100
ansible, so previous task has been
completed guys. See

00:12:52.100
00:12:56.300
that? All packages has been removed
because we have taken

00:12:56.300
00:12:57.600
absent state.

00:12:57.600
00:12:59.610
[no audio]

00:12:59.600
00:13:02.500
If we make it as a present, then it is
going to install these

00:13:02.500
00:13:04.410
packages. Now.

00:13:04.400
00:13:08.610
We are taking one more example to
install multiple packages.

00:13:08.600
00:13:15.210
Right, so let me write install this
"demo_install".

00:13:15.200
00:13:18.400
So it is going to install multiple
packages.

00:13:18.400
00:13:20.110
That's it.

00:13:20.100
00:13:23.100
Installing your multiple packages like
git, tomcat, httpd,

00:13:23.100
00:13:23.810
nginx.

00:13:23.800
00:13:24.900
So git is already there.

00:13:24.900
00:13:30.510
[no audio]

00:13:30.500
00:13:32.700
So like this is the guys this simple
concept.
00:13:32.700
00:13:38.000
So now ansible loops are nothing but
and small loops or helpful

00:13:38.000
00:13:42.510
to repeat certain tasks for given
number of times or maybe

00:13:42.500
00:13:45.610
sometimes based on condition as well.

00:13:45.600
00:13:46.000
Right?

00:13:46.000
00:13:48.700
So while going forward, we'll go with
step-by-step and we'll

00:13:48.700
00:13:50.200
complete different types of loops.

00:13:50.200
00:13:51.400
This is the basic loops.

00:13:51.400
00:13:54.110
You have to know first this loop.

00:13:54.100
00:13:54.710
Right.

00:13:54.700
00:13:59.900
So after this I will update the
remaining loops concept based

00:13:59.900
00:14:03.500
on scenario based on situation. Right?
For time being,

00:14:03.500
00:14:06.810
I'm giving only simple loops concept.

00:14:06.800
00:14:07.510
That's it.

00:14:07.500
00:14:10.310
So it is installing httpd, right?

00:14:10.300
00:14:11.000
That's it guys.

00:14:11.000
00:14:13.910
This is a simple way to understand
about your loops.

00:14:13.900
00:14:18.610
The only thing is loops are useful to
repeat a certain tasks.
00:14:18.600
00:14:22.200
While repeating your task, right,
automatically,

00:14:22.200
00:14:26.510
you can pick your values, your
packages or your, whatever the

00:14:26.500
00:14:30.710
list of values you have given under
loops, one by one.

00:14:30.700
00:14:32.800
Not only this I am giving one more
example suppose.

00:14:32.800
00:14:37.910
I need to create number of users:

00:14:37.900
00:14:42.700
tomcat user, weblogic user,
websphere user, apache user. Some

00:14:42.700
00:14:43.400
number of users.

00:14:43.400
00:14:50.300
I need to create on my given nodes on
my targets right? Under

00:14:50.300
00:14:52.900
the time also, you can take simply
loop and you can take

00:14:52.900
00:14:55.910
user module and you can create it
right.

00:14:55.900
00:15:00.000
Anyway, we'll see a number of
examples whilst working with

00:15:00.000
00:15:01.410
real-time scripts.

00:15:01.400
00:15:04.999
Okay guys, thank you for watching this
simple video.
Transcript
00:00:00.000
00:00:02.000
Friends, here

00:00:02.000
00:00:04.000
our concept is ansible tags.

00:00:04.400
00:00:08.600
See this ansible tags or useful to
execute or skip required

00:00:08.600
00:00:13.300
tasks from number of tasks or from
your playbook suggestion

00:00:13.300
00:00:16.000
that you are having a Playbook which
consists of some 20

00:00:16.000
00:00:19.400
tasks and whenever if you run your
playbook, you know that

00:00:19.400
00:00:22.800
by default it is going to exclude all
tasks, but I want to

00:00:22.800
00:00:25.300
skip or I want to exclude certain tasks.
00:00:26.000
00:00:27.800
Then how we can do that.

00:00:28.100
00:00:32.900
So in that requirement tags will help
us how it is going

00:00:32.900
00:00:33.500
to help you.

00:00:33.600
00:00:35.300
Let me show you with an example.

00:00:35.800
00:00:37.600
Let me open my aunt's will controller.

00:00:38.100
00:00:40.100
So I'm going to open a simple
Playbook.

00:00:40.500
00:00:42.200
I mean, I am going to write a simple
Blue Book.

00:00:42.200
00:00:44.800
I have given a name for working with
tax dot yml.

00:00:45.500
00:00:46.900
Let me write a simple Playbook.

00:00:47.200
00:00:50.400
So I am writing it Playbook name as
are simply plane MS.

00:00:52.000
00:00:55.700
play with Suppose fight tasks.

00:00:55.900
00:00:58.000
You can write any number of tasks
and you can test it.

00:00:58.700
00:01:05.500
So as of now I am taking host as
simply localhost then let

00:01:05.500
00:01:10.100
me disable gather facts false then let
me write tasks section.

00:01:10.600
00:01:13.800
So as of now, I am writing simply at all
tasked with the

00:01:13.800
00:01:15.000
help of debug module.

00:01:15.500
00:01:18.700
Let's say this is first task.
00:01:20.800
00:01:22.600
And this type of tasks.

00:01:22.600
00:01:24.700
I want to write suppose at least five.

00:01:31.500
00:01:41.200
first task second third fourth write Phi.

00:01:41.400
00:01:45.300
Let me give the name for that first
second.

00:01:49.800
00:02:06.400
third fourth Fifth just save it right now
see that.

00:02:07.400
00:02:09.600
First let me run this play book, you
know that whenever if

00:02:09.600
00:02:12.699
you run this Playbook it is going to
execute fight tasks.

00:02:12.699
00:02:16.000
Simply each and every task is simply
displaying some information

00:02:16.000
00:02:17.000
some message right?

00:02:17.400
00:02:18.500
Anyway, let me run that.

00:02:20.700
00:02:23.800
Working with tax dot yml just see the
output.

00:02:24.600
00:02:28.500
So by default your playbook is going
to execute all tasks

00:02:28.500
00:02:30.000
which are there in your playbook.

00:02:31.400
00:02:35.300
Now my requirement is suppose if I
have five tasks.

00:02:35.300
00:02:39.900
I want to exclude or let's say suppose
only first task sometimes

00:02:40.000
00:02:42.700
and whenever if I run some other
times, I want to exclude
00:02:42.700
00:02:47.300
suppose some third task then how you
can control your required

00:02:47.300
00:02:51.900
task to execute or to skip so for that
tags are helpful tags

00:02:51.900
00:02:55.700
means just you have to write for each
and every task one

00:02:55.700
00:02:57.700
key as like tags.

00:02:57.700
00:02:59.700
Let's say you can provide any name
for your tag.

00:03:00.000
00:03:01.600
So I I'm going to give suppose one.

00:03:03.400
00:03:05.200
Alex let me do first.

00:03:07.000
00:03:11.800
So likewise, you can give for each and
every task some tags.

00:03:12.900
00:03:18.200
second so I am going to provide for
each and every tasks.

00:03:20.000
00:03:21.700
Tags, let's say third.

00:03:24.600
00:03:27.100
Then tags, let's say forth.

00:03:32.000
00:03:35.000
Then for last one, let's say taxes.

00:03:36.300
00:03:37.900
V that's it.

00:03:39.000
00:03:42.200
So let me run once again your
playbook just now.

00:03:42.200
00:03:45.700
I have given a I mean I have given
tags for each and every

00:03:45.700
00:03:50.700
task and I'm running is there any
change know so even though
00:03:50.700
00:03:53.700
if you mentioned tags in your playbook
and if you are not

00:03:53.700
00:03:57.000
using on your command line, then
there is no use now.

00:03:57.000
00:04:01.100
Let me run my playbook with my
required task.

00:04:01.200
00:04:03.900
So if you want to run your playbook
with your required tasks,

00:04:03.900
00:04:05.400
then you have to pass.

00:04:05.500
00:04:08.900
Pass tags value on your command
line while running your playbook

00:04:09.800
00:04:14.100
so that you can provide with - - tax or
simply - t let me

00:04:14.100
00:04:15.900
provide first with - - tax.

00:04:15.900
00:04:20.399
I want to execute only first task then
for first ask.

00:04:20.399
00:04:21.000
What is the tag?

00:04:21.000
00:04:26.600
You have given first just provide that
here so that now you

00:04:26.600
00:04:29.600
are answerable Playbook is going to
run from your ml file

00:04:29.600
00:04:33.200
only the task, which is having tag as
first see the output

00:04:35.000
00:04:36.600
Not is not running remind tags.

00:04:36.700
00:04:38.400
It is not running the main tasks.

00:04:39.200
00:04:41.400
I want to run first and fourth.
00:04:42.700
00:04:45.300
Then comma first Comer fourth see
the output.

00:04:47.900
00:04:53.900
now you can also provide with the
shortcut as - t both are

00:04:53.900
00:04:56.700
same - Tiara - - tags.

00:04:58.200
00:05:02.500
Now I want to skip these two tasks or
anyone of that and

00:05:02.500
00:05:03.900
I want to run remaining tasks.

00:05:03.900
00:05:11.000
Then you can pass - - skip tags first
and fourth first comma

00:05:11.000
00:05:15.100
for so that it is going to skip your first
and fourth task

00:05:15.100
00:05:17.000
and it is going to run remaining tasks.

00:05:17.000
00:05:18.900
It is going to execute your remaining
tasks.

00:05:20.200
00:05:20.600
That's it.

00:05:22.200
00:05:23.000
And one more thing.

00:05:24.300
00:05:28.200
We have a tags and without tags if
you run your Playbook

00:05:28.200
00:05:32.100
by default it is going to execute Oliver
tasks.

00:05:33.400
00:05:34.000
That's fine.

00:05:34.100
00:05:38.800
Now see suppose with one tag.

00:05:38.800
00:05:42.900
I want to run your first and suppose
some third or fourth

00:05:42.900
00:05:43.900
any two tasks.
00:05:43.900
00:05:47.700
I want to run with one tag in that case
just to provide same

00:05:47.700
00:05:51.800
name for your two tasks suppose.

00:05:51.800
00:05:54.700
I want to provide first year and then
4/3 also first.

00:05:57.400
00:05:58.900
Let me write first.

00:06:00.700
00:06:04.100
Now I'm running our Playbook with
simply first.

00:06:05.200
00:06:05.900
Let me run.

00:06:07.600
00:06:10.500
And see the output it is going to
execute your first and

00:06:10.500
00:06:11.400
third task.

00:06:13.200
00:06:14.800
But I want to control now.

00:06:14.900
00:06:17.600
I want exit only first task without
changing your tags.

00:06:17.600
00:06:18.600
Then it is not possible.

00:06:19.300
00:06:23.400
I want to run only first task without
changing your tag because

00:06:23.600
00:06:27.000
if I go with - t first it is going to exclude
first and third

00:06:27.200
00:06:31.800
but I want to exclude only one only
first then so in that

00:06:31.800
00:06:35.300
case what you have to do is just
provide for each and every

00:06:35.700
00:06:38.000
task separate tags first thing.
00:06:39.800
00:06:44.800
and whenever if you want to execute
multiple tasks with the

00:06:44.800
00:06:49.500
same tag name, then see that you can
also provide multiple

00:06:49.500
00:06:56.000
tags for each and every task see that
now first of all, if

00:06:56.000
00:06:58.500
you run in this way, it is going to
execute now your only

00:06:58.500
00:07:04.400
first task Suppose I want to exclude
first task on third

00:07:04.400
00:07:08.800
task with the help of one tag, then add
same tag here and

00:07:08.800
00:07:13.200
here let's say common tasks common
then here and here.

00:07:15.400
00:07:16.000
That's it.

00:07:17.600
00:07:20.300
Now if I run with the first it is going to
execute only first

00:07:20.300
00:07:25.500
task we clear and if I run with common
now common tag is

00:07:25.500
00:07:28.200
therefore first and third that's what is
going to exclude

00:07:28.200
00:07:29.700
first and third tasks.

00:07:30.100
00:07:30.600
That's it.

00:07:33.300
00:07:35.500
And one more thing be clear.

00:07:36.200
00:07:39.600
Yeah, see whatever the tags are
available in your playbook.
00:07:39.700
00:07:45.900
You can list them see that first thing
and simple - Playbook.

00:07:46.200
00:07:47.300
We have a help.

00:07:49.000
00:07:49.700
See the output.

00:07:51.300
00:07:52.000
See somewhere.

00:07:52.000
00:07:56.900
We have tags - tea or iPhone - tax just
to run your required

00:07:57.800
00:08:02.300
tasks based on your tags or - iPhones
keep tags.

00:08:03.400
00:08:06.900
And one more thing is there - iPhone
list tags see.

00:08:09.400
00:08:15.300
Simply your playbook - iPhone list
tags.

00:08:15.500
00:08:17.800
It is going to list for each and every
task.

00:08:17.800
00:08:19.100
What are the available tags?

00:08:22.000
00:08:27.300
See that we have common one tag
fifth first fourth second

00:08:27.300
00:08:30.900
and third so these are the tags which
we provided inside

00:08:30.900
00:08:33.900
of our playbook for your all tasks.

00:08:35.400
00:08:36.700
Right, that's fine.

00:08:37.200
00:08:37.799
Be clear.

00:08:39.000
00:08:43.700
Now one more thing if I run our
Playbook without any I mean
00:08:43.700
00:08:47.400
without passing any tags, you know
that it is going to execute

00:08:47.400
00:08:48.600
all your tasks.

00:08:49.799
00:08:51.700
But I don't want to exclude even in this
way.

00:08:52.600
00:08:54.500
If I pass tag, then all I want eggs.

00:08:54.600
00:08:57.500
I have to exclude that required task.

00:08:57.600
00:08:59.000
Otherwise, I don't want to execute.

00:09:00.100
00:09:00.800
By default.

00:09:00.800
00:09:05.200
I don't want to run any of your task
then in that case for

00:09:05.200
00:09:08.600
each and every task you can add one
extra tag called Never.

00:09:09.900
00:09:10.900
Never see that.

00:09:13.300
00:09:18.200
Now you can provide for each and
every task you're required

00:09:18.200
00:09:19.800
tag along with never.

00:09:21.400
00:09:23.500
Never very very helpful one.

00:09:23.700
00:09:28.400
Never be clear with never.

00:09:31.100
00:09:35.400
So you can pass your tags with list of
tags.

00:09:44.900
00:09:49.300
So guys just now I provided a tag
called Never for each and

00:09:49.300
00:09:50.200
every task.
00:09:50.800
00:09:54.900
That's why if I run my playbook it won't
execute any task.

00:09:56.500
00:10:01.400
See that it is not executing any task
because I said that

00:10:01.400
00:10:04.000
don't execute any one of the tasks by
default.

00:10:04.000
00:10:07.800
There is the meaning for never tagged
very very helpful one.

00:10:09.000
00:10:12.400
So if you provide never for any one of
the tag or alt tags,

00:10:12.400
00:10:17.500
then that particular tasks or not going
to execute but even

00:10:17.500
00:10:20.200
though if you mention never and if you
want to exclude your

00:10:20.200
00:10:24.500
required tasks based on tag, then you
can mention - tea or

00:10:24.500
00:10:27.900
your I mean hyphen t space you are
required tag name, see

00:10:27.900
00:10:31.200
that. It is executing now.

00:10:32.300
00:10:35.700
So whenever if you add never tagged,
what is the advantage

00:10:35.700
00:10:40.800
with that if you run your Playbook by
default no one, I mean

00:10:40.800
00:10:42.800
any one of your tasks won't execute.

00:10:44.000
00:10:47.300
The tags, I mean the tasks which are
having tag value as

00:10:47.300
00:10:51.100
never those won't exclude, but let me
remove for one of the
00:10:51.100
00:10:59.400
tasks. I removed never for fourth task
and I'm running my

00:10:59.400
00:11:02.000
playbook without any tax then see the
result.

00:11:03.500
00:11:06.800
It is going to exclude for the task
because for fourth task

00:11:06.800
00:11:10.400
we did not provide a tag value as
never right?

00:11:10.400
00:11:13.100
So if you don't provide Never by
default, it will run if

00:11:13.100
00:11:16.000
you provide Never by default, it won't
execute until you

00:11:16.000
00:11:19.400
call a required tag for your required
task.

00:11:21.600
00:11:23.800
Right fine now.

00:11:25.900
00:11:32.500
Now suppose I want to run let's a
second task.

00:11:34.900
00:11:35.600
It's running.

00:11:37.200
00:11:41.100
And remaining tasks are going to skip
because we are not

00:11:41.100
00:11:46.600
calling. Anyway, we provided never
also never tagged as but

00:11:46.800
00:11:50.500
even though if I call second task or
third task or fourth

00:11:50.500
00:11:54.400
task, but I want X good by default one
task.

00:11:54.800
00:11:57.200
It may be any task in that case.
00:11:57.200
00:12:01.000
What you have to do is you have to
write always let me write

00:12:01.000
00:12:04.400
for last task or it may be anything our
first task instead

00:12:04.400
00:12:10.500
of never but don't write never and
always So now how didn't

00:12:10.500
00:12:18.000
always? First thing if I run a task with
required tag, it

00:12:18.000
00:12:20.400
has to exclude second task along with
that.

00:12:20.500
00:12:23.900
It is also going to exclude first task
because for first

00:12:23.900
00:12:27.300
task I had given always means
whether you are going to pass

00:12:27.300
00:12:30.300
tags or Not by default.

00:12:30.900
00:12:34.800
The first task will exclude because for
first task we have

00:12:34.900
00:12:37.000
one of the tag value as always.

00:12:37.400
00:12:41.500
So if you have a always for your tag
for your task, then

00:12:41.500
00:12:42.500
it is going to execute by.

00:12:43.200
00:12:47.700
See that let me run second task, but it
is excluding first

00:12:47.700
00:12:48.400
task as well.

00:12:48.500
00:12:52.500
Because for first task we have given
tag value as always.

00:12:53.100
00:12:53.600
That's it.
00:12:55.500
00:12:59.100
Now even though if you run without
tags see the result.

00:13:00.500
00:13:04.200
It is executing first task because we
have given always.

00:13:05.500
00:13:11.600
right, so guys be clear with always and
never never if you

00:13:11.600
00:13:16.000
mention never then by default that it
asked won't execute.

00:13:16.700
00:13:20.500
You have to call other tag for that
whenever if you want

00:13:20.500
00:13:24.300
to execute a task, right suppose if I
want to exclude from

00:13:24.300
00:13:27.200
command line this task then I need to
pass tag a second.

00:13:27.700
00:13:30.200
If I don't per second it will never
execute.

00:13:30.700
00:13:31.100
That's it.

00:13:31.100
00:13:34.600
That is the use of never always
whether you are going to

00:13:34.600
00:13:36.100
call this task or not.

00:13:36.900
00:13:40.200
By default will execute because we
have given always that's

00:13:40.200
00:13:45.600
it. So guys, this is the usage of your
tags, right and finally,

00:13:45.600
00:13:46.400
let me show you.

00:13:47.600
00:13:55.300
the list of tags I see that always
common and first then
00:13:55.300
00:14:01.500
what about you are never Always
common first then what about

00:14:01.500
00:14:06.200
this tax second never so whenever if
you write number of

00:14:06.200
00:14:10.800
tags along with never then those tags
won't display on your

00:14:10.800
00:14:13.600
command line whenever if you pass -
iPhone list attacks.

00:14:14.900
00:14:18.800
if I remove never for any one of the
tasks, then this key

00:14:18.800
00:14:23.000
this is tag key will display on your
command line if with

00:14:23.100
00:14:26.300
iPhone iPhone list tags either now, we
are getting forth

00:14:26.500
00:14:30.700
because just now 4/4 I removed never
but if I replace that

00:14:32.600
00:14:36.700
and if I rerun it is not going to display.

00:14:38.100
00:14:39.700
Right, that's it.

00:14:39.900
00:14:43.500
So if this is somewhat to prove I mean
hiding your tags.

00:14:45.100
00:14:46.300
Right for third person.

00:14:46.700
00:14:47.200
That's it.

00:14:48.100
00:14:52.100
And where these tags are helpful just
now we came to know

00:14:52.100
00:14:56.400
that we can control the execution of
your tasks based on
00:14:56.400
00:15:00.800
tags. And if you don't want the eggs
good by default any

00:15:01.000
00:15:04.600
any one of your tasks then for each
and every task we have

00:15:04.600
00:15:09.000
to provide one of the tag value as
never and if you want

00:15:09.000
00:15:13.500
to execute by default your some of the
tasks or any one of

00:15:13.500
00:15:17.900
the tasks then for that we have to
delete never and right

00:15:17.900
00:15:19.700
always in place of never.

00:15:21.300
00:15:21.900
That's fine.

00:15:23.100
00:15:28.600
but in real time where you are going to
use this Tags just

00:15:28.600
00:15:32.100
assume that you are having some
number of tasks in your playbook

00:15:32.600
00:15:37.100
and some tasks are for suppose Linux
box and some tasks or

00:15:37.100
00:15:41.200
for suppose open to and some tasks
or 4% weighs something

00:15:41.200
00:15:41.700
like that.

00:15:41.800
00:15:44.700
Then you will provide tags for each
and every task based

00:15:44.700
00:15:48.100
on your required syntax, which is there
in your tasks so

00:15:48.100
00:15:51.700
that you can call center is tasks
whenever if you are running
00:15:51.700
00:15:52.500
your playbook.

00:15:53.500
00:15:57.000
By selecting a Target section as sent
to a servers.

00:15:58.500
00:16:02.500
Or you will pass your tag as Ubuntu
whenever if you are if

00:16:02.500
00:16:05.500
you never if you are selecting your
target as Ubuntu servers

00:16:06.500
00:16:08.500
not only like that we are having so
many cases.

00:16:08.900
00:16:11.900
Okay, we'll come to know each and
every use case while going

00:16:11.900
00:16:13.500
forward. Okay?

00:16:13.900
00:16:17.800
Okay guys, thank you for watching this
simple video on your

00:16:17.800
00:16:18.500
tags.
Transcript
00:00:00.000
00:00:02.400
Friends, here

00:00:02.400
00:00:05.500
our concept is error handling in
Huntsville playbooks.

00:00:05.600
00:00:06.700
And this is the part 1.

00:00:07.200
00:00:12.600
Let me start that see ansible normally
has defaults that

00:00:12.600
00:00:17.000
make sure to check the it encodes of
command or modules and

00:00:17.000
00:00:21.500
it fails if if written code is nonzero, so
just assume that

00:00:21.800
00:00:25.700
you are running a simple task through
your playbook and in
00:00:25.700
00:00:29.700
the tasks you are running simply take
command suppose and

00:00:29.700
00:00:32.600
while running your command you may
get This output or error

00:00:32.600
00:00:36.200
output if we get success output then
written code is 0 if

00:00:36.200
00:00:38.700
you get an error output, then written
code is nonzero.

00:00:39.100
00:00:44.200
So whenever if we get it encode has
nonzero then by default

00:00:44.200
00:00:48.100
your answer will play book is going to
fail your task and

00:00:48.100
00:00:52.600
if the current task fails then Playbook
will stop the excluding

00:00:52.600
00:00:54.300
remaining tasks on the host.

00:00:56.600
00:00:56.900
Right.

00:00:56.900
00:00:58.500
See let me explain that.

00:01:00.000
00:01:02.800
Let me take Playbook name as error
handling dot yml.

00:01:03.000
00:01:05.000
Let me write suppose I am taking
here.

00:01:05.000
00:01:11.000
Also my target as simply Localhost
you can take any number

00:01:11.000
00:01:12.300
of servers then.

00:01:12.300
00:01:14.000
Let me disable gather facts.

00:01:15.000
00:01:16.600
Then let me read tasks section.
00:01:17.500
00:01:18.500
So just assume that.

00:01:20.100
00:01:21.700
I am writing a task called.

00:01:21.700
00:01:27.600
Let's say I want to run command
suppose LS route home.

00:01:29.100
00:01:32.800
Then I want to capture the output for
this so register.

00:01:34.500
00:01:40.300
LS out or home out Then immediately
I want to display that

00:01:40.300
00:01:41.400
out then simply.

00:01:41.400
00:01:43.400
You can write very close to home out.

00:01:45.100
00:01:45.700
That's fine.

00:01:46.100
00:01:49.000
Then I want to write one more task.

00:01:49.100
00:01:49.300
Now.

00:01:49.300
00:01:54.600
The purpose of this task is I need to
list for temple location

00:01:55.600
00:01:59.100
and let me capture the output into
some variable called.

00:02:00.400
00:02:05.300
temp out then let me display this.

00:02:08.400
00:02:11.900
So simply write y equals to Temp out
that's fine.

00:02:12.100
00:02:13.800
So guys in our Playbook.

00:02:13.800
00:02:15.100
We are having four tasks.

00:02:15.400
00:02:17.000
Let me run this play book first.

00:02:21.000
00:02:22.300
Just after the output first.
00:02:26.800
00:02:27.200
Right.

00:02:28.000
00:02:30.000
So those two tasks.

00:02:30.000
00:02:33.000
I mean, these are the main task right
this one and this one.

00:02:33.600
00:02:36.400
So whatever we are getting from this
you are displaying that

00:02:36.600
00:02:39.000
then whatever work we are getting
from this task you're displaying

00:02:39.000
00:02:42.500
here. So anyway or all four tasks are
successful.

00:02:43.300
00:02:44.500
That's why there is no problem.

00:02:44.900
00:02:48.000
But after that instead of home, I am
giving some invalid

00:02:48.000
00:02:52.500
path and let me run this and see the
output So let me run

00:02:52.500
00:02:53.800
this and see the output.

00:02:58.200
00:03:01.300
See your play book has been stopped.

00:03:02.300
00:03:06.200
Why the first reason is the command
first while running your

00:03:06.200
00:03:09.600
first command cannot access home.

00:03:09.800
00:03:11.200
I mean this path is not there.

00:03:12.100
00:03:15.300
So because this is fail, that's why your
playbook is going

00:03:15.300
00:03:17.500
to stop executing remaining tasks.

00:03:18.500
00:03:21.200
Now if Observer here, do you have
any dependency between
00:03:21.200
00:03:22.600
here and here?

00:03:23.600
00:03:26.600
No, Those are a noodle pass right?

00:03:27.500
00:03:30.000
There is no dependency between
these two paths individual

00:03:30.000
00:03:35.200
paths. So in case if I get any error
here at the time by

00:03:35.200
00:03:38.300
default, your ants bill is going to stop
the remaining tasks

00:03:38.400
00:03:39.500
on your target server.

00:03:41.400
00:03:44.400
So in case if I get an error, no
problem, I want to ignore

00:03:44.400
00:03:48.000
that if I when you are going to get an
error whenever if

00:03:48.000
00:03:51.100
it is going to be returned nonzero,
right?

00:03:51.500
00:03:55.700
Anyway, whether it is 0 or nonzero in
case if I get any error

00:03:55.700
00:03:59.400
or the time I want to I don't want to
stop the excluding

00:03:59.400
00:04:01.100
the remaining tasks in my playbook.

00:04:01.100
00:04:05.600
Then what you have to write is simply
can write ignore errors

00:04:05.700
00:04:06.700
option as yes.

00:04:08.100
00:04:09.600
Let me run this and see the output.

00:04:13.400
00:04:22.300
something Okay spell mistake.

00:04:25.399
00:04:26.000
See the output.
00:04:29.900
00:04:32.200
See first task was failed.

00:04:32.500
00:04:33.400
But no problem.

00:04:33.400
00:04:34.800
We are ignoring if it is failed.

00:04:34.800
00:04:37.900
We are ignoring so when it is going to
file written code

00:04:37.900
00:04:39.500
is two nonzero.

00:04:40.200
00:04:40.800
That's it.

00:04:42.600
00:04:42.900
Right.

00:04:42.900
00:04:47.900
See sometimes you want to ignore if
you get any error from

00:04:47.900
00:04:49.100
the current task.

00:04:49.200
00:04:51.200
Yes, you can ignore that using in this
way.

00:04:52.600
00:04:55.100
maybe sometimes whatever the
command you are running that

00:04:55.100
00:04:58.100
command output may be I mean even
though if it is giving

00:04:58.100
00:05:01.600
nonzero, you need to consider that
just assume that you are

00:05:01.600
00:05:04.100
running some shell script on your
remote server and your

00:05:04.100
00:05:07.400
shell script is going to return different
types of raincoats

00:05:07.400
00:05:12.600
exit codes, right if you if I get one
some meaning if I get
00:05:12.600
00:05:16.500
to some meaning You know that by
default your playbook is

00:05:16.500
00:05:19.800
going to fail whenever if written code
is nonzero, but we

00:05:19.800
00:05:23.000
know that for our requirement even
though if it is non zero

00:05:23.700
00:05:24.900
we have to consider it.

00:05:25.000
00:05:29.700
So at that time you have to take ignore
errors as yes, let

00:05:29.700
00:05:31.300
me give One More Sample.

00:05:32.700
00:05:34.400
Let me save this play book first.

00:05:35.800
00:05:37.400
So I want to share all these things.

00:05:42.700
00:05:43.700
Just give me a minute.

00:05:51.100
00:05:54.900
Now see suppose I am writing to tasks
in my playbook.

00:05:55.600
00:05:58.800
The very first task is opposed one
more thing.

00:06:02.500
00:06:07.800
Starting engine X then, you know to
start or stop any service

00:06:07.800
00:06:11.500
you have to take service module then
name in genetics then

00:06:11.900
00:06:19.100
state. Started then I'm going to write
one more task.

00:06:19.900
00:06:27.800
starting httpd Service, then name
httpd then let me write

00:06:27.800
00:06:29.400
straight As started.
00:06:31.000
00:06:31.500
That's it.

00:06:32.900
00:06:35.000
Let me run this play book and see the
output what you are

00:06:35.000
00:06:46.100
getting. first observe the output
starting in genetics fail

00:06:47.700
00:06:51.800
why because could not find the
requester service in Unix

00:06:51.800
00:06:54.600
on host in you as actually I don't have
any neck service

00:06:54.600
00:06:57.700
on my host because of that this task is
failing.

00:06:58.200
00:07:01.200
So if it is not there don't worry, at least
you have to start

00:07:01.200
00:07:03.800
extra debris may be a chilly Breeze
there on your host.

00:07:04.200
00:07:08.800
But because of this task fail the
subsequent tasks also they

00:07:08.800
00:07:11.600
are going to stop they're not going to
execute on your host

00:07:12.400
00:07:16.200
if current task is going to fail then
remaining tasks won't

00:07:16.200
00:07:21.100
execute on your if it is not there I don't
bother about it

00:07:21.300
00:07:25.000
if it if it fails okay no problem at least
run the second

00:07:25.000
00:07:27.900
task then what you have to write is
you have to write here
00:07:27.900
00:07:36.500
ignore errors yes and we need
become as Yes actually now

00:07:36.500
00:07:46.700
let me run and see the result it is
ignoring now starting

00:07:46.700
00:07:50.000
next he's ignoring but it is not stopping
I mean it is it

00:07:50.000
00:07:54.500
is going to execute the next task So
when it is going to

00:07:54.500
00:07:58.600
xcode next task, even though if your
current task fail whenever

00:07:58.600
00:08:01.800
if you had ignored errors as yes, that's
it.

00:08:04.200
00:08:07.300
Right fine and one more thing guys.

00:08:09.800
00:08:12.600
But me right here you are one more
play book.

00:08:14.900
00:08:16.800
Yeah, next thing is see.

00:08:16.800
00:08:21.500
Sometimes you need to fail your
required task wantedly.

00:08:23.200
00:08:26.000
Sometimes you need to failure
Playbook wantedly.

00:08:27.900
00:08:31.200
See, let me show you that so that you
can understand suppose

00:08:31.200
00:08:32.500
I am writing simply.

00:08:37.900
00:08:39.600
Local Host that's fine.

00:08:41.400
00:08:46.100
gather facts false Then let me write
tasks section.
00:08:47.500
00:08:51.400
So here I am writing simply Command
Module simply.

00:08:51.400
00:08:52.700
I'm writing LS.

00:08:54.400
00:09:00.800
Home guys, this is not exact Playbook
meaning just I am giving

00:09:00.800
00:09:05.900
this example to understand the usage
of concept called how

00:09:05.900
00:09:09.500
wantedly we can fail a task right see.

00:09:12.700
00:09:13.100
Yeah.

00:09:13.500
00:09:18.400
Anyway first thing yeah, let me show
you that register out.

00:09:18.400
00:09:19.800
Let me display that output.

00:09:21.400
00:09:29.600
so debug bar equals to out Even
though anyway, we know that

00:09:29.600
00:09:33.000
LS / home is the valid path you're
going to execute that

00:09:33.000
00:09:35.100
now through your playbook and you're
going to get success

00:09:35.100
00:09:38.200
output and you are getting written
code AS 0 right?

00:09:38.300
00:09:39.600
Let me run and see the result.

00:09:44.700
00:09:46.200
What is the written code here 0?

00:09:48.000
00:09:51.500
So suppose if I get written code AS 0
then I want to fail

00:09:51.500
00:09:52.300
my playbook.

00:09:52.300
00:09:53.900
I want to fail my task.
00:09:55.100
00:09:55.500
One deadly.

00:09:55.500
00:09:59.600
I want to fail if I get 0 if I get non zero
then no problem

00:10:00.800
00:10:01.400
right now.

00:10:01.400
00:10:02.800
See that how you can do that.

00:10:04.200
00:10:04.900
Here itself.

00:10:04.900
00:10:10.700
You can add a simple option called
failed van out dot written

00:10:10.700
00:10:14.000
kirino from your output a key called
written code, right

00:10:14.200
00:10:17.400
if it is equal to zero fail it now one
today.

00:10:17.400
00:10:20.700
I am failing my task now see the
result.

00:10:24.100
00:10:24.600
What happened?

00:10:25.600
00:10:27.300
Sorry failed.

00:10:31.900
00:10:35.300
See the output wantedly We are failing
our task.

00:10:35.300
00:10:35.800
That's it.

00:10:37.100
00:10:41.300
This is one way I mean actual this is
the latest way to fail

00:10:41.700
00:10:46.800
your task wantedly, I mean based on
requirement on not wantedly

00:10:46.800
00:10:48.300
actually based on requirement.

00:10:48.800
00:10:52.300
There is one more way old method.
00:10:52.300
00:10:55.100
I'm not actually not exactly old
method.

00:10:55.500
00:10:57.400
You can fail with some message as
well.

00:10:59.400
00:11:01.500
Let me write here itself suppose.

00:11:01.500
00:11:03.500
I am writing a task simply.

00:11:03.500
00:11:07.300
Once again this only guys you based
on your requirement.

00:11:07.300
00:11:10.400
You can take any written code just for
example, I am taking

00:11:10.600
00:11:13.700
I'm going to fail my Playbook or task
when written code is

00:11:13.700
00:11:16.300
zero. Just wait.

00:11:16.500
00:11:19.100
Yeah, let me write simply register.

00:11:20.900
00:11:23.200
Out that's it.

00:11:23.300
00:11:23.500
Now.

00:11:23.500
00:11:28.600
I am writing a module called fail a
module called fail in

00:11:28.600
00:11:29.900
the ad you can write some option.

00:11:31.900
00:11:39.200
failing failed because or C is 0 and
God is 0 then here.

00:11:39.200
00:11:43.800
You can write simply condition when
out dot or see if it

00:11:43.800
00:11:46.900
is equal to 0 We are failing that's it.

00:11:47.500
00:11:51.000
But instead of writing to separate tasks
if you want to fail
00:11:51.000
00:11:52.500
your task here itself.

00:11:53.800
00:11:58.200
Right, you can you can use an option
called failed when now

00:11:58.200
00:11:59.600
let me run and see the output.

00:12:04.500
00:12:05.000
That's it.

00:12:06.800
00:12:10.700
We are failing with required message,
so this is one more

00:12:10.700
00:12:15.600
weight to failure of Playbook on your
target, that's it.

00:12:16.800
00:12:17.100
Okay.

00:12:20.000
00:12:22.600
Okay guys, thank you for watching this
simple video.
Transcript
00:00:00.000
00:00:05.600
Friends, here our concepts are: what
is the block and error

00:00:05.600
00:00:08.500
handling with block and rescue in
playbooks?

00:00:08.500
00:00:11.800
See this concept is very important and
useful while

00:00:11.800
00:00:14.564
writing your real-time scripts. Let me
explain that.

00:00:14.564
00:00:21.400
See, already we know this point that
is, ansible stops playbook execution

00:00:21.400
00:00:27.500
on a task failure and we can choose to
ignore_errors to continue with the remaining tasks.
00:00:27.500
00:00:30.200
So the meaning for this is, suppose
just assume that you're

00:00:30.200
00:00:33.600
having a simple playbook which
consists of 3 or 4 tasks,

00:00:33.600
00:00:37.200
and assume that the very first task is
going to fail. And

00:00:37.200
00:00:40.900
if the first task fail, by default ,your
ansible will stop

00:00:40.900
00:00:48.300
the execution of remaining tasks on
your target. But if you

00:00:48.300
00:00:51.800
want to execute remaining task, even
though your first task

00:00:51.800
00:00:55.600
fail, then for your first task you need to
add an option

00:00:55.600
00:00:59.700
called "ignore_errors" so that you can
convert the remaining

00:00:59.700
00:01:03.200
tasks. Let me explain that with simple
playbook.

00:01:03.200
00:01:06.800
Let me open my ansible controller.
Suppose guys here

00:01:06.800
00:01:12.200
I'm having some tomcats on my host,
let's say tomcat7 and 9. Okay.

00:01:12.200
00:01:15.700
Now what I want to do is simply I want
to list, through playbook,

00:01:15.700
00:01:21.900
tomcat7 files and tomcat8 files and
tomcat9 files, but

00:01:21.900
00:01:29.400
we don't have tomcat8, right? But let
me try this playbook and see the result.
00:01:29.400
00:01:30.900
Let me write a simple playbook.

00:01:30.900
00:01:37.100
So I am going to take a playbook
name "ignore_errors_concept.yml".

00:01:37.100
00:01:39.500
Let me do this thing.

00:01:39.500
00:01:43.622
"- hosts: localhost"

00:01:43.622
00:01:47.352
"gather_facts: false"

00:01:47.352
00:01:51.800
So simply disable it by making as a
false or no.

00:01:51.800
00:01:53.070
Then let me write a task section:
"tasks

00:01:53.070
00:01:57.500
So the very first task is simply I am
taking a Command Module

00:01:57.500
00:02:00.234
"- command: "ls"

00:02:00.200
00:02:01.700
So let me provide complete path.

00:02:01.740
00:02:07.699
[no audio]

00:02:07.699
00:02:12.400
In this I have tomcat7 right? Let me
display that.

00:02:12.400
00:02:16.700
"- command: "ls
/home/ansadmin/tomcat7""

00:02:16.700
00:02:20.400
You want to display that output, then
you need to capture the output first.

00:02:20.400
00:02:27.011
"register: tomcat7_out"

00:02:27.011
00:02:36.758
Then I am writing "- debug:
var=tomcat7_out"

00:02:36.758
00:02:41.400
I will run this play book on see the
result.
00:02:41.400
00:02:46.900
So my playbook "cd
my_ansible_nprod"

00:02:46.900
00:02:55.671
Let me run "ansible-playbook
ignore_errors_concept.yml" just observe the output.

00:02:55.671
00:02:58.800
See, what is the output you're getting?

00:02:58.800
00:03:02.470
These are the files in my tomcat7
directory. That's fine.

00:03:02.470
00:03:07.800
Now, let me write include one more
task in your playbook.

00:03:07.800
00:03:18.684
"command:
"ls/home/ansadmin/tomcat8"". Remember tomcat8 is not there.

00:03:18.684
00:03:20.825
Anyway that will get fail, right?

00:03:20.825
00:03:23.766
Let me "register: tomcat8_out".

00:03:23.766
00:03:27.336
[no audio]

00:03:27.336
00:03:31.084
And let me display this information.

00:03:31.084
00:03:33.957
debug: var=tomcat8_out".

00:03:33.957
00:03:36.268
And let me write one more task

00:03:36.268
00:03:47.859
Be clear guys. This task: "command:
"ls /home/ansadmin/tomcat9"". We have tomcat9.

00:03:47.859
00:03:52.548
Then let me " register: tomcat9_out"

00:03:52.548
00:03:56.500
Guys you can take any variable name,
right? And I am trying

00:03:56.500
00:03:58.582
to display this information as well.

00:03:58.582
00:04:10.123
"- debug: var=tomcat9_out"
00:04:10.123
00:04:15.400
So guys now, if I run this playbook we
are expecting this task is going to

00:04:15.400
00:04:19.100
fail because we know that on my
server I don't have tomcat8 directory.

00:04:19.100
00:04:21.600
That's why this will fail.

00:04:21.600
00:04:26.399
So if it fails then on this server your
playbook will stop

00:04:26.399
00:04:30.200
the remaining tasks execution part.

00:04:30.200
00:04:31.542
Right? See the output first.

00:04:31.542
00:04:35.456
[no audio]

00:04:35.456
00:04:40.900
See second? While executing second
command your task failed.

00:04:40.900
00:04:44.800
That's why your playbook is going to
stop executing remaining

00:04:44.800
00:04:47.300
tasks on your target.

00:04:47.300
00:04:53.500
But even though if this task failed, I
want to execute remaining tasks. Then,

00:04:53.500
00:04:57.000
where you are expecting I mean task
is going to get failed

00:04:57.000
00:05:06.200
there you can add "ignore_errors:
yes". Now see the result.

00:05:06.200
00:05:09.700
If it is error, it will ignore but still it will
display

00:05:09.700
00:05:12.700
some output. That output may consist
of some information. See that

00:05:12.700
00:05:14.100
it is ignoring second command,
00:05:14.100
00:05:17.200
is ignoring. But If you observe in the
output, what

00:05:17.200
00:05:20.200
is the error we are getting? Cannot
access this, no such

00:05:20.200
00:05:24.000
file or directory. But after that you're
executing your third

00:05:24.000
00:05:29.470
command task. Then you are
displaying that with the help of debug module. That's fine.

00:05:29.500
00:05:33.500
But I assume that. Very simple guys.
Assume that

00:05:33.500
00:05:37.800
you are not sure tomcat7 is there or
tomcat8 is there or tomcat 9 is there.

00:05:37.801
00:05:39.705
[no audio]

00:05:39.758
00:05:42.929
Then I want to add ignore errors
option

00:05:42.929
00:05:47.764
for each and every option. For each
and every task then yes, you can do it. No problem.

00:05:47.764
00:05:54.710
[no audio]

00:05:54.700
00:05:55.200
That's it.

00:05:55.200
00:05:57.305
[no audio]

00:05:57.305
00:06:03.200
Right, but guys if you observe here,
for this task and for

00:06:03.200
00:06:06.100
this task right and even for your

00:06:06.100
00:06:11.675
[corrective text]

00:06:11.675
00:06:15.975
For three tasks, you are adding an
option called "ignore_errors: yes".
00:06:15.975
00:06:20.117
So why should I add separately
"ignore_errors: yes"

00:06:20.117
00:06:22.200
for each and every task? So instead of
that,

00:06:22.200
00:06:26.300
what I will do is, first I will write your
three tasks under

00:06:26.300
00:06:27.900
one block. For that block

00:06:27.900
00:06:30.104
I will give you "ignore_errors: yes".

00:06:30.104
00:06:33.200
Not only "ignore_errors: yes."

00:06:33.200
00:06:35.600
You can write number of options for
your block.

00:06:35.600
00:06:40.000
Let me explain that by writing you
code so that you will be good with that.

00:06:40.000
00:06:43.100
The first thing what I am doing is let
me directly copy this

00:06:43.100
00:06:49.000
three. You can debug your task at any
time, right?

00:06:49.000
00:06:51.600
So first task.

00:06:51.600
00:06:53.200
This is your second task, right?

00:06:53.210
00:06:55.248
[no audio]

00:06:55.300
00:06:59.700
I mean tomcat8 for tomcat9 or
tomcat7, 6, whatever it may

00:06:59.700
00:07:05.599
be. Instead of writing your option
individually for each and every task,

00:07:05.599
00:07:09.199
what I am going to do is: under your
tasks,
00:07:09.199
00:07:14.699
I am writing a block, 1 block. Just
assume that block is like a module.

00:07:14.699
00:07:19.400
But under module you have to write
your tasks. Under module,

00:07:19.400
00:07:21.800
you have to write the word "tasks".

00:07:21.800
00:07:23.549
Just provide some space here.

00:07:23.549
00:07:28.182
[no audio]

00:07:28.182
00:07:29.900
So guys, be clear. Under block

00:07:29.900
00:07:33.500
I'm writing three tasks. These same as
writing your individual

00:07:33.500
00:07:37.900
tasks. But the thing is, these three
tasks are there under

00:07:37.900
00:07:42.100
this block. So that if you want to add
any option for these

00:07:42.100
00:07:46.771
three, that option you can add for
block level.

00:07:46.771
00:07:53.700
Now "ignore_errors: yes", you can add
here itself. So that you are avoiding to

00:07:53.700
00:07:57.700
write ignore_errors for each and every
task. Instead of that,

00:07:57.699
00:08:01.099
we are clubbing these tasks under a
block section.

00:08:01.099
00:08:04.900
And for this block level, I'm applying
this.

00:08:04.900
00:08:10.199
Right? Now after this you can display
your debug.
00:08:10.200
00:08:13.166
I mean, let me remove now the
remaining things.

00:08:13.176
00:08:22.622
[no audio]

00:08:22.622
00:08:24.600
That's it.

00:08:24.600
00:08:30.900
For these three tasks, now this option
will be applied. Instead of writing your option

00:08:30.900
00:08:34.100
individually for each and every task,
we group the whole task

00:08:34.100
00:08:35.900
under one block. Then for that

00:08:35.900
00:08:38.700
we are applying "ignore_errors: yes".
Not only that,

00:08:38.700
00:08:43.159
sometimes you need to apply yes for
multiple tasks.

00:08:43.200
00:08:45.400
Sometimes you need to apply some
when condition for your

00:08:45.400
00:08:47.700
multiple tasks. In all those cases

00:08:47.700
00:08:51.299
you can write your tasks under one
block for that block level,

00:08:51.299
00:08:53.500
you can add your option. That's it.

00:08:53.500
00:08:55.100
Now, let me run this and see the
output.

00:08:55.110
00:08:59.044
[no audio]

00:08:59.100
00:08:59.600
That's it.

00:08:59.610
00:09:01.938
[no audio]

00:09:02.000
00:09:04.400
Right? Your three tasks are executing.
00:09:04.400
00:09:09.200
But anyway, second task will get fail
because that directory is not there. No problem.

00:09:09.200
00:09:13.700
We applied ignore_errors for all three
tasks. Be clear.

00:09:13.700
00:09:17.400
I applied this ignore_errors in the
block level, so that whatever

00:09:17.400
00:09:20.500
the task you are having inside of that
block for each and

00:09:20.500
00:09:24.200
every block this option will be applied.
That's it.

00:09:24.199
00:09:25.400
This is one case.

00:09:25.400
00:09:28.500
Let me write one more playbook,
which is somewhat interesting.

00:09:28.499
00:09:38.200
[no audio]

00:09:38.200
00:09:39.236
That's it.

00:09:39.200
00:09:42.700
I mean I have taken a playbook name
"advance_ignore_errors.yml" then in my inventory,

00:09:42.700
00:09:45.831
actually, I have a group called
[web_servers].

00:09:45.831
00:09:52.841
So "- hosts: web_servers". And

00:09:52.841
00:09:54.700
"gather_facts: true".

00:09:54.700
00:09:56.800
Let me write a true even though if you
don't write this line

00:09:56.800
00:10:01.400
by default, it will collect gather facts,
right? Then "tasks".

00:10:01.400
00:10:02.400
Tor your understanding, what I am
doing is simply
00:10:02.400
00:10:10.211
"- debug: var=ansible_os_family".

00:10:10.211
00:10:11.243
First see the output

00:10:11.243
00:10:13.916
[no audio]

00:10:13.916
00:10:22.394
"ansible-playbook
advance_ignore_errors.yml".

00:10:22.394
00:10:26.011
[no audio]

00:10:26.011
00:10:26.394
Just observe the output

00:10:27.300
00:10:32.800
first. How, see that, I have two servers
in my web servers group.

00:10:32.800
00:10:35.700
Then what is the output you are
getting? One is Debian actually

00:10:35.700
00:10:39.700
that is open to server. One more is
RedHat, right? Now guys

00:10:39.700
00:10:45.300
take a task like, if it is Debian, I want
to install Apache II

00:10:45.300
00:10:48.700
and I want to start that. And if it is
RedHat then I want

00:10:48.700
00:10:53.400
to install httpd and then I want to start
it. Right?

00:10:53.400
00:10:54.300
Let me do one thing.

00:10:54.300
00:10:56.300
Let me write a task now under this.

00:10:56.300
00:10:58.500
[no audio]

00:10:58.500
00:11:01.300
Without block concept if you write your
code how it will

00:11:01.300
00:11:06.700
be. And with our block concept if you
write your code how
00:11:06.700
00:11:08.300
it will be. Just observe the output.
Output is not different.

00:11:08.300
00:11:10.699
[no audio]

00:11:10.700
00:11:12.000
I mean there is no difference in output.

00:11:12.000
00:11:15.700
The only thing is while writing your
code you can group your

00:11:15.700
00:11:17.500
tasks under block section.

00:11:17.500
00:11:32.539
So first what I am doing "- name:
Installing httpd for RedHat os family"

00:11:32.500
00:11:39.100
[corrective speech]

00:11:39.100
00:11:47.519
Then "yum:"

00:11:47.519
00:11:50.429
Then you have to take "name: httpd"

00:11:50.429
00:11:53.431
[no audio]

00:11:53.431
00:11:59.100
Then let me provide "state: present".

00:11:59.100
00:12:03.399
That's fine. Then,

00:12:03.400
00:12:06.000
when you have to exclude this
condition, I mean this task,

00:12:06.000
00:12:12.220
in case "when:
ansible_os_family=="RedHat"

00:12:12.220
00:12:15.310
Let me take exact name of that family.

00:12:15.310
00:12:18.458
[no audio]

00:12:18.458
00:12:37.400
Then after installing your httpd
package, I want to "- name: starting httpd for Redhat os family"

00:12:37.400
00:12:38.906
That's it.
00:12:38.906
00:12:46.221
Then let me write "service:"

00:12:46.221
00:12:52.300
"name: httpd"

00:12:52.300
00:12:53.044
"state: started"

00:12:53.044
00:13:17.500
I'm going to apply a condition "when:
ansible_os_family=="RedHat"

00:13:17.500
00:13:19.100
Right, that's fine.

00:13:19.159
00:13:25.129
Now these two tasks are for
ansible_os_family RedHat. Same tasks

00:13:25.129
00:13:28.300
I need to take for Debian as well.

00:13:28.300
00:13:33.200
Let me take a copy of this installing
instead of httpd.

00:13:33.300
00:13:36.500
You have to install apache2 for Debian
family, right?

00:13:36.500
00:13:38.880
[no audio]

00:13:38.880
00:13:40.500
Then let me write here apache2.

00:13:40.500
00:13:43.509
[no audio]

00:13:43.509
00:13:48.300
But condition is Debian when os family
is Debian then only

00:13:48.300
00:13:49.600
have to take apache2.

00:13:49.600
00:13:59.310
[no audio]

00:13:59.300
00:14:02.900
Then service again apache2 here.

00:14:02.900
00:14:09.300
but family Debian.. That's fine.

00:14:09.300
00:14:12.800
Now finally, I want to write "debug:
successfully completed"
00:14:12.800
00:14:16.590
[no audio]

00:14:16.585
00:14:18.300
Successfully completed.

00:14:18.399
00:14:27.666
Let me write as "msg: Successfully
completed all tasks".

00:14:27.666
00:14:21.800
[no audio]

00:14:30.100
00:14:31.200
That's fine.

00:14:31.200
00:14:34.900
But we know that be clear for this
debug module.

00:14:35.100
00:14:38.500
We no need of any root privilege
option.

00:14:38.500
00:14:42.400
I mean become yes option no need to
add for this but for

00:14:42.400
00:14:45.899
remaining all four tasks we need to
add.

00:14:45.899
00:14:50.500
Become as yes then let me add it
"become: yes".

00:14:50.500
00:14:50.900
See guys.

00:14:50.900
00:14:53.400
I can also write become yes in the
task.

00:14:53.400
00:14:57.300
I mean for your entire playbook in the
play level I can write

00:14:57.299
00:15:02.199
"become: yes". But in my case, I'm
having one task called debug. For this

00:15:02.199
00:15:05.500
I don't want this become option.

00:15:05.500
00:15:08.500
Just assume that instead of writing
here.
00:15:08.500
00:15:10.430
In the task level you can write
"become: yes".

00:15:10.430
00:15:14.404
[no audio]

00:15:14.404
00:15:20.714
"become: yes". Then for each and
every task we need to add "become: yes" option.

00:15:20.714
00:15:23.000
[no audio]

00:15:23.000
00:15:28.319
There's this just I am giving for your
understanding about block concept.

00:15:28.319
00:15:31.891
[no audio]

00:15:31.891
00:15:33.233
That's fine.

00:15:33.233
00:15:36.200
Anyway, if you run this, it will work
right? Let me try with

00:15:36.200
00:15:38.904
[no audio]

00:15:38.904
00:15:45.395
gathering facts. So for one server with
httpd.

00:15:45.395
00:15:48.900
For remaining server with apache 2.
Just wait

00:15:49.000
00:15:52.800
it is going to collect gather facts. Then
skipping for one

00:15:52.800
00:15:57.400
server, installing httpd because that is
open to server or Debian family.

00:15:57.400
00:15:59.800
You can observe here previous task
output Debian.

00:15:59.900
00:16:06.099
It is skipping for that right. Starting
httpd for RedHat os family.

00:16:06.100
00:16:09.400
So it is skipping for this because it is
Debian you're running.
00:16:09.400
00:16:16.800
for RedHat os family. Now here
skipping for apache skipping for RedHat family.

00:16:16.800
00:16:19.110
Right. Now we'll yeah, that's it.

00:16:19.100
00:16:22.300
Now starting a Apache II for Debian os
family.

00:16:22.300
00:16:25.410
So it's skipping for RedHat family.
Right?

00:16:25.400
00:16:27.600
Anyway, you are all tasks has been
executed.

00:16:27.600
00:16:29.310
That's fine.

00:16:29.300
00:16:33.400
Now over here guys for this first task
and for second

00:16:33.400
00:16:40.210
task there is a common options right.
These two options you are adding.

00:16:40.200
00:16:43.200
So why should I add these two options
for this task

00:16:43.200
00:16:45.900
and this task in this way? Instead of
that

00:16:45.900
00:16:52.110
what you can do is first you can group
your two tasks

00:16:52.100
00:16:57.866
and in the further group, you can apply
your options.

00:16:57.866
00:16:59.900
So for that concept we are using
block.

00:17:00.100
00:17:03.529
So see that "block:". Under block

00:17:03.529
00:17:08.930
[no audio]

00:17:08.930
00:17:10.200
I am under block.
00:17:10.200
00:17:12.040
I'm grouping these two tasks.

00:17:12.040
00:17:18.510
[no audio]

00:17:18.500
00:17:19.727
That's it.

00:17:19.700
00:17:23.000
Now in the block level we clear. In the
block level

00:17:23.098
00:17:27.800
I am adding these two options so that
for this task and for

00:17:27.800
00:17:31.099
this task commonly, you are providing
this options.

00:17:31.098
00:17:36.000
That's it. The same way you can do for
second thing as well.

00:17:36.000
00:17:36.700
Yeah one more thing.

00:17:36.700
00:17:45.290
Yeah, that is for ansible_os_family
from RedHat right. Now, add one more "block:".

00:17:45.290
00:17:48.099
So in the block, for this block the
second block guys,

00:17:48.099
00:17:49.800
you can add any number of blocks in
your core.

00:17:49.800
00:17:50.500
No problem.

00:17:50.500
00:17:52.710
[no audio]

00:17:52.710
00:17:57.500
Yeah, instead of these two adding this
os family as Debian

00:17:57.500
00:18:02.710
and become yes, individually for each
and every task. Now we are clubbing.

00:18:02.700
00:18:03.800
We are grouping first, your two tasks.

00:18:03.800
00:18:11.910
[no audio]
00:18:11.900
00:18:17.700
Now in the block level see for this
block, right?

00:18:17.700
00:18:19.810
[no audio]

00:18:19.800
00:18:25.600
for this block we added when
condition and become yes, that's

00:18:25.600
00:18:30.200
it. So you are reducing writing these
two options for each

00:18:30.200
00:18:34.510
and every task. Right now, let me save
it.

00:18:34.500
00:18:38.000
So before going to run this, anyway
already have that I

00:18:38.000
00:18:42.610
mean. In your target servers just now,
we install your packages but no problem.

00:18:42.600
00:18:46.300
Let me rerun at least your playbook is
working or not.

00:18:46.300
00:18:47.300
You can verify that.

00:18:47.300
00:18:53.210
[no audio]

00:18:53.200
00:18:55.199
gathering facts. Once it is done.

00:18:55.199
00:18:57.800
Then first block will execute in
sequence only.

00:18:57.800
00:19:02.500
So in first block installing for RedHat
os family httpd,

00:19:02.500
00:19:07.500
This is open already is skipping,
starting httpd. So

00:19:07.500
00:19:12.110
guys, okay. Means already it was there
right? Yes. Okay.

00:19:12.100
00:19:13.500
Alright is running state now.
00:19:13.500
00:19:16.700
It is working for Debian family with
using second block.

00:19:16.700
00:19:29.810
[no audio]

00:19:29.800
00:19:30.300
That's it.

00:19:30.300
00:19:33.110
[no audio]

00:19:33.100
00:19:37.300
So guys finally simply block concept is
useful to group number

00:19:37.300
00:19:40.510
of tasks under one block.

00:19:40.500
00:19:46.210
So that you can apply common
options for all your tasks in one place.

00:19:46.200
00:19:46.910
That's it.

00:19:46.900
00:19:51.900
There is a simple usage of your block.
But using block how

00:19:51.900
00:19:57.700
you can use error handling? How you
can work with error handling

00:19:57.700
00:20:01.600
by using your block module in your
tasks section.

00:20:01.600
00:20:04.300
Let me write a simple playbook. Very
simple.

00:20:04.300
00:20:05.500
You can understand very easily.

00:20:05.500
00:20:07.710
[no audio]

00:20:07.700
00:20:09.002
error handling.

00:20:09.002
00:20:12.848
[no audio]

00:20:12.848
00:20:14.148
block_and_

00:20:14.148
00:20:19.082
[no audio]
00:20:19.082
00:20:23.233
rescue_errorhandling.yml.

00:20:23.233
00:20:27.800
See that guys I am taking "- hosts:
localhost"

00:20:27.800
00:20:38.846
You can take anything your target
"gather_facts: false"

00:20:38.846
00:20:44.900
Then I am writing "tasks:"

00:20:44.900
00:20:48.900
So now I'm using "block:", be clear
block. And in block

00:20:48.900
00:20:51.200
I'm writing one task called

00:20:53.500
00:21:04.300
"- name: Finding files in
/home/ansadmin/tomcat8". Then I am using

00:21:04.300
00:21:13.910
"command: "ls"
/home/ansadmin/tomcat8"

00:21:13.900
00:21:18.281
And I'm capturing the output. Anyway,
it will fail right. We know it will fail because

00:21:18.281
00:21:23.332
tomcat8 is not there on my host. Then
let me capture the output as

00:21:23.332
00:21:25.500
"register: tomcat8_out"

00:21:25.500
00:21:29.057
[no audio]

00:21:29.057
00:21:30.000
Right fine.

00:21:30.500
00:21:33.200
See you guys whenever if I run this
anyway, it is going to

00:21:33.200
00:21:38.700
fail. If it fails then only I want to run
other tasks. If it's

00:21:38.700
00:21:40.600
success, I don't want on other tasks.
00:21:41.600
00:21:45.200
That is the error handling with the help
of block. See,

00:21:45.200
00:21:49.100
if you know python or Java. In python
we are having try and

00:21:49.100
00:21:54.700
except block and in Java, we have try
and catch blocks.

00:21:54.700
00:21:57.700
So what is the purpose of that means?
Whatever it is

00:21:57.700
00:22:02.400
there in try block guys, in python if you
know python.

00:22:02.400
00:22:06.000
If you while running your code, if
something goes wrong with

00:22:06.000
00:22:08.500
the try block, then only accepted block
will execute.

00:22:08.499
00:22:13.899
Otherwise if try success then except
won't execute.

00:22:13.900
00:22:19.682
See that then just write "rescue:".

00:22:19.682
00:22:25.400
Don't take here - because for this
block this is rescue automatically.

00:22:25.500
00:22:29.200
Your answer will be, identify that.
Don't. Generally whenever if

00:22:29.200
00:22:30.600
you are taking some tasks, right?

00:22:30.600
00:22:32.600
This is like a task will write hyphens.

00:22:32.600
00:22:36.600
But for rescue, don't right "-" under this
block, only rescue

00:22:36.600
00:22:41.600
is there. Then enter. Simply I'm writing
"debug:".
00:22:41.600
00:23:03.302
I am writing a msg: "The given path:
/home/ansadmin/tomcat8 is not a valid path"".

00:23:03.302
00:23:04.443
That's it.

00:23:04.443
00:23:06.457
[no audio]

00:23:06.457
00:23:09.849
Let me run this and see the output.

00:23:09.850
00:23:15.700
So block and playbook name is
"block_and_rescue_errorhandling"

00:23:15.799
00:23:18.800
See the output? Finding files.

00:23:18.800
00:23:20.799
It got failed, right?

00:23:20.800
00:23:23.500
That's why your second task is
executing, which is there

00:23:23.500
00:23:26.680
in our rescue.

00:23:26.680
00:23:31.799
But suppose if this is a valid one if this
is a valid one.

00:23:31.800
00:23:34.334
If this is a valid one.

00:23:34.300
00:23:37.000
Now see the output your second task
is not going to explore

00:23:37.000
00:23:39.030
see that.

00:23:39.000
00:23:42.341
Second task is not going to execute.

00:23:42.300
00:23:53.310
Right, but if it fails this task is
executing. If its success right? This is skipping.

00:23:53.300
00:23:57.700
So in this way, you can handle your
errors using block on

00:23:57.700
00:24:00.100
rescue. That's it.
00:24:00.100
00:24:03.499
There is one more option with block
and rescue that is finally

00:24:03.499
00:24:08.199
same as finally in your python and
your Java.

00:24:08.200
00:24:14.160
So "finally:". So simply I am writing a
module under finally "debug:".

00:24:14.160
00:24:15.523
Let me write a message for that.

00:24:15.523
00:24:19.215
[no audio]

00:24:19.215
00:24:20.800
So this will always execute.

00:24:20.800
00:24:25.920
New Text

00:24:25.920
00:24:28.632
That's it.

00:24:28.600
00:24:34.400
Okay be clear. For block these two are
the optional. So for

00:24:34.400
00:24:37.400
block if you take rescue and finally
how they are going to

00:24:37.400
00:24:42.200
work? In your block, whatever the
code you are having whatever

00:24:42.200
00:24:43.400
the tasks or tasks

00:24:43.400
00:24:48.600
you're having, if that fail then only
rescue will execute.

00:24:48.600
00:24:51.800
But finally will execute always.
Whether your block is going

00:24:51.800
00:24:56.600
to get success or it is going to failure.
Finally will execute

00:24:56.600
00:24:59.000
always now. Let me run and see the
output.
00:24:59.000
00:25:01.810
[no audio]

00:25:01.800
00:25:02.300
What happened?

00:25:02.300
00:25:14.924
[corrective speech]

00:25:14.924
00:25:16.924
Sorry, not finally, "always:".

00:25:16.924
00:25:23.417
So in python it is "finally", in playbook
it is "always".

00:25:23.417
00:25:24.600
Now see the output.

00:25:24.600
00:25:27.710
[no audio]

00:25:27.709
00:25:30.900
This will execute always.

00:25:30.900
00:25:34.700
Right? Now, let me make it I mean
what I can do.

00:25:34.699
00:25:39.900
[no audio]

00:25:39.900
00:25:41.170
Let me take tomcat 8.

00:25:41.170
00:25:44.481
[no audio]

00:25:44.481
00:25:46.831
See previously your block was
success.

00:25:46.831
00:25:48.400
That's why it is skipping.

00:25:48.500
00:25:50.100
But anyway, it is executing right. Now

00:25:50.100
00:25:53.400
What I am doing is now I am trying to
take tomcat 8. Now it

00:25:53.400
00:25:57.000
will fail. If it will fail rescue will execute,
but anyway

00:25:57.000
00:25:58.751
always will execute, always. That's it.

00:25:58.751
00:26:00.800
I'll see the output.
00:26:00.800
00:26:03.383
[no audio]

00:26:03.383
00:26:05.008
It failed.

00:26:05.000
00:26:07.296
That's why rescues executing.

00:26:07.200
00:26:09.800
But anyway, you are always, will
always execute.

00:26:09.800
00:26:11.208
That's it.

00:26:11.200
00:26:14.500
So guys, this is the simple way to
handle your errors with

00:26:14.500
00:26:18.011
block rescue always in your
playbooks.

00:26:18.000
00:26:21.100
So very important point is you can use
block to group

00:26:21.099
00:26:26.399
your number of tasks so that you can
apply some options

00:26:26.400
00:26:29.800
commonly for each and every task
which is there in your block.

00:26:29.800
00:26:34.000
That's it. And be clear while taking
block rescue. And always

00:26:34.000
00:26:38.300
don't take hyphens for rescue and
always. And this type of

00:26:38.300
00:26:41.400
block rescue always you can write any
number of blocks in

00:26:41.400
00:26:43.354
your playbook.

00:26:43.300
00:26:43.800
That's it.

00:26:44.500
00:26:44.800
Okay.
00:26:46.600
00:26:49.100
Okay guys, thank you for watching this
simple video.
Transcript
00:00:00.000
00:00:04.310
Friends here we are discussing about
ansible playbooks.

00:00:04.300
00:00:09.209
See we know that we are having two
ways to execute a task on our managed nodes.

00:00:09.200
00:00:13.800
So what are the two ways: one is
using ad-hoc commands and one

00:00:13.800
00:00:19.210
more is using playbooks. See to
execute our task on your managed nodes already

00:00:19.200
00:00:24.810
we're having ad-hoc commands. Then
why we need to go with playbooks?

00:00:24.800
00:00:28.510
Let me explain this with an example.

00:00:28.500
00:00:33.610
See suppose I am having some
number of servers.
00:00:33.600
00:00:34.000
Right.

00:00:34.000
00:00:42.010
Let me open my inventory. Suppose I
am having 3 servers right now.

00:00:42.000
00:00:46.809
I have a requirement that I need to
install in all the servers

00:00:46.800
00:00:47.800
some packages.

00:00:47.800
00:00:55.309
Let's say I want to install httpd, nginx,
some wget package, some vim package.

00:00:55.300
00:00:57.010
Now as of now, we don't know
playbooks.

00:00:57.000
00:00:58.809
Actually, we know ad-hoc commands.

00:00:58.800
00:01:02.710
Now if I want to install httpd, what is
the ad-hoc command?

00:01:02.700
00:01:16.510
"ansible all -m yum -a "name=httpd
state=present""

00:01:16.500
00:01:20.710
Now, this is the ad-hoc command we
are running to install httpd, but at the same time, I

00:01:20.700
00:01:25.210
need to install my nginx as well, then
you have to run once again.

00:01:25.200
00:01:27.760
"ansible all -m yum -a "name=nginx
state=present""

00:01:27.760
00:01:32.930
Then one more ad-hoc command
"ansible all -m yum -a "name=wget state=present""

00:01:32.930
00:01:40.110
Then one more "ansible all -m yum -a
"name=vim state=present""

00:01:40.100
00:01:42.310
We are running four ad-hoc
commands.
00:01:42.300
00:01:44.600
So first we have to run first ad-hoc
command and then we have to

00:01:44.600
00:01:46.000
wait after completion of that.

00:01:46.000
00:01:48.800
Then we have to run second after
completion of that then

00:01:48.800
00:01:51.900
again, we have to run third one then
after that we have to

00:01:51.900
00:01:53.510
run fourth one.

00:01:53.500
00:01:56.310
So we need four steps to execute
these tasks.

00:01:56.300
00:02:01.510
I mean to install your httpd, nginx,
wget and vim packages.

00:02:01.500
00:02:05.000
Right? But using your ad-hoc
commands, you cannot install

00:02:05.000
00:02:07.310
all the packages at a time.

00:02:07.300
00:02:11.810
You don't have any possibility to install

00:02:11.800
00:02:13.910
all packages at a time with ad-hoc.

00:02:13.900
00:02:17.500
That means ad-hoc commands are
not helpful when dealing with

00:02:17.500
00:02:20.700
multiple tasks. If you want to work with
one task,

00:02:20.700
00:02:26.200
yes, we can go with ad-hoc command.
But if you want to execute

00:02:26.200
00:02:29.609
multiple tasks, then ad-hoc commands
or not suitable.

00:02:29.600
00:02:36.510
Then ansible playbook is the solution
for us in that scenario.
00:02:36.500
00:02:40.510
Then how you can do that? Just
assume that as of now,

00:02:40.500
00:02:42.510
these are the four ad-hoc commands.

00:02:42.500
00:02:48.000
What I will do is I will write in one file
and I will save

00:02:48.000
00:02:49.100
it as a suppose,

00:02:49.100
00:02:52.410
[no audio]

00:02:52.400
00:02:58.810
demo.yml. Now instead of running four
tasks to separately to install

00:02:58.800
00:03:02.010
your wget, vim, nginx, httpd,

00:03:02.000
00:03:06.010
now, what I did is I placed all this
under one file. Now, I

00:03:06.000
00:03:09.300
will run this file in one step. Previously
to install your

00:03:09.300
00:03:12.400
packages, we need to run four time
four steps.

00:03:13.400
00:03:16.400
Because for each outcome and you
had to run once. Four steps

00:03:16.400
00:03:20.100
we followed, but now I will run only in
one step this file

00:03:20.100
00:03:24.400
demo.yml file. That file will go execute
under ad-hoc

00:03:24.400
00:03:29.410
commands one by one. We reduce
three steps, right?

00:03:29.400
00:03:32.410
Anyway, we have to write file that is
one step.
00:03:32.400
00:03:35.900
Then we reduce your steps to execute
your tasks on your

00:03:35.900
00:03:39.510
managed nodes to install all these
packages.

00:03:39.500
00:03:46.609
That means playbook is helpful to
execute multiple tasks

00:03:46.600
00:03:53.200
and it eliminates the limitation of ad-
hoc commands. Using ad-hoc

00:03:53.200
00:03:55.800
commands, you can execute only one
task but instead of that

00:03:55.800
00:04:01.010
if you go playbook, you can execute
multiple tasks. That's it.

00:04:01.000
00:04:04.700
And basically, this playbook is YAML
file and it consists

00:04:04.700
00:04:09.609
of tasks or number of tasks. Suppose I
want to install only httpd. Yes.

00:04:09.600
00:04:13.109
We can write only one task in your
playbook.

00:04:13.100
00:04:16.000
Suppose if I want to install some
number of packages, yes you

00:04:16.000
00:04:19.409
can get multiple tasks also, no
problem.

00:04:19.399
00:04:20.600
Along with your tasks,

00:04:20.600
00:04:23.700
you can also use some different
concept like variables, files,

00:04:23.700
00:04:25.600
templates, some other concepts as
well.
00:04:26.500
00:04:31.110
Anyway, we'll go with all these
concepts step by step. As of now we don't worry.

00:04:31.100
00:04:34.210
If you go with all these things you can
add some effect to,

00:04:34.200
00:04:38.310
we can work with your managed
nodes in an effective way.

00:04:38.300
00:04:42.500
Right? And writing your playbook or
YAML file is very easy.

00:04:43.200
00:04:45.800
You can easily understand how to
write YAML file for your

00:04:45.800
00:04:52.000
playbook. And finally, playbooks are
the configuration, deployment

00:04:52.000
00:04:57.810
and orchestration language of ansible
and it is expressed in YAML format.

00:04:57.800
00:05:00.300
We know that using playbook we can
configure our servers,

00:05:00.300
00:05:03.400
we can deploy this on your servers,
and we can orchestrate

00:05:03.400
00:05:10.710
the servers. So all those things we can
achieve with playbooks very effectively. Right.

00:05:10.700
00:05:14.500
So to do any one of these tasks, either
configuration management

00:05:14.500
00:05:18.710
or deployment or orchestration we can
write a playbook.

00:05:18.700
00:05:23.810
But how to write, we will discuss, we
will learn step by step.

00:05:23.800
00:05:27.200
Right? Now, before going to work with
your playbooks.
00:05:27.200
00:05:29.300
First of all, you have to know what is
the structure of a

00:05:29.300
00:05:35.610
playbook. See basically, your
playbook having some concepts.

00:05:35.600
00:05:39.909
They are like task, play and playbook.

00:05:39.900
00:05:48.810
First let me explain with diagram.
Assume that this is YAML file or your playbook.

00:05:48.800
00:05:51.810
See it consists of number of plays.

00:05:51.800
00:05:55.100
You may have any number of plays in
your playbook. Suppose

00:05:55.100
00:05:59.010
"p-1" just assume that. I am writing
hyphens. Be clear.

00:05:59.000
00:06:04.650
That is our practice as well. "p-2", play
two and your "p-3".

00:06:04.650
00:06:08.510
Likewise, you can add any number of
plays in a playbook.

00:06:08.500
00:06:11.310
Now what is a play?

00:06:11.300
00:06:17.710
Play is the combination of tasks less
targets.

00:06:17.700
00:06:23.000
Tasks + targets. See how some tasks
on which servers unit

00:06:23.000
00:06:26.200
executes, that is your target. You
manage servers or targets,

00:06:26.200
00:06:30.600
right? So tasks with a target is called a
play.

00:06:30.600
00:06:33.409
[no audio]
00:06:33.400
00:06:37.000
Right? Now why we need to write
number of plays in a playbook?

00:06:37.800
00:06:42.700
Sometimes, just assume that, see in
our inventory

00:06:43.000
00:06:46.400
we have DB servers as well as web
servers. Suppose

00:06:46.400
00:06:51.300
I want to install httpd on the servers.
Now for this target

00:06:51.300
00:06:56.909
task is different, right. And on these
servers I want to install MySQL server.

00:06:56.900
00:07:00.400
Now the task is different for this group
and task is different

00:07:00.400
00:07:01.510
for this group.

00:07:01.500
00:07:05.100
That's why what we will do is, this task
will exclude on this

00:07:05.100
00:07:09.400
group. That's why I am going to write
one play for this. And

00:07:09.400
00:07:16.409
for these servers, I will write to install
MySQL task. And this is one other play.

00:07:16.400
00:07:19.800
In case if we how same task for all
servers, you can write

00:07:19.800
00:07:21.400
only one play in your playbook.

00:07:21.400
00:07:23.710
[no audio]

00:07:23.700
00:07:29.100
But sometimes you may need to do
you may how to perform different

00:07:29.100
00:07:32.010
tasks on different targets.
00:07:32.000
00:07:39.010
So for different tasks for different
targets, you need to write different plays in your playbook.

00:07:39.000
00:07:44.300
Right? Simply guys task is anything:
installing like http server

00:07:44.300
00:07:47.610
or installing Java or installing wget

00:07:47.600
00:07:49.200
or installing nginx server,

00:07:49.200
00:07:51.610
whatever it may be, that is a task.

00:07:51.600
00:07:54.300
Now play is nothing but, along with
your task,

00:07:54.300
00:07:56.800
if you mention your target, on which
target you are going

00:07:56.800
00:08:00.510
to perform your tasks, that is a play.

00:08:00.500
00:08:03.710
Right? Now playbook is the collection
of plays.

00:08:03.700
00:08:06.900
So when you will write number of
plays in your playbook, be

00:08:06.900
00:08:10.200
clear when you are going to write
number of plays in your

00:08:10.200
00:08:14.510
playbook. We will write number of
plays in your playbook

00:08:14.500
00:08:20.310
whenever if you have a different task
for different targets.

00:08:20.300
00:08:23.200
If on all servers if you want to perform
with same task,

00:08:23.200
00:08:25.909
you can add only one playbook.

00:08:25.900
00:08:28.600
Whenever if you want to perform
different tasks with the
00:08:28.600
00:08:32.409
different targets, then we will write
number of plays.

00:08:32.400
00:08:35.600
So we will discuss about how to write
a number of plays later.

00:08:36.200
00:08:37.000
For time being,

00:08:37.000
00:08:40.909
I am going to show you very simple
playbook with one play

00:08:40.900
00:08:43.700
and initially we will practice with only
one play. Once if

00:08:43.700
00:08:51.409
you get some idea then we will go and
execute number of plays with your playbooks. Right?

00:08:51.400
00:08:53.610
Let me open.

00:08:53.600
00:08:56.710
And I hope this has an inventory guys.

00:08:56.700
00:09:01.300
Right? Suppose my requirement is: I
need to install on all

00:09:01.300
00:09:05.500
the servers suppose simply wget
package. And all the servers

00:09:05.500
00:09:07.710
I want to install wget package.

00:09:07.700
00:09:12.510
So now observe that. Installing wget
package is the task.

00:09:12.500
00:09:20.610
This is a task. And on all the servers
now task with your target is a play.

00:09:20.600
00:09:21.710
That's it.

00:09:21.700
00:09:25.710
Now this play you're writing in one file,
that is a playbook.

00:09:25.700
00:09:27.910
Actually, you can write number of
plays also, no problem.
00:09:27.900
00:09:33.010
But for time being we are going to
discuss a playbook with one play, be clear.

00:09:33.000
00:09:35.600
We can write any number of plays in
your playbook for time

00:09:35.600
00:09:39.810
being. We are going to write only one
play in your playbook.

00:09:39.800
00:09:40.310
Right.

00:09:40.300
00:09:46.510
See playbook is a file playbook is
YAML file.

00:09:46.500
00:09:50.510
You have to start that play with three
hyphens.

00:09:50.500
00:09:53.300
Then inside of playbook as of now, I
am going to write only

00:09:53.300
00:09:57.310
one play. Assume that you have only
one play in your playbook.

00:09:57.300
00:10:01.110
So play consists of targets.

00:10:01.100
00:10:04.910
Targets as well as tasks.

00:10:04.900
00:10:07.710
The task on which you are going to
perform that is a target

00:10:07.700
00:10:10.710
Target with the task is a play. Right?

00:10:10.700
00:10:12.910
That play is a playbook here.

00:10:12.900
00:10:13.400
That's it.

00:10:13.400
00:10:17.410
[no audio]

00:10:17.400
00:10:21.900
Let me first write one simple playbook.
See an all my servers

00:10:21.900
00:10:24.100
I need to install simply wget package.
00:10:24.100
00:10:32.010
Then I am writing a playbook called "
vim install_wget.yml"

00:10:32.000
00:10:34.510
Okay, we'll discuss about that in detail.

00:10:34.500
00:10:35.310
What happened?

00:10:35.300
00:10:37.000
Yeah vmi is not there.

00:10:37.000
00:10:45.010
No problem install "vi install_wget.yml"

00:10:45.000
00:10:46.500
Now, see that? What I am writing first.

00:10:46.500
00:10:50.510
I am writing "---", which represent that
is a playbook.

00:10:50.500
00:10:52.500
Then under that,

00:10:52.500
00:10:56.700
you have to write one space first then
- then this is a play

00:10:56.700
00:10:59.310
or write a code for your play.

00:10:59.300
00:11:05.310
- we clear space - space now.

00:11:05.300
00:11:08.100
You have to write a play. Play is
nothing but targets plus

00:11:08.100
00:11:12.492
hosts. So first you need to mention
your targets: "hosts: all"

00:11:12.492
00:11:18.910
Then play may consist of one task or
more than one.

00:11:18.900
00:11:22.700
So you have a "tasks" section inside
the task.

00:11:22.700
00:11:26.810
You can write any number of tasks,
maybe one task or number of tasks see that

00:11:26.800
00:11:31.300
I am writing "yum" because we need to
install
00:11:31.300
00:11:33.910
wget package. We have to work with
yum write

00:11:33.900
00:11:40.100
yum. "name = wget", "state = present".
The same

00:11:40.100
00:11:44.900
type of ad-hoc command syntax. But
you know, this is you have

00:11:44.900
00:11:46.410
to exclude with root privileges.

00:11:46.400
00:11:49.500
That's why on our ad-hoc commands

00:11:49.500
00:11:52.800
we are writing - become option. Now
here we have to mention that

00:11:52.800
00:11:57.310
as a "become: yes? But don't worry.
We'll discuss in detail.

00:11:57.300
00:12:00.600
Now this is a simple playbook to install
wget package on all

00:12:00.600
00:12:05.410
your servers. Now let me run simply
that ansible playbook

00:12:05.400
00:12:10.010
install wget. Guys here I'm using a
password-less authentication.

00:12:10.000
00:12:12.900
I already exchanged my keys with all
my manage servers. Now

00:12:12.900
00:12:13.879
see the result

00:12:13.869
00:12:17.725
[no audio]

00:12:17.725
00:12:21.818
Yes changed zero means already
actually we

00:12:21.818
00:12:25.400
have that. Let me remove instead of
install. Let me remove

00:12:25.400
00:12:27.150
so that we can see that.
00:12:27.150
00:12:33.863
[no audio

00:12:33.863
00:12:40.410
So in detail, I will explain the output as
well with your playbooks.

00:12:40.400
00:12:42.810
See now changed one.

00:12:42.800
00:12:46.900
Just now we remove that our task is
actually its removed

00:12:46.900
00:12:50.110
change one means your task has
been executed.

00:12:50.100
00:12:54.400
Okay, and if you remember I told you
somewhere set up module

00:12:54.400
00:12:56.600
by default, will execute with your
playbooks.

00:12:56.600
00:13:00.610
But on ad-hoc commands you need to
run with - yum setup module,

00:13:00.600
00:13:03.200
but playbook, by default, will run your
setup module.

00:13:03.200
00:13:06.210
There is nothing but "Gathering
Facts".

00:13:06.200
00:13:06.900
Give me one second.

00:13:06.900
00:13:08.500
We'll discuss that now see.

00:13:08.500
00:13:11.410
[no audio]

00:13:11.400
00:13:17.600
Now what I am doing is install your
package now let instead

00:13:17.600
00:13:21.990
of absent let me write present or
latest.

00:13:21.990
00:13:27.092
[no audio]
00:13:27.092
00:13:32.010
Now if I run this it is going to install
your wget package on all servers.

00:13:32.000
00:13:37.910
Along with wget, suppose I want to
install let's say some vim as well.

00:13:37.900
00:13:39.310
Then it's very easy.

00:13:39.300
00:13:41.910
Add one more task on the other tasks
section.

00:13:41.900
00:13:54.110
Simply write see here "- yum
name=vim state=present" or latest. That's it.

00:13:54.100
00:13:56.810
So now we're executing multiple tasks.

00:13:56.800
00:13:59.200
So if already wget is not installed then
it will install

00:13:59.200
00:14:03.010
if it is there it won't install because
ansible is idempotent.

00:14:03.000
00:14:05.500
If it is already state is reached it won't
skip if it

00:14:05.500
00:14:07.900
is not reached then only it will try to
reach the required

00:14:07.900
00:14:12.110
state by using your playbooks.
Change one.

00:14:12.100
00:14:13.200
See that first yum is for install wget
second yum is just to install vim.

00:14:13.200
00:14:17.610
[no audio]

00:14:17.600
00:14:20.100
Already vim is there that's why it is not
installing.

00:14:20.100
00:14:22.510
[no audio]
00:14:22.500
00:14:25.710
Right? Now see that as of now we did
that.

00:14:25.700
00:14:28.010
I mean to install your wget and vim.

00:14:28.000
00:14:30.900
Let's say we have web servers now on
all servers.

00:14:30.900
00:14:33.800
We are installing wget and vim but on
web servers, I want

00:14:33.800
00:14:35.410
to install suppose.

00:14:35.400
00:14:39.100
Let's say httpd then I am going to write
one more play

00:14:39.100
00:14:43.100
book. That is install httpd Dot.

00:14:43.100
00:14:43.800
yml.

00:14:49.800
00:14:50.610
See the result.

00:14:50.600
00:14:53.000
I mean see the way how I am going to
write a play book three,

00:14:53.000
00:14:58.400
hyphens. Then - space - space host
now.

00:14:58.400
00:15:01.610
I want to work with only web servers,
right?

00:15:01.600
00:15:03.900
And if you want to install your
package, you need to have

00:15:03.900
00:15:07.000
a - b option on your own or commands
but here in playbooks.

00:15:07.000
00:15:13.000
You heard right become as yes then
tasks then what is your

00:15:13.000
00:15:14.710
task? You have to write with?
00:15:14.700
00:15:19.610
Funds so we'll discuss each and every
rule don't worry M

00:15:19.600
00:15:24.700
name equals to httpd State equals to
present if it is not

00:15:24.700
00:15:25.800
there then only it will install.

00:15:25.800
00:15:28.210
[no audio]

00:15:28.200
00:15:31.700
Now see that guys this is just to give
some idea.

00:15:31.700
00:15:34.100
Don't worry how to write a play book
will discuss that.

00:15:34.100
00:15:39.610
[no audio]

00:15:39.600
00:15:41.500
So already we have HTTP and all
servers.

00:15:41.500
00:15:45.610
That's why it is not installing now guys,
if You observe

00:15:45.600
00:15:48.300
if how to play books install.

00:15:48.300
00:15:50.710
[no audio]

00:15:50.700
00:15:56.210
wget packaged as one Playbook and
one more is installed

00:15:56.200
00:16:00.100
HTTP as a one more play book now
here Target is different

00:16:00.100
00:16:02.910
all but here Target is different web.

00:16:02.900
00:16:04.200
Now if I want to Club these two.

00:16:04.200
00:16:05.800
Yes, we can Club simply.

00:16:05.800
00:16:08.500
What I am doing is I am going to Club
this in your previous
00:16:08.500
00:16:13.200
playbook install wget now see the
result.

00:16:13.200
00:16:18.210
[no audio]

00:16:18.200
00:16:22.800
See, this is one play target is different
and action are

00:16:22.800
00:16:25.010
also different suppose tasks.

00:16:25.000
00:16:28.800
And this is second play Target is
different your task is

00:16:28.800
00:16:30.110
also different.

00:16:30.100
00:16:33.300
So now this is a complete playbook.
Playbook with the different

00:16:33.300
00:16:35.810
plays multiple plays.

00:16:35.800
00:16:36.610
Right.

00:16:36.600
00:16:40.000
Now what I am doing is I want to
remove and all my servers

00:16:40.000
00:16:43.210
your W Gateway I am package.

00:16:43.200
00:16:47.100
And HTTP servers on your web
servers then just let me write

00:16:47.100
00:16:50.810
apps and so that you can understand
how it is working.

00:16:50.800
00:16:51.000
Now.

00:16:51.000
00:16:52.910
I am removing in so instead of
installing.

00:16:52.900
00:16:57.300
I want to remove on all servers VI M
and W gate and on web

00:16:57.300
00:17:00.510
servers. I want to remove httpd.
00:17:00.500
00:17:01.000
That's it.

00:17:01.000
00:17:05.510
[no audio]

00:17:05.500
00:17:08.598
So, you guys now we have a playbook
with multiple plays.

00:17:08.598
00:17:10.559
[no audio]

00:17:10.549
00:17:14.608
This is a playbook that playbook with
two plays.

00:17:14.598
00:17:17.010
This play is organized with all these
servers.

00:17:17.000
00:17:19.410
This play is with your dumb web
servers.

00:17:19.400
00:17:24.710
That's it ansible Playbook install.

00:17:24.700
00:17:25.800
This is the Playbook name.

00:17:25.800
00:17:29.099
I am I'm removing actually now see
that it is executing.

00:17:29.099
00:17:32.200
First play first in sequence will execute
first will exclude

00:17:32.200
00:17:33.700
this one then it will execute second
one.

00:17:33.700
00:17:35.910
[no audio]

00:17:35.900
00:17:39.400
So in first to play first task is removing
the obligate and

00:17:39.400
00:17:41.510
vim done.

00:17:41.500
00:17:44.599
sorry first task is removing the obligate
second task is
00:17:44.599
00:17:49.200
removing vim done now in second
plays a task we have only

00:17:49.200
00:17:59.800
one task and removing HD DVD right
then that's it right so

00:17:59.800
00:18:05.500
finally, how to understand that this is a
play book which

00:18:05.500
00:18:10.600
consists of two plays why we need to
write a to plays means

00:18:10.600
00:18:14.200
whenever you have a requirement to
execute different tasks

00:18:14.200
00:18:19.610
on different targets Then we have to
write different plays.

00:18:19.600
00:18:22.400
So guys while practicing initially we'll
go with only one

00:18:22.400
00:18:27.810
play in your playbook then once if you
are good with your

00:18:27.800
00:18:31.300
Writing playbooks then we'll go with an
do work with multiple

00:18:31.300
00:18:32.910
plays in your playbook.

00:18:32.900
00:18:33.810
Okay?

00:18:33.800
00:18:34.400
Okay guys.

00:18:34.400
00:18:40.320
Thank you for watching this video.
Transcript
00:00:00.000
00:00:05.500
Here we are discussing uses of
delegate_to, run_once and

00:00:05.500
00:00:08.500
local_action in Ansible Playbooks with
a simple playbook

00:00:08.500
00:00:09.700
called Discovery Script.

00:00:09.700
00:00:12.200
So, here Discovery Script is nothing
but a Playbook. But the

00:00:12.200
00:00:15.800
purpose of that Discovery Script, is
that it will generate a CSV

00:00:15.800
00:00:20.000
file, and in that CSV file I have
information like - let me

00:00:20.000
00:00:21.800
draw the CSV file first.
00:00:24.200
00:00:27.000
Just assume that there are a number
of records and fields.

00:00:27.400
00:00:27.800
Okay?

00:00:28.200
00:00:29.800
So here is our server name,

00:00:30.900
00:00:32.299
then here OS name,

00:00:33.600
00:00:34.800
then OS family.

00:00:36.200
00:00:43.800
ways distribution, release version,
RAM size and then up time

00:00:43.800
00:00:45.400
of the server, something like that.

00:00:45.400
00:00:49.300
I need to generate a CSV file for for
my all servers, right?

00:00:49.500
00:00:51.300
So for that we are going to write a
playbook.

00:00:52.100
00:00:54.400
Of course, you can do this thing with
your shell script and

00:00:54.400
00:00:55.300
python script as well.

00:00:55.300
00:00:58.100
But, if you go with shell script and
python script, it will

00:00:58.100
00:01:02.400
take longer to get your details, but with
ansible

00:01:02.400
00:01:06.400
you will get your info much quicker.

00:01:07.500
00:01:09.400
Let me open my controller first.

00:01:10.700
00:01:13.200
See, I am taking Playbook name as
discovery_playbook.yml

00:01:13.200
00:01:20.500
First, let me write some information
here like Discovery
00:01:22.700
00:01:27.200
play. Now, let me take target as
web_servers and then,

00:01:27.200
00:01:29.800
et me disable gather_facts.

00:01:31.000
00:01:33.100
Then let me write it out, sections,

00:01:33.100
00:01:37.800
I mean tasks. In first ask what I am
doing, is finding OS

00:01:37.800
00:01:41.700
name. So if you want to find OS name,
you can run shell command

00:01:41.700
00:01:45.600
like shell: "uname" and I am
registering that output

00:01:47.600
00:01:49.900
with the OS name. Then,

00:01:49.900
00:01:51.400
let me write one more task.

00:01:51.700
00:01:55.000
The purpose of this task is finding up
time.

00:01:56.400
00:01:57.300
Right?

00:01:57.800
00:02:01.200
So if you want to find out time again
run your up time command

00:02:01.200
00:02:04.700
of your OS using shell or Command
Module then let me register

00:02:04.700
00:02:07.700
this output into a variable called up
time.

00:02:08.800
00:02:11.699
Actually, we need to find different
values to create your

00:02:11.699
00:02:12.400
CSV file.

00:02:13.199
00:02:16.500
Let me hold here and let me display
these two values first
00:02:17.400
00:02:21.500
so debug, let me write this playing.

00:02:24.900
00:02:27.800
Discovery info debug.

00:02:28.700
00:02:32.600
So with the help of message then
what I am doing is see guys,

00:02:32.900
00:02:36.900
you know, there is a default variable
called inventory hostname

00:02:37.000
00:02:40.500
through which you can display the
hostname then I want to

00:02:40.500
00:02:43.400
display here ways name.

00:02:43.800
00:02:47.200
So why is named we stored into a
variable called ways underscore

00:02:47.200
00:02:51.700
name then in that STD out we need
then let's say one more

00:02:51.700
00:03:00.600
thing. up time STD out first observed
this output So I ansible

00:03:00.700
00:03:06.300
Playbook Discovery first observe the
output then remaining

00:03:06.300
00:03:07.700
fields. We will get it.

00:03:08.500
00:03:12.400
So guys in my group of web servers
group one server is local

00:03:12.400
00:03:15.200
server. I mean ansible engine one
more server is from my

00:03:15.200
00:03:17.800
AWS Cloud just observe the output.

00:03:23.000
00:03:25.000
Finding up time just wait.

00:03:30.600
00:03:35.400
See that you are getting your server
name ways name up time
00:03:36.200
00:03:39.900
right but in up time suppose, I want to
get only four days

00:03:39.900
00:03:42.100
or two hours 31 something like that.

00:03:42.100
00:03:43.300
I don't want to get remaining thing.

00:03:43.300
00:03:45.400
If you want to get a number of users
on load average.

00:03:45.400
00:03:48.500
You can take it for time being I want to
get take only this

00:03:48.600
00:03:49.100
up time.

00:03:50.000
00:03:52.200
Then you can modify your information
in this way.

00:03:53.400
00:03:57.500
See I can split based on comma and
then I can take first

00:03:57.500
00:03:58.200
this value.

00:03:59.300
00:04:02.000
So guys if you are good at python, you
can easily understand

00:04:02.000
00:04:13.400
this. split, then get index 0 then again
split with up then

00:04:13.400
00:04:22.000
take index - 1 So based on this
comma and up I am doing that

00:04:22.200
00:04:24.500
now first other the output so that you
are going to get something

00:04:24.500
00:04:25.600
wrong. What is that?

00:04:25.899
00:04:26.200
Yeah.

00:04:26.200
00:04:27.800
I have taken here double quotations.
00:04:28.500
00:04:31.800
No because already for message guys
for message If You observe

00:04:31.800
00:04:33.700
here you're already taking double
quotations.

00:04:33.700
00:04:36.000
That's why just take here single
quotation.

00:04:37.500
00:04:38.800
Otherwise use Escape symbol.

00:04:42.400
00:04:44.400
Okay now let me run and see the
result.

00:04:45.700
00:05:03.700
first observe the output So along with
your uptime ways name,

00:05:03.800
00:05:05.900
I need suppose ansible ways.

00:05:06.000
00:05:10.200
I mean you are remote server ways
family distribution release

00:05:10.200
00:05:11.900
version all those things.

00:05:13.200
00:05:13.600
What happened?

00:05:21.400
00:05:22.100
Oh, sorry.

00:05:23.500
00:05:26.100
I have taken two times quotations.

00:05:27.800
00:05:28.600
It's my bad.

00:05:31.300
00:05:32.000
Now it's fine.

00:05:34.200
00:05:34.800
Sorry guys.

00:05:34.800
00:05:36.400
Let me run and see the result.

00:05:39.200
00:05:42.100
Anyway along with your waist name
and you are up time.
00:05:42.800
00:05:46.500
We are going to fetch some more
informations like OS family

00:05:46.500
00:05:50.800
distribution version and release and
for each and everything.

00:05:50.800
00:05:52.300
You need to write a separate task.

00:05:52.300
00:05:56.500
But if you are good at gather facts
Concepts in your gather

00:05:56.500
00:05:59.800
facts by default, you're going to get
some informations about

00:05:59.800
00:06:04.000
your manager nodes so actually to
find out you are What is

00:06:04.000
00:06:05.800
name you're using you name
command?

00:06:06.000
00:06:06.900
No need of that.

00:06:07.000
00:06:12.700
Let me remove this task if you are
good at and gather facts

00:06:12.700
00:06:17.300
Concepts. in your gather fares
concept there is a one of

00:06:17.300
00:06:27.600
the fact called ansible system Right
now, let me run and

00:06:27.600
00:06:28.400
see the result now.

00:06:31.100
00:06:32.200
Ansible system is nothing.

00:06:32.200
00:06:35.100
But your operating system named
you're going to get through

00:06:35.100
00:06:36.900
your gather facts by your ansible.

00:06:38.600
00:06:40.000
So it is gathering facts.
00:06:40.200
00:06:41.000
Just wait.

00:06:42.200
00:06:44.700
Now meanwhile, I'm going to write a
different variables.

00:06:44.700
00:06:46.800
I mean different information.

00:06:47.000
00:06:48.000
I want to get for that.

00:06:48.000
00:06:50.700
I am writing so and simple.

00:06:52.200
00:06:55.500
OS family, yeah got it.

00:06:55.500
00:06:59.400
See the output you're getting right
Linux Linux because there

00:06:59.400
00:07:02.300
is a default fact called ansible system
so that you can get

00:07:02.300
00:07:07.300
your manage server OS name so now
I am using that Concepts

00:07:07.300
00:07:09.700
here. That's why I'm enabling here
gather facts.

00:07:09.700
00:07:13.200
True then inventory hostname OS
family after that.

00:07:13.200
00:07:14.200
I want to get suppose.

00:07:15.500
00:07:17.800
What is name then distribution?

00:07:17.800
00:07:22.300
I want to get then there are some
default facts and simple

00:07:22.300
00:07:31.000
distribution. , then I want to get ansible
distribution version

00:07:31.000
00:07:33.000
you are having one more default fact
release.

00:07:33.000
00:07:34.300
Also you're having likewise.
00:07:34.300
00:07:37.000
You can get your require variables and
you can get them.

00:07:37.000
00:07:38.600
Let me run this and see the result.

00:07:40.800
00:07:44.700
For each and every server
automatically now you are going

00:07:44.700
00:07:51.300
to get in the output server name OS
family OS name and then

00:07:51.300
00:07:55.300
distribution then up time right just wait
and see the result.

00:07:57.200
00:07:59.400
But whatever the output you are going
to get that output

00:07:59.400
00:08:03.600
we want to redirect into some CSV file
is you are getting

00:08:03.600
00:08:06.500
the all information is required
informations.

00:08:06.800
00:08:10.100
Now, I want to generate a CSV file for
this information.

00:08:12.300
00:08:12.700
Right.

00:08:13.200
00:08:13.600
Yeah.

00:08:13.700
00:08:15.900
Now you're going to get your required
Concepts.

00:08:16.200
00:08:18.800
So guys just now we got our required
output.

00:08:19.200
00:08:23.100
Anyway, that is just to see a while
running your playbook.

00:08:23.100
00:08:27.600
We can see by using debug module,
but I want to rewrite this
00:08:27.600
00:08:28.900
information to CSV.

00:08:29.100
00:08:32.299
So before going to redirect into CSV
file, let me create

00:08:32.299
00:08:33.500
a CSV file first.

00:08:34.600
00:08:43.700
empty CSV file write C name creating
Mt.

00:08:43.799
00:08:50.299
CSV file So guys in case if already
CSV file, is there whatever

00:08:50.299
00:08:51.600
the name you are going to take.

00:08:52.200
00:08:55.400
So let me remove that first in case if
there are any hold

00:08:55.500
00:08:56.299
a CSV files.

00:08:56.299
00:08:58.800
Are there any way we are going to run
very first time but

00:08:58.800
00:09:01.800
while running second time you will
have your old CSV file

00:09:01.800
00:09:03.100
for your inventory or Discovery.

00:09:03.100
00:09:06.800
That's why removing world.

00:09:09.400
00:09:17.200
Discovery dot CSV file So there is a
file concept then you

00:09:17.200
00:09:19.000
can take that destination.

00:09:19.200
00:09:21.100
Let's say in the current destination.

00:09:22.900
00:09:26.900
Discovery dot CSV file right then
State.

00:09:27.100
00:09:28.700
Let me give it as absent.
00:09:28.700
00:09:29.100
That's it.

00:09:29.100
00:09:32.900
So that if file is there it will remove and
one more thing

00:09:33.000
00:09:36.000
now creating creating.

00:09:37.800
00:09:38.200
Mt.

00:09:38.200
00:09:39.800
Discovery dot CSV file.

00:09:40.900
00:09:44.200
So once you have a file in that we will
write our content.

00:09:45.800
00:09:52.300
right fine See that guy's actually for
your CSV file you

00:09:52.300
00:09:53.100
need header as well.

00:09:53.100
00:09:54.800
That's why instead of file module.

00:09:54.800
00:09:57.800
What I am doing is I am taking copy
module and I am providing

00:09:57.800
00:10:00.200
destination as in the current location.

00:10:02.200
00:10:06.400
Discovery dot CSV then I want to write
some content into

00:10:06.400
00:10:11.200
that. So content is like, you know
server name because if

00:10:11.200
00:10:14.600
You observe in your sequence what
we are having for server

00:10:14.600
00:10:18.800
name, we are having let me write
server name first IPR name

00:10:18.800
00:10:19.400
or fqdn?

00:10:19.400
00:10:22.200
Whatever it may be then OS family.
00:10:24.600
00:10:27.600
Next I'm taking, because by default
CSP can understand based

00:10:27.600
00:10:28.200
on commas.

00:10:29.300
00:10:30.500
Then why is name?

00:10:32.800
00:10:40.800
then distribution you can also take
release and version also

00:10:44.100
00:10:47.100
distribution then up time.

00:10:48.100
00:10:49.500
So I want these informations.

00:10:49.500
00:10:50.100
That's it.

00:10:51.200
00:10:55.900
Right and guys, you know that we
clear you know that whenever

00:10:55.900
00:10:59.000
if you run your playbook this task and
this task are also

00:10:59.000
00:11:02.000
going to exclude on each and every
server, but where you

00:11:02.000
00:11:04.700
want to generate your CSV file on your
Local Host.

00:11:04.700
00:11:07.600
I want to generate why should I create
my files in the remote

00:11:07.600
00:11:10.800
servers because finally I need my
information in my local

00:11:10.800
00:11:13.800
host. I need to create a result CSV.

00:11:13.900
00:11:14.900
On my Local Host.

00:11:15.800
00:11:19.400
We know that by default these two
tasks are going to not
00:11:19.400
00:11:21.900
only these two any task any task is
going to execute on each

00:11:21.900
00:11:24.800
and every Target server, but I want to
restrict that.

00:11:26.000
00:11:27.700
This and this tasks.

00:11:27.700
00:11:29.900
I want to execute on my local server.

00:11:30.000
00:11:34.500
So in that case you have to add one
option called delegate

00:11:34.900
00:11:39.200
to suppose if you don't add this it is
going to exhibit on

00:11:39.200
00:11:44.600
your remote servers now delegate to
localhost X good only

00:11:44.600
00:11:47.900
this task on my local host the same
way for this.

00:11:47.900
00:11:50.400
Also you have to add delegate.

00:11:52.900
00:11:54.200
Localhost that's it.

00:11:55.400
00:11:55.800
Okay.

00:11:56.200
00:12:00.400
Now let me run this play book and see
the result first then

00:12:00.400
00:12:02.200
we have to add one more option.

00:12:02.200
00:12:05.400
Actually, I will show you that why we
need to add that option

00:12:05.700
00:12:06.900
but first observe the output.

00:12:07.900
00:12:16.900
Gathering facts Then after that it will
run up time command.

00:12:17.900
00:12:19.600
Right finding up time.
00:12:20.900
00:12:22.400
Found four local hosts now.

00:12:22.400
00:12:25.400
It is founding I Finding Forever second
server.

00:12:25.500
00:12:26.400
Aw, server.

00:12:27.400
00:12:27.900
Got it.

00:12:27.900
00:12:29.900
Now removing old Discovery CSV file.

00:12:32.000
00:12:35.300
What happened creating Discovery
dot CSV?

00:12:38.500
00:12:44.400
Okay, spell mistake my content see
why Aunty Aunty it's my

00:12:44.400
00:13:02.900
bad. Finding up time.

00:13:06.500
00:13:10.700
Now once it is done, then it is going to
see that.

00:13:12.100
00:13:17.800
Removing old story CSV file creating
Discovery CSV file Target

00:13:17.800
00:13:18.600
is localhost.

00:13:19.900
00:13:23.000
Even though if you are running your
task based on your web

00:13:23.000
00:13:26.200
servers group, but Target is localized
because we modified

00:13:26.200
00:13:33.400
that with the help of delegated to right
fine and guys, actually

00:13:33.400
00:13:34.400
you're deleting right?

00:13:34.700
00:13:37.400
You're deleting Here If You observe
this task you are deleting

00:13:37.400
00:13:39.000
your Discovery dot CSV file.
00:13:42.300
00:13:42.800
Right.

00:13:43.300
00:13:48.200
And anyway, these two tasks, I mean
this task is on localhost,

00:13:48.900
00:13:50.900
but you are having in your target to
servers.

00:13:51.000
00:13:54.000
That's why these deleting two times on
your localhost.

00:13:54.300
00:13:57.600
Do we need to exclude that to X to
delete your file once

00:13:57.600
00:13:59.000
it is deleted it is not available.

00:13:59.000
00:14:00.000
Why should I be run?

00:14:00.100
00:14:04.100
Once again, first of all two times it is
deleting because

00:14:04.100
00:14:07.200
in web servers to group you are
having two servers, even

00:14:07.200
00:14:10.600
though your task is on Local Host
because you're having to

00:14:10.700
00:14:11.900
Gets in your inventory file.

00:14:11.900
00:14:14.800
I mean in your group in your target
section.

00:14:15.100
00:14:19.000
That's why it's task is running two
times the same way here.

00:14:19.000
00:14:21.400
Also, we are creating some header
CSV file.

00:14:22.200
00:14:23.300
We are creating here.

00:14:23.500
00:14:24.900
Why should we create a once again?
00:14:26.200
00:14:26.700
Right.

00:14:26.800
00:14:29.300
That's why only for these two tasks.

00:14:29.300
00:14:30.700
You need to run two times.

00:14:31.000
00:14:34.300
Just deleting one file creating one file
on your Local Host.

00:14:34.500
00:14:38.300
It is it is it is enough to run only once
that's why you

00:14:38.300
00:14:43.100
can run run once proved our yes.

00:14:49.300
00:14:49.800
That's it.

00:14:50.900
00:14:51.000
Now.

00:14:51.000
00:14:52.300
Let me run and see the result.

00:14:58.300
00:15:02.400
Because of run once now these two
tasks are going to execute

00:15:02.400
00:15:03.300
only one time.

00:15:04.300
00:15:06.900
I called easy enough to run only one
time on your Local Host

00:15:06.900
00:15:09.700
because you are deleting one file and
you're creating one

00:15:09.700
00:15:10.500
file with header.

00:15:11.600
00:15:13.400
So that is the usage of run once.

00:15:17.900
00:15:19.100
Just wait and see the result.

00:15:19.100
00:15:19.700
That's it.

00:15:20.400
00:15:23.700
See now it is you argue for executing
your task is that this
00:15:23.700
00:15:26.500
could only one time to delete your
Discovery dot CSV file

00:15:26.700
00:15:28.900
and creating discovered dot CSV file.

00:15:29.200
00:15:30.100
I mean with header.

00:15:30.200
00:15:31.700
Let me write that it's good.

00:15:31.700
00:15:39.700
I mean create Discord dot CSV file
with CSV header with header

00:15:42.700
00:15:43.300
That's it.

00:15:45.100
00:15:47.700
Right now see the file is created or
not.

00:15:49.700
00:15:52.100
Cat Discovery dot CSV.

00:15:52.100
00:15:52.500
Yes.

00:15:52.500
00:15:56.200
It has been created with server name
ways family waste in

00:15:56.200
00:16:00.200
distribution of time header has been
created but your cursor

00:16:00.200
00:16:02.400
is also I mean you our Command is
also coming in the same

00:16:02.400
00:16:06.600
line. You can simply add / n or the end
of this.

00:16:08.400
00:16:08.800
That's it.

00:16:10.500
00:16:10.900
Okay.

00:16:11.700
00:16:16.600
Now next thing is based on server
wise you have a information

00:16:17.100
00:16:19.200
in this way this entire information.
00:16:19.200
00:16:25.600
I want to store into my CSV file right
just to copy this

00:16:25.700
00:16:27.300
and see how I am going to do that.

00:16:27.700
00:16:32.000
There is there is a module called line
in file so updating.

00:16:33.400
00:16:39.200
Info of each server in CSV file guys.

00:16:39.200
00:16:45.400
There is a module called line in File so
here see if you

00:16:45.400
00:16:49.100
want to get there is a I mean directly
that is the module

00:16:50.000
00:16:53.500
in your ansible line in five.

00:16:54.200
00:16:55.400
Very very useful one.

00:16:55.700
00:16:59.300
You just go here and search in official
documentation the

00:16:59.300
00:17:00.800
usage of your line in file.

00:17:01.900
00:17:05.598
So there are some lot of options
available with the line

00:17:05.598
00:17:06.098
in file.

00:17:06.200
00:17:09.000
And so that you can see each and
every information in this

00:17:09.000
00:17:14.500
official documentation of your ansible,
right see that But

00:17:14.500
00:17:15.800
having different options here.

00:17:17.000
00:17:20.200
Okay line in file path and line based
on regex.
00:17:20.200
00:17:22.500
Also, you can add as of now we are
not using reg ex.

00:17:22.500
00:17:25.200
Anyway while going forward will use
different options as

00:17:25.200
00:17:30.599
well. Now, let me open your file line in
file path.

00:17:31.000
00:17:33.000
What is the path in the current
location?

00:17:33.099
00:17:35.800
We have a discovery dot CSV file in
that.

00:17:36.500
00:17:37.500
I want to add a line.

00:17:37.700
00:17:38.400
What is your line?

00:17:39.400
00:17:40.300
This is our line.

00:17:41.200
00:17:41.700
That's it.

00:17:43.700
00:17:46.000
Right and one more thing generally.

00:17:46.000
00:17:46.700
These are tasks.

00:17:46.700
00:17:50.700
Also going to run on your remote
server on Target only always

00:17:50.700
00:17:53.400
you're always accepted debug
module, right generally your

00:17:53.400
00:17:57.200
each and every task module will
execute the task on your

00:17:57.200
00:18:00.200
remote server on your target server,
but we are going to

00:18:00.200
00:18:02.400
create this information on Local Host,
right?
00:18:02.500
00:18:06.800
That's why for this also you need to
write delegated to localhost.

00:18:07.600
00:18:12.100
But if you here add run once what will
happen it will update

00:18:12.100
00:18:15.200
the information for only Server for all
servers you need

00:18:15.200
00:18:16.000
to repeat this.

00:18:16.000
00:18:18.400
That's why don't write run once here.

00:18:18.700
00:18:19.200
That's it.

00:18:20.300
00:18:28.400
Now, let me So ansible Playbook
Discovery Playbook Dot, yml.

00:18:34.500
00:18:35.900
So it is collecting facts.

00:18:37.300
00:18:40.500
Done with localhost working on your
one more server that

00:18:40.500
00:18:42.900
is called aw server.

00:18:45.000
00:18:48.600
Now finding up time found on your
localhost now working with

00:18:48.600
00:18:49.900
your second server.

00:18:53.300
00:18:55.100
You got the result right now.

00:18:55.100
00:18:59.600
It is creating CSV file now see the
result.

00:19:00.800
00:19:01.400
That's it.

00:19:01.900
00:19:05.900
Right you got your remote servers in
for I mean, you're all

00:19:05.900
00:19:08.000
managed service information this CSV
file.
00:19:08.600
00:19:14.500
So guys, this is the simple way to
create CSV file for your

00:19:14.500
00:19:15.700
Discovery purpose.

00:19:16.600
00:19:17.000
Okay.

00:19:18.900
00:19:24.300
Suppose if you're the Tomcat admin,
right and you want to

00:19:24.300
00:19:26.200
write a simple playbook for Discovery.

00:19:26.200
00:19:30.100
Like I need to find the Tomcat version
Tomcat home.

00:19:30.300
00:19:32.400
What is the Java is using by Tomcat?

00:19:32.600
00:19:34.600
How many applications are running
your tomcat?

00:19:34.900
00:19:38.000
And what is the port is used by your
Tomcat something like

00:19:38.000
00:19:40.700
that. I can find the information on each
and every server

00:19:40.700
00:19:44.900
and finally I can upload that update
that export the data

00:19:44.900
00:19:46.000
into CSV file.

00:19:46.500
00:19:48.300
So in that case it is very helpful.

00:19:49.100
00:19:50.300
Okay friends, that's fine.

00:19:50.400
00:19:53.800
Now let me explain the difference
between delegated to and

00:19:53.800
00:19:55.600
local action see already.

00:19:55.600
00:19:57.600
We know that delegated to option.
00:19:57.700
00:20:01.000
What is the usage of delegated to
delegate to is useful to

00:20:01.000
00:20:05.100
execute your task on this particular
server, even though

00:20:05.100
00:20:07.700
if you're having number of servers in
your web servers group

00:20:07.700
00:20:10.800
for all the servers this task is going to
execute on this

00:20:10.800
00:20:13.000
localhost. Not only Local Host.

00:20:13.000
00:20:17.700
You can provide any server name,
which is there in your inventory.

00:20:17.700
00:20:18.300
Let me explain.

00:20:18.400
00:20:22.700
in this with simple Playbook So I'm
going to write delegated

00:20:22.700
00:20:24.100
to versus local action.

00:20:27.800
00:20:29.300
See, I'm writing a simple Playbook.

00:20:30.200
00:20:37.500
Let me take host as a web servers
and then I am disabling

00:20:37.500
00:20:42.500
gather facts as a false and then let me
write the last section.

00:20:43.800
00:20:47.600
So first task simply I want to find first
uptime of all my

00:20:47.600
00:20:51.200
servers. And let me register this.

00:20:52.400
00:20:56.600
Integer variable called up time and let
me display the uptime

00:20:56.600
00:20:57.500
for all servers.
00:20:57.600
00:21:00.900
So simply by using debug wire equals
to of time.

00:21:03.400
00:21:10.300
Then dot STD out save it and run it
Playbook delegate to

00:21:10.300
00:21:13.700
local delegate to assess local action
dot yml.

00:21:14.400
00:21:17.500
So as of now we are not using any
local action or delegate

00:21:17.500
00:21:18.700
it to in your tasks.

00:21:20.500
00:21:22.500
And observe the output what you are
going to get your going

00:21:22.500
00:21:24.600
to find the uptime of each and every
server.

00:21:24.600
00:21:27.300
So for this server uptime is for days
and for This Server

00:21:27.300
00:21:32.900
suppose up time is 22 minutes, but
while executing your shell

00:21:32.900
00:21:36.800
module if I mentioned delegated to is
localhost.

00:21:37.900
00:21:42.300
Then your task is going to exclude for
two servers on this

00:21:42.300
00:21:43.200
localhost only.

00:21:43.200
00:21:46.600
That's why you are going to get up
time 22 means for two

00:21:46.600
00:21:52.300
servers see the result if it is executing
individually for

00:21:52.300
00:21:53.200
each and every server.
00:21:53.200
00:21:56.100
You have to get up timers for days and
22 minutes, but you

00:21:56.100
00:21:59.900
are getting for those two servers you
are getting 22 or 23

00:21:59.900
00:22:03.100
minutes for this server and the server
you are getting 23

00:22:03.100
00:22:08.600
minutes because your you mentioned
execute this task on this

00:22:08.600
00:22:13.400
localhost. Not only that you can also
execute your task.

00:22:15.100
00:22:16.500
Only require Target server.

00:22:16.500
00:22:20.100
Let me take I want to exclude the task
for all my servers

00:22:20.100
00:22:23.200
which are there in web servers for all
the servers exclude

00:22:23.200
00:22:24.500
this task on this target.

00:22:24.500
00:22:24.900
That's it.

00:22:25.400
00:22:28.200
Now save this and run it now you're
going to get up time

00:22:28.200
00:22:32.000
for two servers something like four
days because you are

00:22:32.000
00:22:33.300
excluding your task.

00:22:33.300
00:22:35.700
Shall uptime task anywhere.

00:22:36.900
00:22:40.700
Of 50 2.90 1.2 21.1 9 9 server.

00:22:41.100
00:22:42.900
That's why you're going to get up time
for four days.
00:22:43.300
00:22:43.800
That's it.

00:22:45.400
00:22:47.800
And then what about local action?

00:22:48.000
00:22:48.300
Nothing?

00:22:48.300
00:22:51.900
Is there suppose delegate to localhost
means you are going

00:22:51.900
00:22:55.100
to execute your task on localhost the
same syntax.

00:22:55.100
00:22:59.300
You can also achoo using this local
action module.

00:22:59.500
00:23:02.200
Nothing is that but you have to write in
this way which your

00:23:02.200
00:23:03.800
module then your arguments.

00:23:04.500
00:23:08.600
Anyway, this is old way now better to
use delegate to localhost

00:23:08.600
00:23:11.200
or delegate to any required server
instead of local action.

00:23:11.600
00:23:13.900
Anyway, let me run this and see the
result you're going to

00:23:13.900
00:23:17.800
get. Time for those two servers from
Local Host see the output.

00:23:18.100
00:23:18.600
That's it.

00:23:19.500
00:23:19.900
Okay.

00:23:20.000
00:23:22.700
So that is the difference between
delegated to on localhost.

00:23:23.000
00:23:27.600
Sorry local action local action by
default your task will
00:23:27.600
00:23:31.400
run for all servers on local server, but
delegate it to depends

00:23:31.400
00:23:33.400
on the server which you are going to
provide here.

00:23:33.600
00:23:35.900
If you provide Local Host this task will
execute on local

00:23:35.900
00:23:39.000
roads. If you provide any other server
your task will execute

00:23:39.000
00:23:40.100
on that Target server.

00:23:40.100
00:23:40.700
That's it.

00:23:41.000
00:23:44.500
So using delegate to you can prove
you can execute your task

00:23:44.500
00:23:48.100
and an any server but local action
always on local server.

00:23:48.100
00:23:48.500
That's it.

00:23:48.500
00:23:53.000
That is the difference between your
delegate it to and local

00:23:53.000
00:23:54.100
action. That's it.

00:23:54.400
00:23:54.800
Okay guys.

00:23:54.800
00:23:56.100
Thank you for watching this video.
Transcript
00:00:00.000
00:00:02.400
[no audio] Friends here

00:00:02.400
00:00:06.500
our concept is Python shutil module.
See this shutil module

00:00:06.500
00:00:10.600
is the default module with your Python
2 or Python 3 and

00:00:10.600
00:00:14.400
this module provides us in a number
of high-level operations

00:00:14.400
00:00:16.309
on files and directories.

00:00:16.300
00:00:21.200
They are like copy, move, remove and
much more. See using this

00:00:21.200
00:00:25.000
module, also we can do some file
operations, but compared
00:00:25.000
00:00:30.210
to VS module, shutil module is having
advanced level operations.

00:00:30.200
00:00:33.400
First let me show you the list of
operations or functions

00:00:33.400
00:00:35.910
which are available with your shutil
module.

00:00:35.900
00:00:38.809
So, we have some syntax to list them.

00:00:38.800
00:00:44.309
Let me open my terminal Python
Shell. First let me import

00:00:44.300
00:00:48.809
shutil module then simply use
dir(shutil)

00:00:48.800
00:00:52.100
If you observe here, we are having
different types of error

00:00:52.100
00:00:55.900
exception handling and some
operations with your shutil

00:00:55.900
00:00:59.900
module. There are different types of
operations, right. So

00:00:59.900
00:01:05.410
here I am going to explain about your
shutil module step-by-step.

00:01:05.400
00:01:10.310
So, in this part we are going to discuss
about operations

00:01:10.300
00:01:14.600
with copy related thing. Suppose if you
want to copy files

00:01:14.600
00:01:18.000
or directories using shutil module, then
what are the functions available with your shutil module.

00:01:18.500
00:01:22.000
The functions are available with your
Shuttle module right see

00:01:18.000
00:01:22.010
[no audio]
00:01:22.000
00:01:26.910
See that? If you observe here: copy,
copy_to, copy_ file,

00:01:26.900
00:01:31.410
these are the copy related operations
with your shutil module.

00:01:31.400
00:01:34.800
And one more thing, you can use the
shutil module with Unix-like

00:01:34.800
00:01:39.900
system also. So this is my scent OS.
Let me enter into my

00:01:39.900
00:01:44.100
Python 3 and here also you can import
your shutil and you

00:01:44.100
00:01:48.310
can see the list of operations, right?

00:01:48.300
00:01:53.200
So here, our concept is how to copy
files with your shutil

00:01:53.200
00:01:57.100
module. So, to copy we are having
different types of functions

00:01:57.100
00:02:01.110
with your shutil module. Why these
many operations or functions?

00:02:01.100
00:02:03.810
Let me explain them step-by-step.

00:02:03.800
00:02:07.410
So, suppose we are going to discuss
all these things, right?

00:02:07.400
00:02:11.600
So, first of all, let me take my complete
Python path.

00:02:11.600
00:02:15.910
[no audio]

00:02:15.900
00:02:19.900
So, this is my Python 3 path on this
host.

00:02:19.900
00:02:23.810
[no audio]
00:02:23.800
00:02:28.200
So, I already taken a sheet name as
shutil_part_1.py.

00:02:28.200
00:02:34.609
Now. So if you want to copy a file you
need source and destination first.

00:02:34.600
00:02:37.410
Let me take src.

00:02:37.400
00:02:43.410
I mean some file so I am taking from
this location one of the file.

00:02:43.400
00:02:44.910
Let me take one-by-one.

00:02:44.900
00:02:52.010
So. Source in this location, I have
supposed this script, so I am taking that.

00:02:52.000
00:02:54.800
Then destination also I am taking
same path first.

00:02:54.800
00:02:58.410
[no audio]

00:02:58.400
00:03:01.600
So, if you take same path, there is no
use but in case, if we

00:03:01.600
00:03:08.109
take same path, what will happen?
Shutil.copyfile.

00:03:08.100
00:03:11.100
So, guys, if you go in this order, then it
is very easy to

00:03:11.100
00:03:13.310
understand about all these operations.

00:03:13.300
00:03:18.800
So, I will write my order to explain
about copy operations

00:03:18.800
00:03:23.010
with your shutil module. Tat's fine.

00:03:23.000
00:03:26.500
So, shutil.copyfile(src,destination).

00:03:26.500
00:03:28.709
[no audio]

00:03:28.700
00:03:31.010
Now, just come here.
00:03:31.000
00:03:36.300
So, you have this script. So now let
me run this and see the

00:03:36.300
00:03:40.410
result. What happened?

00:03:40.400
00:03:43.810
Yeah, I forgot to import shutil module.

00:03:43.800
00:03:45.200
Let me import that first: import shutil

00:03:45.200
00:03:48.310
[no audio]

00:03:48.300
00:03:51.109
Now run that and see the result.

00:03:51.100
00:03:53.709
SameFileError.

00:03:53.700
00:03:57.600
So, your shutil module is giving an
exception: SameFile

00:03:57.600
00:04:02.810
Error. Actually, if you want to copy a
file from source destination

00:04:02.800
00:04:05.700
by taking source destination as same,
with same file name,

00:04:05.700
00:04:06.900
then there is no use. Suppose

00:04:06.900
00:04:09.910
I want to take a backup, then there is
some use, right?

00:04:09.900
00:04:14.209
So, I am taking this destination as
some backup file. Now if you run this.

00:04:14.200
00:04:17.110
[no audio]

00:04:17.100
00:04:20.810
So I'm running our script now it's
done.

00:04:20.800
00:04:25.500
Now again, see list files
working_with_remote_server.py

00:04:25.500
00:04:30.010
This is the file and we have taken our
backup for that.
00:04:30.000
00:04:34.100
Right. And if you observe here, this file
was created suppose

00:04:34.100
00:04:38.810
September 22nd, but this file created
just now.

00:04:38.800
00:04:42.900
And what are the permissions here.
These permissions and these

00:04:42.900
00:04:46.010
permissions are completely different.

00:04:46.000
00:04:52.200
Right. But while taking backup,
suppose I want to have same

00:04:52.200
00:05:00.510
permissions of my source file, then
don't use copy file. Then use copy simply,

00:05:00.500
00:05:08.110
shutil.copy(src,dest). So before going
to take it, I am removing

00:05:08.100
00:05:14.409
previous backup file. Let's be clear.

00:05:14.400
00:05:19.310
So why am taking copy instead of
copy file?

00:05:19.300
00:05:22.409
See if we take copy file,

00:05:22.400
00:05:30.510
it is not preserving the permissions of
your source file to your destination file.

00:05:30.500
00:05:33.300
But if you go with copy, whatever the
permissions are there

00:05:33.300
00:05:36.400
with your source file, same
permissions will be there for

00:05:36.400
00:05:38.710
your destination file as well.

00:05:38.700
00:05:45.200
Now, let me run our script and after
that just see that. This
00:05:45.200
00:05:50.010
is the backup file just now we have
taken using either copy

00:05:50.000
00:05:55.200
operation and see the permissions
here and here. Now. They

00:05:55.200
00:06:02.900
are same. But apart from permissions,
I want to have the entire

00:06:02.900
00:06:07.810
metadata as it is. Whatever it is.
Therefore your source file,

00:06:07.800
00:06:11.200
that entire metadata, I want for your
destination file as

00:06:11.200
00:06:15.010
well. That means timestamp also, I
don't want to change.

00:06:15.000
00:06:18.909
I want to get this timestamp for my
backup file.

00:06:18.900
00:06:21.700
Then use copy to module.

00:06:21.700
00:06:24.510
[no audio]

00:06:24.500
00:06:26.800
So, guys if you come from here to
here,

00:06:26.800
00:06:30.310
[no audio]

00:06:30.300
00:06:36.000
permissions so I am taking copy
operations.

00:06:36.000
00:06:38.810
[no audio]

00:06:38.800
00:06:44.710
Same permissions for source and
destination.

00:06:44.700
00:06:49.100
So now I am using
shutil.copy2(src,dest).

00:06:49.100
00:06:52.409
[no audio]
00:06:52.400
00:06:56.300
So, before that, let me remove once
again my backup file and

00:06:56.300
00:07:03.000
now I am running our script. Now see
the result. For you here,

00:07:03.000
00:07:05.409
[no audio]

00:07:05.400
00:07:09.200
backup file and your origin source and
destination. Now for

00:07:09.200
00:07:17.310
the both the files are having same
permissions and same timestamp, right?

00:07:17.300
00:07:26.110
So same metadata for this destination
as well. That's it.

00:07:26.100
00:07:31.810
So now we done with copy file first,
then copy, then copy2.

00:07:31.800
00:07:39.409
Right? Copy, then go with copy2. Now
you have some idea of why we are

00:07:39.400
00:07:44.200
using copy file or copy or copy2.
Right. Now, let me go with

00:07:44.200
00:07:46.510
copymode first.

00:07:46.500
00:07:48.100
We done with this 3 right? Now.

00:07:48.100
00:07:52.710
Let me go with copymode. See
nothing is there? Copymode.

00:07:52.700
00:07:57.610
Whatever the permissions are there
with your source file, that permissions only,

00:07:57.600
00:08:03.409
I want to get for same destination file.
But here, make sure that it is not copying a file.

00:08:03.400
00:08:06.600
It is giving only permissions of source
files to destination
00:08:06.600
00:08:15.000
file. See that? Suppose if you observe
here, let me for

00:08:15.000
00:08:18.700
this only, I am giving same
permissions, 700.

00:08:18.700
00:08:21.110
[no audio]

00:08:21.100
00:08:25.210
So, for this shutil module, we are
having 700

00:08:25.200
00:08:30.500
permissions. So, this permission I
want to provide for this

00:08:30.500
00:08:35.900
file. Then, take this as the source file.
Very simple guys.

00:08:35.900
00:08:42.409
[no audio]

00:08:42.400
00:08:47.210
Whatever the permissions are there
with our source file,

00:08:47.200
00:08:54.200
that permissions will be given to your
destination file. Now.

00:08:54.200
00:08:56.510
Let me comment this.

00:08:56.500
00:09:03.010
So, before running our script, we need
to add syntax as well. Right.

00:09:03.000
00:09:05.000
[no audio]

00:09:05.000
00:09:06.710
shutil.

00:09:06.700
00:09:12.100
copymode(src,dest). Be clear.

00:09:12.100
00:09:15.700
It is giving only permissions of your
source files to destination

00:09:15.700
00:09:24.110
file. Make sure that your source on this
destination must be exist. Right. Now.
00:09:24.100
00:09:30.410
So before running our python script,
what is the permissions of this?

00:09:30.400
00:09:37.110
775. Now. We are providing this
permission to this file.

00:09:37.100
00:09:40.410
So, we have given for that logic in our
script.

00:09:40.400
00:09:42.810
So now check it.

00:09:42.800
00:09:45.410
So, what are the permissions are
there for your backup file?

00:09:45.400
00:09:49.200
Whatever the permissions are there
for this script that

00:09:49.200
00:09:53.100
permissions have provided to your
destination file, but we

00:09:53.100
00:09:56.300
are not copying see that?

00:09:56.300
00:10:00.010
[no audio]

00:10:00.000
00:10:00.510
Right.

00:10:00.500
00:10:04.100
This is different content. This file is
different

00:10:04.100
00:10:08.800
content. So, with our logic, we are
providing only

00:10:08.800
00:10:16.110
modes permission of this file to this
file, but we are not copying. Be clear. That's fine.

00:10:16.100
00:10:23.300
Then copystat. See why we are using
copy to operation while

00:10:23.300
00:10:29.000
copying? I want to get entire metadata
of this file to destination
00:10:29.000
00:10:33.000
file. Suppose you already created your
destination file, but

00:10:33.000
00:10:36.900
you want to get some metadata of
same file to, I mean, you

00:10:36.900
00:10:41.710
want to assign same metadata of a file
to another file. Nothing

00:10:41.700
00:10:48.510
is there. Suppose, just observe that.
So we created this file November 1.

00:10:48.500
00:10:55.010
And what other data is there? Here I
mean, date Sep 22. So along with permissions,

00:10:55.000
00:10:59.910
I want to assign this timestamp to my
file.

00:10:59.900
00:11:02.700
Then you have to use copystat.

00:11:02.700
00:11:07.810
[no audio]

00:11:07.800
00:11:22.910
Simply
schedule.copystat(src,destination). Right. Now. Let me run this
and see the result.

00:11:22.900
00:11:26.200
[corrective speech]

00:11:26.200
00:11:30.110
[no audio]

00:11:30.100
00:11:33.510
So, guys previously your backup file
timestamp,is this one. Now.

00:11:33.500
00:11:37.900
We are assigning this timestamp to, I
mean, this timestamp

00:11:37.900
00:11:43.900
to your file. Just observe that. See
that? Timestamp of your

00:11:43.900
00:11:49.210
backup file and your python script are
same and permissions as well.
00:11:49.200
00:11:54.610
So entire metadata will be assigned to
your destination file.

00:11:54.600
00:12:00.510
Make sure that you are not copying
the content of your file to your destination file.

00:12:00.500
00:12:08.010
You are giving only permissions.
That's it.

00:12:08.000
00:12:10.410
See the content of this file is different.

00:12:10.400
00:12:13.300
This is the content. And the content of
this file is different,

00:12:13.300
00:12:22.310
right? This file is different. That's it.
That's fine.

00:12:22.300
00:12:26.100
Now, yeah guys, of this copyfileobj is
nothing but you

00:12:26.100
00:12:30.900
know, you can open a file using open
and read mode and you

00:12:30.900
00:12:34.210
can write that content into some other
file using write mode.

00:12:34.200
00:12:38.800
So, the file object whatever you
created that file object

00:12:38.800
00:12:41.700
can be copied from one file object to
another file object using

00:12:41.700
00:12:46.000
copyfileobj. Just assume that you just
drive it this

00:12:46.000
00:12:53.410
logic. Just suppose I'm there is a file
called xyz.txt.

00:12:53.400
00:12:57.500
I'm opening that in read mode and I'm
creating one more file
00:12:57.500
00:13:08.210
object. Some pqr.txt. But this is in
write mode. Right.

00:13:08.200
00:13:12.810
Now if you want to copy the content of
f1 to f2 then use

00:13:12.800
00:13:24.410
shutil.copyfileobj(f1,f2). Just try with
this.

00:13:24.400
00:13:28.110
Now, we are pending with one more
operation that is copytree.

00:13:28.100
00:13:34.200
Nothing is there. Copytree is useful to
clone or copy entire

00:13:34.200
00:13:42.110
directory recursively to your
destination. Let's say, suppose

00:13:42.100
00:13:43.700
I'm having some tomcat9.

00:13:43.700
00:13:48.610
So, if you observe that tomcat9, we
are having different data structure for that.

00:13:48.600
00:13:51.710
I mean different files and folders in
that, right? Now.

00:13:51.700
00:13:54.500
What I want to do is I want to copy
that entire directory

00:13:54.500
00:13:56.900
structure into some other file.

00:13:56.900
00:14:04.700
Let's say shutil.copytree. Let me take
now source

00:14:04.700
00:14:05.900
src="/home/Automation/tomcat7"

00:14:05.900
00:14:14.510
[no audio]

00:14:14.500
00:14:37.610
shutil.copytree(src,'/tp/tomcat7')

00:14:37.600
00:14:39.500
Right now, let me run this.
00:14:39.500
00:14:45.910
So before going to run, let me check it.
Is there any tomcat9?

00:14:45.900
00:14:49.910
I mean something tomcat7 or simply
tomcat. That is your wish.

00:14:49.900
00:14:52.510
You can take any destination directory.

00:14:52.500
00:14:54.100
We don't have any tomcat here now.

00:14:54.100
00:14:57.170
Let me run our python script.

00:14:57.170
00:15:09.110
[corrective speech]

00:15:09.100
00:15:12.410
tomcat has been created.

00:15:12.400
00:15:18.800
And make sure that it is giving entire
metadata, whatever

00:15:18.800
00:15:22.700
you are having for your source that
metadata will be provided

00:15:22.700
00:15:30.410
for your destination as well, using
copytree operation from your shutil module. That's it.

00:15:30.400
00:15:37.300
Right. Your last point. Suppose guys if
you want

00:15:37.300
00:15:41.900
to remove a directory structure

00:15:41.900
00:15:44.100
recursively, then simply you can use

00:15:44.100
00:15:46.510
[no audio]

00:15:46.500
00:15:51.200
shutil.rmtree. Simply your destination.

00:15:51.200
00:15:54.000
So, I am going to remove this path
only directly.

00:15:54.000
00:15:57.300
You can provide your destination or
the you can store your
00:15:57.300
00:16:03.010
destination into some variable some
dest variable and then

00:16:03.000
00:16:05.200
you can use that variable, otherwise
directly.

00:16:05.200
00:16:09.810
You can provide your source and
destination paths in your

00:16:09.800
00:16:15.400
operation itself, so rmtree. So it will
remove the entire

00:16:15.400
00:16:09.810
directory structure recursively.

00:16:17.600
00:16:21.910
So, suppose if I run that.

00:16:21.900
00:16:28.310
And see the temp location, you don't
have tomcat here. That's it. So guys,

00:16:28.300
00:16:36.110
these are the simple copy file
operations with your shutil module. Okay. Very useful.

00:16:36.100
00:16:40.700
Your develop site or some Linux
admin site or maybe

00:16:40.700
00:16:44.200
any admin, like WebLogic or
database. Because you are going

00:16:44.200
00:16:49.500
to take some backups, right, and in
your database site,

00:16:49.500
00:16:53.810
sometimes you need to create same
time stream for your destination as well.

00:16:53.800
00:16:59.310
So, other time you can use simply
copy to operation from your shutil mode.

00:16:59.300
00:17:04.000
Okay. Okay guys. Thank you for
watching this video.
Transcript
00:00:00.000
00:00:05.900
[no audio] Our concept here is
Introduction to template module.

00:00:05.900
00:00:08.800
We have seen the usage of template
module while working with

00:00:08.800
00:00:13.400
your Tomcat installation and
configuration and here I want

00:00:13.400
00:00:16.800
to show you one more example to
know the importance of your

00:00:16.800
00:00:18.600
template module in real-time.

00:00:18.900
00:00:20.700
Let me open my ansible controller.

00:00:21.700
00:00:25.800
So here I have an inventory in which I
have two servers and,
00:00:25.800
00:00:28.500
if you observe here, I have some
playbook.

00:00:29.300
00:00:32.799
First, let me run this Playbook.

00:00:32.799
00:00:35.600
So what is the purpose of this
Playbook? It's to simply install

00:00:35.600
00:00:38.800
your HTTP and then start the HTTP
service first.

00:00:38.800
00:00:39.900
Let me run this playbook.

00:00:43.400
00:00:48.300
Install and configure http.yml and if
you observe here,

00:00:48.400
00:00:52.300
I have written a playbook.
Straightforward, just simply install

00:00:52.500
00:00:55.900
and then start. We know if you run
your httpd, I

00:00:55.900
00:00:58.800
mean whenever if you install your
httpd by default, it is

00:00:58.800
00:01:01.100
going to run on the port called a gyro.

00:01:03.100
00:01:03.500
Right?

00:01:04.500
00:01:07.000
So meanwhile, I will open my Firefox
here.

00:01:09.100
00:01:11.700
So once installation is done, then we
will see that.

00:01:13.500
00:01:16.000
Just wait, you will get the usage of
template module.

00:01:22.300
00:01:26.200
Yes, installation and already it has
started your service,
00:01:26.400
00:01:31.300
I mean http service. Now, let me open
the URL.

00:01:36.900
00:01:39.500
So by default we'll run on the port
called 80.

00:01:39.500
00:01:43.400
Let me open that. You're getting a
default page of your

00:01:43.500
00:01:45.600
Apache or HTTP webserver, right?

00:01:46.000
00:01:49.300
Let me open one more URL for your
second server.

00:01:49.300
00:01:51.300
[no audio]

00:01:53.200
00:01:56.900
Now I have a requirement, see if

00:01:56.900
00:02:01.800
I run a playbook to install and
configure your httpd, I want

00:02:01.800
00:02:06.500
to get the default page of your web
server. Like this is from

00:02:06.700
00:02:10.100
here. I need to get information like this
is from this IP

00:02:10.500
00:02:11.900
and this is from this IP.

00:02:12.900
00:02:17.100
See, you are getting this default page
somewhere

00:02:17.400
00:02:23.600
from your httpd index file, index.html
file.

00:02:23.900
00:02:26.100
Let me show you that where you are
having that file.

00:02:28.500
00:02:31.100
Let me log in and do a remote server
or one of the server

00:02:31.100
00:02:43.000
first. Let me search otherwise.
00:02:49.900
00:02:53.500
Yeah, this is the actually the default
page from which you

00:02:53.500
00:02:57.200
are getting the information for you are
httpd, right?

00:02:57.700
00:02:59.700
The only here only you're having
HTTP right?

00:03:00.100
00:03:01.600
Let me open this file first.

00:03:05.300
00:03:07.400
And see the content you're getting
some content, right?

00:03:07.500
00:03:10.800
So what I am doing is let me remove
all the content.

00:03:10.900
00:03:14.100
I'm manually I'm trying to write this is
from so-and-so server.

00:03:22.400
00:03:25.700
This is from let's say I'm not writing
exit IP just I am

00:03:25.700
00:03:31.700
writing something but if you run your
Playbook by default,

00:03:31.700
00:03:35.100
I want to get the index page suppose if
this is this is the

00:03:35.100
00:03:35.600
server here.

00:03:35.600
00:03:38.100
I want to get this is from this IP right?

00:03:38.100
00:03:39.200
Let me refresh it here.

00:03:40.600
00:03:42.900
This is from just assume that this is
like 18.

00:03:42.900
00:03:49.200
2.20 of 5.1 19.1 I-94 and here also, I
want to get by default.
00:03:50.200
00:03:53.700
Right, that means while writing your
playbook through your

00:03:53.700
00:03:54.500
playbook itself.

00:03:54.500
00:03:59.800
I need to configure then see what I am
doing is I am writing

00:03:59.800
00:04:00.900
a template module.

00:04:02.200
00:04:03.000
Right, then here.

00:04:03.000
00:04:06.100
I am taking some source source is on
my Local Host.

00:04:06.100
00:04:09.900
I am taking some index dot HTML.

00:04:09.900
00:04:10.300
Sorry.

00:04:10.300
00:04:15.200
Yeah HTML dot g 2 so this file is not
there.

00:04:15.200
00:04:17.300
We need to create it then destination.

00:04:17.899
00:04:19.300
See what is the destination location?

00:04:24.500
00:04:26.100
Let me take complete path.

00:04:28.300
00:04:31.500
Please just wait you will get the idea
why we are using this.

00:04:39.600
00:04:45.100
Now simply we are copying some file
from our local server

00:04:45.100
00:04:46.000
to remote server.

00:04:46.400
00:04:49.600
But this I am taking as a ginger to
template file.

00:04:50.000
00:04:54.100
So in this file, what I am going to do is
let me create this
00:04:54.100
00:04:56.700
file first on your current location.

00:04:58.400
00:05:00.600
So I'm taking filename as in this way.

00:05:03.500
00:05:07.400
Then here I am writing see that this is
from I'm writing

00:05:07.400
00:05:08.200
some variable.

00:05:09.600
00:05:13.100
So, you know, there is a default
variable called inventory.

00:05:14.300
00:05:15.200
Host name.

00:05:15.700
00:05:18.000
Let me save it now.

00:05:18.000
00:05:20.300
I am re running out Playbook on
localhost.

00:05:20.700
00:05:23.600
I mean on our and simple controller.

00:05:25.300
00:05:29.200
See guys how it is going to work see it
is going to copy

00:05:29.200
00:05:33.000
this file to this location on each and
every server whatever

00:05:33.000
00:05:36.100
the server's you're having in your all
but while copying

00:05:36.100
00:05:40.200
this file to this location in this file, we
have a variable

00:05:40.200
00:05:42.800
called inventory hostname.

00:05:43.200
00:05:47.300
So whenever this content is copying to
First server automatically

00:05:47.300
00:05:49.200
that server IP will be replaced rear.

00:05:49.600
00:05:53.300
So dynamically, you are replacing the
variable values while
00:05:53.300
00:05:55.000
working with your respective servers.

00:05:57.200
00:05:59.400
Right now, let me run and see the
result.

00:06:02.800
00:06:04.600
So once it is done, then we will see.

00:06:17.600
00:06:19.800
Just wait now it is copying.

00:06:23.100
00:06:28.600
So once it is done, then we will open
our Firefox on there.

00:06:28.600
00:06:31.800
We will refresh the page and you can
see the result.

00:06:32.700
00:06:41.600
starting httpd service So yeah, it's
almost done.

00:06:43.600
00:06:45.100
Now, let me open your url.

00:06:45.700
00:06:48.000
I am refreshing see the result content
what you are getting.

00:06:49.400
00:06:55.000
And this is previous content, but just
now we copied index

00:06:55.000
00:06:58.800
dot HTML dot g to file to your remote
server with the name

00:06:58.800
00:07:01.900
called index dot HTML in the required
location.

00:07:02.400
00:07:03.300
I mean this one.

00:07:05.700
00:07:10.100
But while copying the content of
content from source to destination

00:07:10.400
00:07:13.200
if there are any variable in these that
will be replaced

00:07:13.200
00:07:16.300
dynamically. So we are replacing with
inventory host name
00:07:16.300
00:07:20.100
means with what server you are
working that server IP will

00:07:20.100
00:07:23.300
be replaced in the destination now see
the result.

00:07:24.700
00:07:27.400
So dynamically, we are able to
configure.

00:07:29.300
00:07:33.000
You are index dot HTML file and your
destination with help

00:07:33.000
00:07:33.800
of template module.

00:07:33.800
00:07:37.700
Not only this let us assume that by
default your Port is

00:07:37.700
00:07:41.700
running on a 0 right, but I want to work
with for one server

00:07:41.700
00:07:46.100
suppose 8080 another server suppose
8090 and not only port

00:07:46.100
00:07:50.500
numbers. You can replace any
parameter in your configuration

00:07:50.500
00:07:54.600
file using your template module on
your target server see

00:07:54.600
00:07:55.900
for your template module.

00:07:55.900
00:07:58.500
You are having Source destination as
arguments.

00:07:58.800
00:08:01.300
Not only these two are having different
types of arguments

00:08:01.300
00:08:03.400
for your template module which are
very helpful.

00:08:03.400
00:08:08.600
Let me open or template module
documentation from your official
00:08:08.600
00:08:13.200
website of ansible just open here and
see that so for your

00:08:13.200
00:08:16.900
hands while you're having some
default of variables and we're

00:08:16.900
00:08:19.800
having some different types of
arguments here just go to

00:08:19.800
00:08:23.000
this page and you can see here some
examples of your template

00:08:23.000
00:08:25.100
module right in next video.

00:08:25.100
00:08:28.200
We will see how to work with
variables.

00:08:28.600
00:08:32.400
In your template module and how to
use conditional statements

00:08:32.500
00:08:36.700
if if else if else if conditional
statements and then we

00:08:36.700
00:08:41.400
will also see some Loops to iterate
some lines or some values

00:08:41.500
00:08:42.799
in your template module.

00:08:43.100
00:08:43.500
Okay?

00:08:44.000
00:08:44.200
Okay.

00:08:44.200
00:08:44.600
Yes.

00:08:44.600
00:08:46.200
Thank you for watching this video.
Transcript
00:00:00.000
00:00:04.500
We know template module is useful to
copy a file,

00:00:04.512
00:00:08.305
from Ansible Engine, to manage
nodes, with some Dynamic data.

00:00:08.305
00:00:11.904
See, we already have in copy module,
but copy module,

00:00:11.904
00:00:13.836
is useful to copy a static file,

00:00:13.836
00:00:17.666
from your Ansible Engine, to manage
nodes, right?

00:00:17.666
00:00:23.164
Now, if you want to copy a file to your
manager node,

00:00:23.164
00:00:26.638
with some Dynamic data, then you
have to use template module,
00:00:26.638
00:00:27.836
So, if you want to use template
module,

00:00:27.836
00:00:30.100
you have to know the concepts, of
template module.

00:00:30.100
00:00:33.600
So, they are like, variables, conditional
statements and loops.

00:00:34.208
00:00:37.766
See, basically template and copy
model, both are useful,

00:00:37.766
00:00:41.651
to copy a file from your Ansible Engine
to managed nodes.

00:00:41.709
00:00:48.500
But, copy for static files, template for
dynamic data. Right, fine.

00:00:48.499
00:00:53.277
Now, copy module is having source
and destination.

00:00:53.277
00:00:56.052
Even template module, is also having
source and destination,

00:00:56.052
00:01:01.458
but source is always .jinja file, Jinja to
template file.

00:01:01.458
00:01:04.376
Of course, it is not mandatory, but it is
good,

00:01:04.376
00:01:09.200
to take .jinja2 as an extension for your
template module, source file.

00:01:10.700
00:01:13.386
Okay, we will see that, so suppose,

00:01:13.496
00:01:18.929
let me open my Ansible Controller, so,
this is my inventory file.

00:01:18.929
00:01:23.800
First, let me create some .jinja2 file
because template model is
00:01:23.800
00:01:27.000
useful to copy a file from your Ansible
Engine to node.

00:01:27.800
00:01:28.000
Right.

00:01:28.000
00:01:30.900
That's why, you should have a
somewhere some source file now.

00:01:30.900
00:01:40.100
I am creating source file name
jinjaexample,

00:01:40.100
00:01:42.300
you can take any name with .j2
extension.

00:01:42.600
00:01:43.200
That's it.

00:01:44.200
00:01:48.900
Okay, first let me write a simple data,

00:01:48.900
00:01:49.900
into this injaexample.j2 file.

00:01:50.300
00:01:55.600
So I am writing this is a simple file, x

00:01:55.600
00:01:57.400
into this jinjaexample.j2 content for
static content.

00:01:57.400
00:01:59.900
You can use copy module, no need to
use Jinja2 template

00:02:00.000
00:02:02.300
but our concept is template module.
So, first I will write static data then,

00:02:05.200
00:02:08.500
we will copy a dynamic data to your
manage nodes

00:02:08.500
00:02:10.199
with the help of template module first.

00:02:10.199
00:02:12.800
Let me write a simple Playbook,

00:02:12.800
00:02:13.800
to copy this file to your manage node.

00:02:14.100
00:02:15.700
Anyway, I have only one manager
node.
00:02:15.900
00:02:16.500
No problem.

00:02:16.500
00:02:19.200
You can work with any number of
nodes now.

00:02:19.200
00:02:20.700
Let me write a play book,

00:02:22.500
00:02:29.700
template_module_usage.yml,

00:02:29.700
00:02:30.600
so simply am starting with three
hyphens.

00:02:30.600
00:02:36.200
Then I am writing directly host,

00:02:36.500
00:02:37.600
as simply all then I'm disabling, gather
facts.

00:02:40.600
00:02:42.000
Let me write it a section.

00:02:42.100
00:02:43.400
So very first task simply,

00:02:43.400
00:02:46.700
I'm writing, I'm giving a name for your
task.

00:02:48.600
00:02:53.700
Copying a file, to manage node or
nodes.

00:02:54.500
00:02:57.200
So, I'm using template module source.

00:02:57.800
00:03:00.400
So, anyway your file is there in the
current location?

00:03:00.400
00:03:04.100
That's why directly can provide the
name of your source file.

00:03:04.100
00:03:06.000
If it isn't a different location,

00:03:06.000
00:03:06.800
you have to provide the complete
path.

00:03:07.800
00:03:08.500
Right, then,
00:03:08.500
00:03:09.700
Let me write it's destination.

00:03:10.300
00:03:12.900
So under temp location on my
managed node.

00:03:12.900
00:03:19.300
I am writing done with Jinja2 done with
template.txt file.

00:03:19.300
00:03:23.800
So, that is your requirement, whether
you want to store

00:03:23.800
00:03:28.100
in your manager node with extension
as .txt, or .XML,

00:03:28.900
00:03:31.700
right or some .com file, whatever.

00:03:31.700
00:03:33.200
It may be based on your requirement.

00:03:33.200
00:03:37.000
You can provide the destination file
extension now,

00:03:37.000
00:03:37.500
let me save it.

00:03:37.800
00:03:41.600
Go to command line of Ansible
Playbook.

00:03:42.300
00:03:46.000
So our Playbook name is
template_module_usage.yml,

00:03:46.000
00:03:47.600
let me run this.

00:03:51.700
00:03:57.600
So meanwhile, I will open my Manager
node, so this is my

00:03:57.600
00:03:58.400
manager. No.

00:04:03.300
00:04:06.200
So let me move into temp location on
my manager node.

00:04:07.200
00:04:09.000
So, just now the file has been created.
00:04:09.000
00:04:12.300
Then with the template_module.txt
open,

00:04:12.300
00:04:16.200
that this is a simple file, see if you
observe this content,

00:04:16.300
00:04:22.300
this is the destination file content, and
in my Matt I mean

00:04:22.300
00:04:26.899
my Ansible Indian, I mean source,

00:04:26.899
00:04:29.100
for is also same, so that means this is
static file,

00:04:29.100
00:04:30.500
for static file, you know need to use
template model directly.

00:04:30.500
00:04:36.000
You can use copy module, but now
observe,

00:04:36.000
00:04:37.300
that suppose I am defining a variable.

00:04:38.600
00:04:39.600
Under which section, I am defining,

00:04:39.800
00:04:48.600
let's say some HTTP Deport some
8080 right

00:04:48.900
00:04:54.600
Now, If you want to replace if you want
to place the value

00:04:54.600
00:05:00.600
of httpd port in the destination file for
that related concept.

00:05:00.600
00:05:03.200
You need to write a logic in our
template file.

00:05:03.200
00:05:04.800
So I am writing now here.

00:05:06.000
00:05:17.800
So, this server is having port for HTTP
d as
00:05:17.800
00:05:22.500
so, what is the variable, I use the here
in my playbook httpd Port copy,

00:05:22.500
00:05:27.100
that variable name, and then here
right with two curly braces

00:05:27.100
00:05:32.300
then paste your variable C now
actually httpd Port is the variable.

00:05:33.500
00:05:37.000
Okay, whenever if you copy this file to
your manager node

00:05:37.600
00:05:41.200
based on the value, which is there in
your play book,

00:05:41.200
00:05:45.800
for HTTP report that value will be
replaced in this place.

00:05:46.000
00:05:48.600
And that content will be copied to your
manage node.

00:05:48.600
00:05:51.200
That means, now this is not a static
file.

00:05:51.200
00:05:51.300
Now.

00:05:51.300
00:05:54.500
This is a dynamic file based on the
value,

00:05:54.500
00:05:55.500
which is there in your playbook.

00:05:55.800
00:05:59.700
The source file data, will be modified,

00:05:59.700
00:06:03.200
and that data will be copied to this
location now,

00:06:03.300
00:06:08.900
let me rerun your playbook again. So,
I copied all the, I saved a Playbook right

00:06:08.900
00:06:12.800
Now, let me run this, and see the
result,
00:06:12.800
00:06:16.000
and you are manager node. So I am
going to open my manager node previously.

00:06:16.000
00:06:21.000
You know, what is the data, is there
now,

00:06:21.000
00:06:22.200
let me still your playbook is running
here.

00:06:24.800
00:06:26.100
Just wait for some time.

00:06:28.100
00:06:31.700
You know, this is my VMware server,

00:06:31.700
00:06:32.400
and the managed node is from cloud.

00:06:32.900
00:06:34.700
So some delay.

00:06:35.000
00:06:35.300
Yeah.

00:06:35.400
00:06:39.200
Now, let me try and see the result of
dynamic leader,

00:06:39.200
00:06:42.700
has been replaced the that data,
suppose in future.

00:06:42.800
00:06:46.100
If you want to modify, the were port on
your manager,

00:06:46.100
00:06:48.300
knows, you know need to login with
each and every server,

00:06:48.300
00:06:51.500
and you now need to modify, the port
number and your manager nodes.

00:06:51.500
00:06:54.600
Just to go to open your playbook, and
modify Port,

00:06:54.600
00:06:59.700
as suppose 7 0 suppose 7 double 0 1,
just assume.

00:07:00.100
00:07:00.800
that let me save it, and run it.
00:07:01.100
00:07:04.200
So, whatever the manager knows you
are managing,

00:07:04.200
00:07:06.800
with your playbook on all those
manager nodes.

00:07:06.800
00:07:10.700
Dynamically, you are going to modify
the port number,

00:07:11.000
00:07:13.000
in your httpd.conf file.

00:07:13.700
00:07:14.100
Of course, I am not taking a file name

00:07:14.100
00:07:16.500
as con file. So, just I'm giving concept.

00:07:16.900
00:07:18.200
So, once it is done,

00:07:19.600
00:07:23.100
it is going to modify the data on your

00:07:23.100
00:07:24.100
managed nodes.

00:07:24.300
00:07:26.500
Let me reopen my file and see the
result.

00:07:26.900
00:07:27.400
That's it.

00:07:27.900
00:07:30.000
So that is the usage of your template
module.

00:07:30.300
00:07:30.800
Right?

00:07:30.800
00:07:35.200
So just now we discussed about
variables in your template module.

00:07:35.200
00:07:39.600
So nothing is there if you want to
replace a variable,

00:07:39.600
00:07:41.500
value you have to write in this way.

00:07:43.000
00:07:45.900
Two curly braces then inside that
variable.
00:07:45.900
00:07:51.400
I mean variable name make sure that
this is in your source

00:07:51.400
00:07:52.500
to file this syntax.

00:07:52.500
00:07:54.200
Should be there in your source file.

00:07:54.700
00:07:56.300
That is simply about variables.

00:07:56.800
00:07:56.900
Now,

00:07:56.900
00:07:58.800
let me go with conditional statements.

00:07:58.900
00:08:02.600
So conditional statements, is like if-
else, and if-else if-else if.

00:08:02.600
00:08:06.500
Now, let me go with very simple
condition that is simply

00:08:06.500
00:08:10.700
if condition so if condition that is the
syntax then,

00:08:10.700
00:08:13.100
whatever the logic, you I want to write
if this condition,

00:08:13.100
00:08:15.100
is true, that logic you have to write
here.

00:08:16.300
00:08:19.600
Then, close your if condition, let me
show you that.

00:08:21.800
00:08:26.900
suppose I am going to write a logic,

00:08:26.900
00:08:30.900
simple logic in my Template module. I
mean sorry,

00:08:30.900
00:08:35.100
with my source file see that what I am
writing is First these are syntax.

00:08:35.100
00:08:40.799
You have to follow, for your if
condition,
00:08:40.799
00:08:43.400
then if if let me define two variables in
my playbook.

00:08:43.500
00:08:46.900
Let's say I am defining some x 56.

00:08:48.000
00:08:50.700
some 78 Right.

00:08:50.700
00:08:57.700
So, what I am doing here, is suppose
if x less than y,

00:08:57.700
00:09:01.100
then only I want to copy some content
to my manager node.

00:09:02.700
00:09:13.700
So, this is a true forgiven condition,
that's it.

00:09:14.100
00:09:19.000
Close your if condition, and if that's it,
let me save it

00:09:19.600
00:09:20.700
and run the Playbook.

00:09:24.400
00:09:26.200
I'm running once it is done.

00:09:26.500
00:09:29.700
See what we have written in your
template source file be clear.

00:09:29.700
00:09:32.700
We are defining variables in our
Playbook,

00:09:32.700
00:09:35.600
or somewhere in your inventory, or
while going forward,

00:09:35.600
00:09:36.700
will discuss about roles in roles.

00:09:36.700
00:09:38.600
We can define variables in different
places,

00:09:39.900
00:09:42.700
Right, but, whenever if you are using
template module,

00:09:42.700
00:09:45.500
in the source file only, have to write
your logic,
00:09:45.500
00:09:49.300
in terms of your variables, or if
condition, or for Loop, or if-else

00:09:49.300
00:09:53.800
if whatever it may be now X and Y
values, will be taken from your playbook.

00:09:54.300
00:09:57.800
56 and 78/56 less than 78.

00:09:57.800
00:09:58.000
Yes.

00:09:58.000
00:09:58.700
That is true.

00:09:59.000
00:10:00.800
So this is a true for given condition.

00:10:00.800
00:10:04.600
This information will be copied to your
manager node,

00:10:04.600
00:10:09.400
in the file of done, with that some
template .txt file,

00:10:09.400
00:10:10.900
because that is true now.

00:10:10.900
00:10:13.600
Let me open your file,

00:10:15.200
00:10:23.900
See that, now suppose if I Modify this
value, 560,

00:10:23.900
00:10:25.500
now your values has been modified in
your playbook.

00:10:25.800
00:10:29.500
But logic is this no, but now, this logic
fails.

00:10:29.800
00:10:32.400
That's why, this content won't be
copied.

00:10:32.600
00:10:35.400
Instead of that, you're going to get an
empty file in your manage node.

00:10:35.500
00:10:38.300
Because if this condition is true, then
only this line,
00:10:38.300
00:10:39.900
will be copied to your manager node.

00:10:40.200
00:10:41.900
We don't have any lines other than
this line,

00:10:41.900
00:10:43.300
That's why this condition is false.

00:10:43.300
00:10:44.700
Then, it is going to skip this line.

00:10:45.600
00:10:47.900
Let me run this Playbook and see the
result, so that you can understand.

00:10:47.900
00:10:54.500
So, guys if you are good with some if
condition or,

00:10:54.500
00:10:58.700
if-else if condition or ifelse, if-else, if-
else condition

00:10:58.700
00:11:02.300
in your other languages same
concept, the only thing is,

00:11:02.300
00:11:04.900
we are using that in the source file,

00:11:04.900
00:11:07.700
whenever if you are using template
module, be clear on that.

00:11:07.900
00:11:14.800
Done, let me open you are node, and
see the result,

00:11:14.800
00:11:16.700
empty file because logic is I mean
logic is correct.

00:11:17.100
00:11:18.200
The condition is false.

00:11:18.200
00:11:21.000
That's why you are not replacing any
value here any data here.

00:11:21.000
00:11:21.800
That's it.

00:11:23.800
00:11:29.200
The same way you can use simply if-
else, if-else condition.
00:11:29.400
00:11:31.400
That's it be clear.

00:11:32.800
00:11:36.500
Curly brace percentile, if condition, so
guys,

00:11:36.500
00:11:39.600
you can make here, either here, or
here the condition for that.

00:11:39.600
00:11:43.100
We already discussed at very first
some operators.

00:11:43.100
00:11:46.000
So, all those operators you can use in
your if condition,

00:11:46.000
00:11:47.000
or if-else condition.

00:11:47.200
00:11:47.600
That's it.

00:11:48.400
00:11:53.900
So now, let me write with if-else a
simple logic,

00:11:53.900
00:11:57.300
So what I am doing is, if x less than y,

00:11:57.300
00:11:59.800
I am writing this is a true for given
condition,

00:12:00.200
00:12:01.600
else, I can also write some else.

00:12:03.900
00:12:12.600
So, when else will execute, means the
condition is false.

00:12:14.000
00:12:17.000
So, based on your X and Y values, if
this condition is false,

00:12:17.000
00:12:20.600
then this will execute, that's it here.

00:12:20.600
00:12:22.300
Also, you can write some variables C.

00:12:22.300
00:12:25.700
Let me include just for your
understanding,

00:12:25.700
00:12:26.500
I am writing some variable here.
00:12:28.500
00:12:32.500
Guys, this is not your required
example,

00:12:32.500
00:12:38.200
Just, I am placing how to use
variables, also you can use variables here,

00:12:38.200
00:12:40.600
in this line, or in this line, but don't use
in this line,

00:12:40.600
00:12:44.700
because there is if condition,

00:12:44.700
00:12:48.300
so, wherever if you want to place data
in that place,

00:12:48.300
00:12:48.800
only you should have a variables.
That's it.

00:12:49.500
00:12:50.900
Let me save it, and run it.

00:12:55.000
00:12:58.100
Anyway, you will get a clear idea,

00:12:58.300
00:12:59.600
whenever we will write real-time
examples.

00:13:00.400
00:13:04.300
So, now we are giving just concepts
with your template module.

00:13:05.400
00:13:05.900
That's it.

00:13:07.400
00:13:10.800
So, once it is done, we will go to your
manager node,

00:13:10.800
00:13:14.500
and will open, see the content in your
manage node.

00:13:14.700
00:13:18.200
This condition is false, and you are
replacing

00:13:18.200
00:13:19.300
the data with your variable data.

00:13:19.600
00:13:24.600
That's it, the same way you have if-
else if-else condition.
00:13:24.600
00:13:28.200
Nothing in the first condition is true,

00:13:28.200
00:13:30.000
some data whatever the data you
want, right.

00:13:30.000
00:13:32.200
Else, if, if this condition is true,
whatever the data you want to write,

00:13:32.200
00:13:34.800
likewise, you can include any number
if-else,

00:13:34.800
00:13:38.400
if conditions, and finally if all the
conditions are false,

00:13:38.400
00:13:41.200
then what is the data you want to write
then,

00:13:41.200
00:13:42.100
that data you have to write under else.

00:13:42.200
00:13:42.500
That's it.

00:13:43.400
00:13:47.200
Be clear with syntaxes, curly brace,
percentile,

00:13:47.200
00:13:47.900
percentile curly brace.

00:13:48.600
00:13:51.000
So this is about simply conditional
statements.

00:13:51.000
00:13:57.000
Now, we have a loop, that is suppose
for loop again,

00:13:57.000
00:14:01.200
syntax is like your if condition ,curly
brace percentile,

00:14:01.300
00:14:02.500
then some for condition.

00:14:02.500
00:14:03.400
I'm in for Loop.

00:14:04.400
00:14:07.600
Percentile curly brace, then whatever
the logic you want to
00:14:07.600
00:14:08.600
repeat that logic.

00:14:08.600
00:14:11.400
You have to write in the next line, then
close.

00:14:11.800
00:14:15.200
So, between these two, I mean curly
braces,

00:14:15.200
00:14:16.200
you can write any number of lines
here.

00:14:16.600
00:14:20.200
See what I am doing is in my
playbook.

00:14:20.700
00:14:22.000
Where is your playbook?

00:14:24.100
00:14:25.700
Suppose I am defining a list.

00:14:26.400
00:14:28.400
Let's LZ or anything.

00:14:28.400
00:14:33.000
You can write, write say now.

00:14:34.200
00:14:35.500
I am writing some logic.

00:14:35.800
00:14:38.700
I'm going to keep that data,

00:14:38.700
00:14:39.200
as days that will work along with that.

00:14:39.500
00:14:44.600
This Loop also, will work for each in Z
guys be clear,

00:14:44.600
00:14:48.100
that is there in my playbook, that is
very important,

00:14:48.100
00:14:49.000
or somewhere in your variable section.

00:14:49.000
00:14:49.900
You should be there.

00:14:50.500
00:14:51.700
Otherwise, it won't work.

00:14:52.800
00:14:55.000
Right, see now.
00:14:55.000
00:14:57.800
I'm writing, I can write some static
data.

00:14:58.300
00:15:05.300
This is a what is that suppose each
then?

00:15:09.800
00:15:14.700
The above, I can also include one
more variable,

00:15:14.700
00:15:15.600
or I mean, you are which that is.

00:15:15.600
00:15:16.800
Let me write one more variable here.

00:15:16.800
00:15:20.500
Anyway, we have already one
variable, called HTTP Port then

00:15:20.500
00:15:25.300
let me write one more static line, this
is without variables.

00:15:26.300
00:15:30.200
So, guys what will happen because of
this,

00:15:30.200
00:15:32.700
for Loop means and for one forget
about that.

00:15:35.400
00:15:37.000
See, we have some values in G.

00:15:37.000
00:15:39.800
It will take one by one, and this data,

00:15:39.800
00:15:40.800
will be repeat for each and every
value.

00:15:41.100
00:15:44.300
So, while repeating first time each
value,

00:15:44.300
00:15:45.600
is the first value in your list three.

00:15:46.900
00:15:51.200
This is a three then your Port, then
this data,

00:15:51.200
00:15:55.800
then for next time. This is a for then
likewise now, let me run this,
00:15:55.800
00:15:57.400
and see the results ,so that you can
understand.

00:16:00.700
00:16:01.500
So it is running.

00:16:02.400
00:16:03.500
Just give me a minute.

00:16:10.400
00:16:11.300
Anyway, never real time.

00:16:11.300
00:16:12.900
It won't take this much latency.

00:16:16.100
00:16:17.800
Done now.

00:16:17.800
00:16:22.000
Let me open your content in your
remote server,

00:16:22.000
00:16:24.500
or manage node. See that this seas.

00:16:26.500
00:16:30.100
See, first thing this information,
because of your if condition,

00:16:30.700
00:16:33.300
and you're having some spaces,

00:16:33.300
00:16:33.900
in your template source file, be clear.

00:16:33.900
00:16:35.100
That is also important.

00:16:36.700
00:16:39.500
This many spaces are there, after that
you're having a for Loop?

00:16:39.500
00:16:44.400
So, this is a three anyway, this port
number is fixed.

00:16:44.400
00:16:48.600
Right, if you open your this, is fixed
one,

00:16:48.600
00:16:51.500
but based on the number of values in
jet, each iteration will take new value from 0,

00:16:51.500
00:16:56.100
and that value will be replaced in
place of each variable.
00:16:56.100
00:16:56.600
That's it.

00:16:57.800
00:17:00.100
So, how many values you are having
in jet that made a number

00:17:00.100
00:17:02.000
of times this data will be repeating.

00:17:02.400
00:17:02.900
That's it.

00:17:03.600
00:17:07.700
So guys, this is the simple concept of
about your template module.

00:17:07.700
00:17:11.598
I mean, in terms of variables
conditions,

00:17:11.598
00:17:14.000
and then loops, okay.

00:17:14.400
00:17:14.900
Okay guys.

00:17:14.900
00:17:16.200
Thank you for watching this video.
Transcript
00:00:00.000
00:00:07.000
[no audio] Here our concept is
Introduction to AWS Provisioning Using Ansible

00:00:07.800
00:00:11.400
We already know that ansible is an
open-source software provisioning,

00:00:11.400
00:00:14.300
configuration management and
application-deployment tool.

00:00:15.000
00:00:18.300
We already use ansible for
configuration management and

00:00:18.300
00:00:22.200
application deployment with simple
examples. We are now discussing

00:00:22.200
00:00:24.900
AWS provisioning using ansible.

00:00:25.700
00:00:29.300
So, you can use ansible for any cloud,
not only with your AWS.
00:00:29.600
00:00:31.400
But here we are working with AWS.

00:00:32.400
00:00:35.300
To work with your AWS using ansible,

00:00:35.700
00:00:39.700
there are predefined modules
available within ansible.

00:00:40.000
00:00:42.800
So simply by using all those
predefined modules,

00:00:42.800
00:00:48.600
we can work with your AWS. So we
can provision or manage AWS

00:00:48.600
00:00:50.800
Cloud using all those modules.

00:00:51.200
00:00:52.700
So already predefined modules are
there.

00:00:53.000
00:00:55.400
You just have to use that module and
work with your

00:00:55.400
00:00:59.900
AWS. So what type of provision can
you do with your ansible?

00:00:59.900
00:01:02.700
Let me give some simple examples.

00:01:03.500
00:01:06.000
So you can launch your EC2 instance
or instances,

00:01:06.000
00:01:07.500
you can create some security groups,

00:01:07.500
00:01:11.200
you can create some key plays, you
can create some S3

00:01:11.200
00:01:14.300
buckets or RDS. Not only this
provision,

00:01:14.800
00:01:20.300
you can also use ansible to generate
some CSV reports about

00:01:20.300
00:01:21.400
your AWS.
00:01:23.200
00:01:28.700
Now, before going to use your ansible
for AWS provisioning,

00:01:28.700
00:01:30.600
you need to do some setup.

00:01:31.200
00:01:35.500
So simply setup environment for
ansible to work with AWS

00:01:35.500
00:01:37.400
cloud. Right?

00:01:37.500
00:01:39.000
Let me do the steps.

00:01:39.300
00:01:42.800
So, the very first step is you need to
install your ansible

00:01:42.800
00:01:48.700
or ansible controller somewhere on
your VM or any AWS VM systems.

00:01:48.800
00:01:53.700
I will show you the remaining steps by
implementing simple

00:01:53.700
00:01:58.100
playbook. The playbook is just to
launch EC2 instance.

00:01:58.600
00:01:59.600
So we have some steps.

00:01:59.700
00:02:02.000
Let me explain them with the help of
simple playbook.

00:02:02.500
00:02:08.000
So first thing let me open my send
ways.

00:02:08.199
00:02:10.000
So here I have my ansible.

00:02:10.300
00:02:12.900
We know that already we set up our
ansible here.

00:02:17.000
00:02:17.500
Right.

00:02:18.100
00:02:22.000
So here, let me create a new directory
for to work with AWS
00:02:22.000
00:02:26.600
cloud. So let me enter into that.

00:02:29.000
00:02:33.800
Fine now, let me open my ATM reiter
now here.

00:02:33.800
00:02:36.900
I am going to create a simple
Playbook.

00:02:38.500
00:02:44.700
to launch or to provision ec2 instance
so simply Launch you

00:02:44.700
00:02:45.800
see to Dot.

00:02:46.200
00:02:46.800
Yml.

00:02:49.000
00:02:51.600
Let me start with your three hyphens
then.

00:02:52.800
00:03:01.300
- name some people play to launch
ec2 instance fine.

00:03:02.400
00:03:07.600
So we know that for each and every
Playbook we need Target

00:03:07.600
00:03:12.400
section. So suppose here what Target
I can provide so we

00:03:12.400
00:03:14.500
are not going to work with any server.

00:03:14.500
00:03:16.100
We are going to work with cloud.

00:03:17.400
00:03:23.000
Right, but ansible Playbook or play
needs Target, but here

00:03:23.000
00:03:24.000
we don't have Target.

00:03:24.400
00:03:27.800
So that's why here just simply take
Target as localhost.

00:03:28.500
00:03:29.600
You can take any host.
00:03:29.900
00:03:32.500
But anyway, you are not going to work
with that host only

00:03:32.500
00:03:35.500
ansible Playbook or play needs the
target.

00:03:36.000
00:03:39.500
That's why we are providing that then
so already we are running

00:03:39.500
00:03:42.800
our ansible controller on localhost only
then we don't want

00:03:42.800
00:03:43.900
any SSH connectivity.

00:03:43.900
00:03:44.800
Simply, right?

00:03:45.600
00:03:48.000
Connection as local that's it.

00:03:48.700
00:03:50.600
So we are not going to work with Local
Host.

00:03:50.600
00:03:52.200
We are working with AWS Cloud.

00:03:52.200
00:03:55.000
That's why I don't want to collect any
facts.

00:03:55.000
00:03:56.800
So simply gather facts false.

00:03:57.000
00:03:57.500
That's it.

00:03:59.200
00:04:01.400
Now, let me write it a Tas section.

00:04:02.400
00:04:05.200
So the very first task suppose
whatever the model you want.

00:04:05.200
00:04:06.800
We will write that first thing.

00:04:06.800
00:04:10.500
Actually, we are writing this Playbook
to launch ec2 instance.

00:04:10.900
00:04:15.200
So I am writing simple task to Launch.
00:04:16.500
00:04:24.200
ec2 instance with default values right?

00:04:24.200
00:04:27.300
Let me save it then here.

00:04:27.300
00:04:28.800
You need to select your module.

00:04:29.600
00:04:31.000
So based on your task.

00:04:31.000
00:04:35.100
You have to select the module for your
AWS cloud from ansible.

00:04:35.600
00:04:37.200
Let me open my browser.

00:04:40.900
00:04:52.200
simply search with AWS modules and
simple just open Cloud

00:04:52.200
00:04:54.800
modules. So there are different
clouds, right?

00:04:54.900
00:04:57.600
So for each and every cloud there are
different modules from

00:04:57.600
00:04:58.300
your ansible.

00:04:58.800
00:05:01.600
So we need AWS Amazon, right?

00:05:01.600
00:05:06.100
So this is our required part from this
you can take any one

00:05:06.100
00:05:08.100
of the module based on your
requirement.

00:05:08.300
00:05:14.100
So as of now, my requirement is AWS
ec2 instance part simply

00:05:14.100
00:05:20.500
there is a easy to you can select either
ec2 or Ec2 instance

00:05:21.000
00:05:22.400
right? So don't worry.

00:05:22.400
00:05:23.200
What is the difference?
00:05:23.500
00:05:27.200
I mean the difference between ec2
and ec2 instance for time

00:05:27.200
00:05:27.600
being first.

00:05:27.600
00:05:31.100
Let me take easy to because we need
some steps to set up

00:05:31.100
00:05:34.100
our environment right fine.

00:05:35.300
00:05:40.800
See I selected easy to for easy to If
You observe here you

00:05:40.800
00:05:46.400
need python greater than 2.6 Bhutto
module now let go back.

00:05:48.200
00:05:52.300
And see here you see two instance
now if I select that it

00:05:52.300
00:05:56.500
needs both o both reboot oak or and
python greater than 2.6

00:05:56.900
00:06:00.300
right. Anyway, we are using python.

00:06:01.600
00:06:05.700
I think 2.7 right put out 7.5.

00:06:05.800
00:06:06.300
That's fine.

00:06:08.100
00:06:15.500
so first Let me open your any module
either ec2 or ec2 instance.

00:06:16.700
00:06:19.900
So this is the module to launch your
ec2 instance.

00:06:20.700
00:06:25.700
Okay, we'll discuss about
requirements first go to a down

00:06:25.700
00:06:30.300
somewhere. You will see some simple
playbooks or to understand

00:06:30.300
00:06:31.700
the usage of ec2 module.
00:06:32.000
00:06:36.600
So easy to write simply I am selecting
that module then.

00:06:40.000
00:06:41.500
Let me open my playbook.

00:06:41.500
00:06:43.300
Simply I'm writing is C2.

00:06:44.600
00:06:46.000
Now under is E2.

00:06:47.100
00:06:48.700
I am not using any key name.

00:06:48.800
00:06:50.300
So I don't want to assign any key.

00:06:50.800
00:06:52.100
Anyway, I don't want to connect with
that.

00:06:52.100
00:06:52.400
Simply.

00:06:52.400
00:06:54.700
I want to create some instance.

00:06:54.700
00:06:58.200
Let me create an instance type with
two dot micro.

00:07:03.400
00:07:06.500
Then I need some meid right?

00:07:06.700
00:07:08.500
That means select meid.

00:07:10.400
00:07:11.100
From here.

00:07:11.600
00:07:16.400
So I want to take suppose this Ami as
the ID to create my

00:07:16.900
00:07:20.600
ec2 instance to launch my ec2
instance to provision my ec2

00:07:20.600
00:07:23.300
instance so image.

00:07:23.700
00:07:26.300
Let me write that image.

00:07:28.200
00:07:28.700
That's it.
00:07:30.700
00:07:35.400
then anyway, I want to go with the
default values for remaining

00:07:35.400
00:07:36.500
values. Now.

00:07:36.500
00:07:38.400
Let me save it now.

00:07:38.400
00:07:40.100
Let me run this play book first.

00:07:40.300
00:07:44.400
See I am running and simple Playbook
our Playbook name is

00:07:44.400
00:07:45.400
launch is e 2 DOT.

00:07:45.400
00:07:50.100
Yml first observe the output it will give
some error see

00:07:50.100
00:07:54.500
this is giving both are required see for
some modules of

00:07:54.500
00:07:57.400
your ansible AWS cloud.

00:07:58.600
00:08:01.000
It needs Bhutto for some modules.

00:08:01.300
00:08:04.600
It needs both o both O3 and boat dock
or that's the reason

00:08:05.000
00:08:06.400
I am going to install.

00:08:08.500
00:08:12.500
Moto moto 3 but you know how to
install boat dock or it will

00:08:12.500
00:08:15.000
automatically install once if we install
boat or boat or

00:08:15.000
00:08:19.400
three now if I run this see I'm not the
root user right?

00:08:19.400
00:08:20.700
I am the ants had been user.

00:08:21.400
00:08:25.000
So if you use this it is going to install in
the root level.
00:08:25.100
00:08:28.500
I mean for all users, but I don't want to
install this boat

00:08:28.500
00:08:30.700
to and boo two three four all users.

00:08:30.700
00:08:31.000
Simply.

00:08:31.000
00:08:35.500
I want to install this two modules for
only this current

00:08:35.500
00:08:39.200
user simply use option called - hyphen
U, So if you don't

00:08:39.200
00:08:41.700
provide iPhone iPhone user for see
the result.

00:08:43.700
00:08:46.799
You will get an error called permission
error, right?

00:08:47.500
00:08:51.500
So that's the reason simply install only
for this user.

00:08:52.400
00:08:52.900
That's it.

00:08:57.400
00:08:57.800
Fine.

00:08:58.500
00:09:02.100
So just now we installed Bordeaux
Bhutto 3 and boto core.

00:09:03.300
00:09:06.300
Right, and this is the Playbook now, let
me rerun your playbook

00:09:06.300
00:09:07.900
once again and see the result.

00:09:09.100
00:09:10.500
So I'm running my PlayBook.

00:09:11.500
00:09:15.600
So it is trying to launch but it is asking
you need some

00:09:15.600
00:09:16.700
region now.
00:09:16.700
00:09:23.200
Let me mention this region in your
Suppose I want to install

00:09:23.200
00:09:26.800
sorry. I won't launch under Us East
one region.

00:09:27.500
00:09:28.200
That's fine.

00:09:35.400
00:09:41.500
Now see that what it is saying it is
saying about No handle

00:09:41.500
00:09:42.800
was ready to authenticate.

00:09:44.100
00:09:47.300
Actually whenever if you run your
playbook, it has to launch

00:09:47.300
00:09:51.600
instance in your AWS Cloud, but what
is your address Cloud?

00:09:52.400
00:09:56.400
So what account in which account you
want to create your

00:09:56.700
00:10:00.300
ec2 instance or you want to launch
your ec2 instance?

00:10:00.800
00:10:04.700
That means you need to provide the
credentials of your AWS

00:10:04.700
00:10:07.900
account in your playbook right now.

00:10:07.900
00:10:10.800
Let me open my AWS account first.

00:10:12.000
00:10:16.400
See if I don't provide the credentials,
right it cannot communicate

00:10:16.400
00:10:17.800
with Butler AWS account.

00:10:18.300
00:10:20.600
See if you click on your name.

00:10:22.800
00:10:24.400
My security credentials are there.

00:10:25.600
00:10:27.600
So I am taking in the root level.
00:10:27.700
00:10:30.700
You can also create some I am user
and you can also provide

00:10:30.700
00:10:31.700
that credentials.

00:10:32.400
00:10:37.800
So access keys right just simply
create new access key.

00:10:39.600
00:10:41.300
So access key ID.

00:10:41.800
00:10:43.600
Let me take this access key ID.

00:10:45.800
00:10:51.300
So I'm opening my playbook AWS
access key.

00:10:53.300
00:10:55.100
The same way you need to provide.

00:10:56.800
00:11:00.100
secret key as well Let me take that.

00:11:01.900
00:11:04.200
See whenever if you want to log in
through browser, you're

00:11:04.200
00:11:08.400
providing your ID and password the
same way whenever programmatically

00:11:08.400
00:11:10.400
if you want to communicate with your
AWS.

00:11:11.800
00:11:13.600
Right, you need these credentials?

00:11:15.300
00:11:19.700
That's it now save it and go and run
your playbook now.

00:11:22.600
00:11:24.700
So it is launching your ec2 instance.

00:11:25.900
00:11:27.600
Right done.

00:11:27.900
00:11:31.300
Just go and open your account.

00:11:36.600
00:11:47.300
services ec2 So it is launching your
ec2 instance.
00:11:50.300
00:11:51.900
Right, that's fine.

00:11:53.300
00:11:55.400
And one more thing see here.

00:11:55.400
00:11:58.400
I provided my credentials in the
Playbook that is not a good

00:11:58.400
00:12:02.500
practice then instead of providing your
credentials in the

00:12:02.500
00:12:06.000
Playbook. You can also store your
credentials somewhere in

00:12:06.000
00:12:07.800
a file called credentials files.

00:12:08.700
00:12:14.600
So to store your credentials in a
different file, you can

00:12:14.700
00:12:16.400
uh proceed with the different ways.

00:12:16.500
00:12:24.500
So here I am going to proceed first let
me install this pip

00:12:24.500
00:12:26.500
install AWS CLI.

00:12:27.100
00:12:31.100
So if you install this AWS CLI using
AWS CLI, you can configure

00:12:31.100
00:12:35.700
your credentials on your host instead
of providing your credentials

00:12:35.700
00:12:36.500
in the Playbook.

00:12:37.200
00:12:39.700
You can provide you can store your
credentials somewhere.

00:12:40.800
00:12:45.100
Let me show you that so first I install
AWS CLI, then simply

00:12:45.100
00:12:50.600
run AWS configure, then it is asking
access key.
00:12:51.000
00:12:53.000
Let me take my access key from here.

00:12:59.500
00:13:00.800
Then secret access key.

00:13:07.500
00:13:08.000
That's it.

00:13:08.400
00:13:11.200
So you can also provide default region
and output format

00:13:11.200
00:13:13.000
and even as of now, I'm not taking
them.

00:13:13.300
00:13:13.800
That's it.

00:13:14.500
00:13:18.100
Now what we are doing is any way of
providing keys in your

00:13:18.100
00:13:20.000
play book itself is not a good practice.

00:13:20.000
00:13:21.700
That's why I'm removing from here.

00:13:22.800
00:13:26.200
And I configured on my Local Host
where this credential store

00:13:27.300
00:13:32.700
see under user home dot a reverse
directory will be created

00:13:32.700
00:13:37.000
once if you run AWS configure and if
you open that I mean

00:13:37.000
00:13:40.500
if you enter into that and there are two
files one is config

00:13:40.500
00:13:42.000
and one more is credentials.

00:13:43.300
00:13:46.400
So just observe your credentials and
confit.

00:13:46.800
00:13:50.100
So in credentials you're having your
keys information and
00:13:50.100
00:13:54.700
in config, actually, you will have your
default region and

00:13:54.700
00:13:55.900
default output format.

00:13:56.500
00:13:58.300
Anyway, here we did not provide
anything.

00:13:58.300
00:14:00.100
That's why there is no information
here.

00:14:01.300
00:14:01.700
That's it.

00:14:02.000
00:14:05.200
Now whenever if you run your
playbook automatically or ansible

00:14:05.200
00:14:09.800
will look into this file for credentials
right now.

00:14:09.800
00:14:12.800
We removed our credentials from our
file now.

00:14:12.800
00:14:15.600
Let me rerun our Playbook ones.

00:14:16.700
00:14:18.200
So here guys be clear.

00:14:18.300
00:14:22.900
I am re running by removing our
credentials from our Playbook.

00:14:23.000
00:14:28.300
But where you stored your credentials
in your credentials

00:14:28.300
00:14:33.800
file under user home under dot AWS
directory, right?

00:14:33.800
00:14:37.000
So to configure that we use AWS
configure command.

00:14:37.500
00:14:40.100
So if you want to run a SS configure
command, you need to

00:14:40.100
00:14:41.600
install AWS CLI.
00:14:42.500
00:14:44.600
That's it right fine.

00:14:44.700
00:14:46.200
Now, let me rerun you are.

00:14:46.500
00:14:52.600
book So as of now you have only one
running instance now,

00:14:52.600
00:14:53.600
let me run this.

00:14:54.800
00:14:57.000
And go to here and refresh it.

00:14:59.200
00:15:01.100
Yeah now it is launching new instance.

00:15:02.200
00:15:04.600
right That's it.

00:15:05.000
00:15:11.600
So simply we stored our credentials
somewhere see even let

00:15:11.600
00:15:17.800
me open this file aspect.

00:15:18.700
00:15:22.400
So here directly, we provided our
credentials and if you

00:15:22.400
00:15:24.300
open that file, you can see your
credentials.

00:15:24.500
00:15:29.600
So you can also encrypt this trenches
by using ansible Vault

00:15:29.600
00:15:32.100
concept will see that in later videos.

00:15:32.400
00:15:35.500
So how to encrypt and decrypt your
credentials.

00:15:36.000
00:15:40.000
Okay, so guys, this is the simple
setup.

00:15:41.700
00:15:45.200
To work with your AWS Cloud using
ansible.

00:15:45.900
00:15:49.800
So first thing we need ansible
controller then second thing
00:15:50.400
00:15:53.100
we need to install different libraries
called boot one Bhutto

00:15:53.100
00:15:57.800
3 and also we need to install AWS
CLI, then these are the

00:15:57.800
00:16:00.200
steps if you want to install the system
level.

00:16:00.400
00:16:04.300
Otherwise, simply use peep install
boot or bootie - iPhone

00:16:04.300
00:16:08.900
user pip install AWS CLI - iPhone
user, right?

00:16:08.900
00:16:11.300
So after that simply run a double is
configured.

00:16:11.500
00:16:14.600
So simply configure your credentials of
AWS account.

00:16:15.200
00:16:15.700
That's it.

00:16:16.500
00:16:21.400
Okay in later videos, we will see in
detail about AWS provisioning

00:16:21.500
00:16:23.500
using ansible right?

00:16:23.500
00:16:26.700
Not only provisioning remember that
you can also generate

00:16:26.700
00:16:31.400
some CSV reports very easily using
ansible guys one more

00:16:31.400
00:16:32.900
Point C.

00:16:32.900
00:16:37.900
So same task whatever we did now,
so that is launch ec2 instance

00:16:38.000
00:16:39.000
that we can also.
00:16:41.900
00:16:46.800
Perform using python bow to three
instead of using ansible

00:16:47.000
00:16:49.200
you can use Python code and bowed
to three module.

00:16:50.600
00:16:54.600
But there you have to write a lengthy
code compared to that

00:16:54.600
00:16:56.000
part in ansible.

00:16:56.300
00:16:58.100
It is some less code.

00:16:59.800
00:17:01.000
What is the advantage?

00:17:02.500
00:17:02.900
Okay.

00:17:02.900
00:17:03.400
Okay guys.

00:17:03.400
00:17:04.598
Thank you for watching this video.
Transcript
00:00:00.000
00:00:04.500
Ec2 instances with required security
groups and tags using

00:00:04.500
00:00:08.010
ansible. So, I want to launch some
instances.

00:00:08.000
00:00:12.110
Maybe one instance are some ten or a
hundred or 20 something

00:00:12.100
00:00:15.410
whatever it maybe count is your wish
so if you want to launch

00:00:15.400
00:00:20.100
ec2 instances with required security
groups and tags, so

00:00:20.100
00:00:23.510
we know that Pax just to identify your
instances.

00:00:23.500
00:00:25.000
This instance is for suppose DB.
00:00:25.000
00:00:29.110
This instance is for suppose some
web server something like

00:00:29.100
00:00:34.100
right, so now here we are going to
launch ec2 instances right

00:00:34.100
00:00:37.800
using ansible and while launching you
can attach some security

00:00:37.800
00:00:40.010
group and even create some tags.

00:00:40.000
00:00:41.200
So how you can do this.

00:00:42.100
00:00:45.400
So, guys, we know that if you want to
work with ansible right

00:00:45.400
00:00:50.410
for each and every task you need to
use one module.

00:00:50.400
00:00:51.500
All right.

00:00:51.500
00:00:54.200
So, there are different models based
on your requirement.

00:00:54.200
00:00:57.110
You have to select your module, right?

00:00:57.100
00:01:00.100
So before going to start this playbook,
right?

00:01:00.100
00:01:02.510
Let me go with your official website.

00:01:02.500
00:01:03.800
Let me check.

00:01:03.800
00:01:05.300
Otherwise, let me search.

00:01:05.300
00:01:07.510
[no audio]

00:01:07.500
00:01:14.000
ansible modules for AWS Right just to
go with your Cloud

00:01:14.000
00:01:17.500
modules and see here.
00:01:17.500
00:01:19.700
You're having different modules.

00:01:19.700
00:01:21.800
All these modules are for your AWS
only.

00:01:21.800
00:01:24.010
[no audio]

00:01:24.000
00:01:27.000
So based on your requirement, you
have to select which module

00:01:27.000
00:01:31.010
you have to use suppose now, we are
going to create an instance.

00:01:31.000
00:01:34.200
So now you have to use Easy to
module right this module you

00:01:34.200
00:01:38.000
have to use for creation of your ec2 or
terminate or start

00:01:38.000
00:01:39.810
or stop right?

00:01:39.800
00:01:43.300
So, for all these things you have to
use this instance, right?

00:01:43.300
00:01:47.300
Just click on this and see that at the
bottom, right?

00:01:47.300
00:01:49.810
You have some simple.

00:01:49.800
00:01:55.500
example playbooks So now what I am
doing is just I am going

00:01:55.500
00:01:58.610
to connect with my server.

00:01:58.600
00:02:02.410
Local Host disease, so from here I
want to work with ansible

00:02:02.400
00:02:06.310
and how to work with your AWS using
ansible, right?

00:02:06.300
00:02:10.109
So, for that you need to do some
setup in our previous video.
00:02:10.100
00:02:16.200
We have been done that set up right if
you want to know about

00:02:16.200
00:02:20.000
how to set up your AWS your answer
will for your AWS just

00:02:20.000
00:02:23.109
see our previous video.

00:02:23.100
00:02:25.100
And also, I'm going to provide that link
on the below of this

00:02:25.100
00:02:27.209
video just go through that first.

00:02:27.200
00:02:29.900
Fine now in last class, right?

00:02:29.900
00:02:33.209
We have created.

00:02:33.200
00:02:36.700
AWS Cloud directory so here we done
some setup now.

00:02:36.700
00:02:39.609
I am going to use some setup here.

00:02:39.600
00:02:43.800
Now I am going to launch ec2
instance with security groups

00:02:43.800
00:02:44.910
and tags.

00:02:44.900
00:02:48.000
So, I'm going to give some name for
your playbook.

00:02:48.000
00:02:51.010
[no audio]

00:02:51.000
00:02:54.000
Create ec2 instance.

00:02:54.000
00:02:56.209
[no audio]

00:02:56.200
00:03:02.510
With security groups and tags not ml.

00:03:02.500
00:03:06.810
So, guys just assume that you are
going to create some.
00:03:06.800
00:03:12.100
instance or you're going to create
number of instances, whatever

00:03:12.100
00:03:15.500
it may be to launch to create your
instance.

00:03:15.500
00:03:17.310
You need easy to module.

00:03:17.300
00:03:18.200
Right and one more thing.

00:03:18.200
00:03:21.810
You have to remember that you are
going to work with your

00:03:21.800
00:03:23.510
AWS using ansible.

00:03:23.500
00:03:24.800
That's why I hear you.

00:03:24.800
00:03:26.810
No need of any notes.

00:03:26.800
00:03:30.100
You should have only ansible
controller on any one of your

00:03:30.100
00:03:33.609
local host from where you want to
work with your AWS.

00:03:33.600
00:03:35.600
So now this is our localhost from here.

00:03:35.600
00:03:40.300
I want to work with our AWS using a
Okay, let me start my

00:03:40.300
00:03:44.000
playbook. So just simply I'm going to
give a name for this

00:03:44.000
00:03:53.810
play. So, this play is used to create or
launch ec2 instance.

00:03:53.800
00:03:58.310
Instance are instances that is your
wish using.

00:03:58.300
00:04:11.700
security groups right and with required
tags. Fine, so guys
00:04:11.700
00:04:15.010
you need for each and every playbook
at least one host.

00:04:15.000
00:04:17.700
But actually, we no need of any host
but Playbook needs one

00:04:17.700
00:04:22.310
host. So that's why I am taking simply
localhost.

00:04:22.300
00:04:23.399
So, this is standard syntax.

00:04:23.399
00:04:25.810
You need to follow for your playbooks.

00:04:25.800
00:04:26.510
Right?

00:04:26.500
00:04:28.500
And I am going to take connection.

00:04:28.500
00:04:33.510
[no audio]

00:04:33.500
00:04:39.600
local right, and I don't want to get facts
gather facts.

00:04:39.600
00:04:43.710
[no audio]

00:04:43.700
00:04:45.600
Because I'm not working with our
server.

00:04:45.600
00:04:47.600
I'm I want to work with Edibles Cloud.

00:04:47.600
00:04:50.710
That's why I know need to get any
facts about your localhost.

00:04:50.700
00:04:54.600
So, if you make this as a false, you will
save some time, right?

00:04:54.600
00:04:56.400
Otherwise your playbook your ansible.

00:04:56.400
00:05:02.310
We'll look I will fetch facts about your
localhost right

00:05:02.300
00:05:05.400
fine. Now I am going to write tasks.
00:05:05.400
00:05:08.010
[no audio]

00:05:08.000
00:05:08.800
So, what is the task?

00:05:08.800
00:05:09.300
You need?

00:05:09.300
00:05:10.710
Actually, you need to write.

00:05:10.700
00:05:12.510
Let me do some name for that.

00:05:12.500
00:05:13.400
So, creating

00:05:15.600
00:05:20.510
ec2 instance, right?

00:05:20.500
00:05:23.700
So now just now we have seen in
official website to create

00:05:23.700
00:05:24.500
your ec2 instance.

00:05:24.500
00:05:26.200
You need easy to module, right?

00:05:26.200
00:05:28.200
Let me take it easy, too.

00:05:28.200
00:05:30.310
[no audio]

00:05:30.300
00:05:33.700
Nice to work with your AWS using
ansible you need to do some

00:05:33.700
00:05:36.810
setup right time in you have to provide
your credentials.

00:05:36.800
00:05:40.100
I already provided my credentials of
my AWS account right

00:05:40.100
00:05:44.110
that set up we have seen in previous
video fine.

00:05:44.100
00:05:48.600
Now, I want to create instance
suppose type.

00:05:48.600
00:05:51.000
I'm going to give type as suppose.
00:05:51.000
00:05:58.810
Let me take T 1 Dot Michael right, and
I need image ID, right

00:05:58.800
00:06:00.400
so, I am going to provide image ID.

00:06:00.400
00:06:04.700
So, I want to take the this image ID
from your AWS console

00:06:04.700
00:06:07.400
based on your region in which region
you are going to launch

00:06:07.400
00:06:08.000
for instance.

00:06:08.000
00:06:10.409
So, I'm going to create my instance in
us

00:06:10.400
00:06:11.510
East one.

00:06:11.500
00:06:13.409
So, I am going to get from here.

00:06:13.400
00:06:16.400
I mean ID, let me take image ID.

00:06:16.400
00:06:19.010
[no audio]

00:06:19.000
00:06:20.900
So, this is the image ID.

00:06:20.900
00:06:25.810
I'm going to take right just use this.

00:06:25.800
00:06:29.110
Fine just now we have given your
image ID.

00:06:29.100
00:06:32.710
Now how many instances you want to
launch with this t1 micro

00:06:32.700
00:06:35.409
using this amazing ID.

00:06:35.400
00:06:35.700
Right.

00:06:35.700
00:06:39.700
So, I want to launch as of now
suppose count one right by

00:06:39.700
00:06:41.310
default count one.
00:06:41.300
00:06:45.610
If you don't provide count value by
default is 1, only right?

00:06:45.600
00:06:50.200
See you should use some keys for
your ec2 instance while

00:06:50.200
00:06:51.310
launching right?

00:06:51.300
00:06:54.600
So, I am going to use key name as
already how this key in

00:06:54.600
00:06:59.010
my AWS use East one region.

00:06:59.000
00:07:01.100
So, if you don't have key what will
happen those things, we

00:07:01.100
00:07:02.300
will see while going forward.

00:07:03.300
00:07:06.500
ansible key Right.

00:07:06.600
00:07:09.200
So, after that just provide region in
which region you are

00:07:09.200
00:07:10.909
going to lunch.

00:07:10.900
00:07:12.200
So, guess based on this region.

00:07:12.200
00:07:16.409
You have to select your key name and
image ID, right?

00:07:16.400
00:07:18.900
So actually, I want to launch in us

00:07:18.900
00:07:21.010
East one.

00:07:21.000
00:07:21.610
Right.

00:07:21.600
00:07:26.400
So, my playbook has to wait up to
successfully up and running

00:07:26.400
00:07:28.200
of my launching is do instance.

00:07:28.200
00:07:29.700
That's why I'm going to provide wait.
00:07:29.700
00:07:35.610
Yes, just see by removing this weight
is option.

00:07:35.600
00:07:37.700
So that you can observe the difference
what will happen if

00:07:37.700
00:07:40.600
I place weight and what will happen if I
don't place weight

00:07:40.600
00:07:41.400
in my playbook?

00:07:41.400
00:07:43.610
[no audio]

00:07:43.600
00:07:47.610
Right fine now guys to provide you
security groups.

00:07:47.600
00:07:49.500
You can follow different ways
suppose.

00:07:49.500
00:07:53.600
If you know security group name you
have to take group as

00:07:53.600
00:07:55.400
the argument. Suppose

00:07:55.400
00:07:58.800
if you know your Security Group ID,
then you have to take

00:07:58.800
00:08:01.710
group ID.

00:08:01.700
00:08:02.409
Right.

00:08:02.400
00:08:05.600
So as of now first, let me take with the
name security group

00:08:05.600
00:08:09.900
name. So, I'm going to take my
security group name as let

00:08:09.900
00:08:11.300
me get my Security Group.

00:08:11.300
00:08:24.409
[no audio]
00:08:24.400
00:08:28.400
Security groups just go here and see
I'm having different

00:08:28.400
00:08:29.510
security groups.

00:08:29.500
00:08:32.409
So, I have one of the security group
named as do with python.

00:08:32.400
00:08:33.200
Let me take it.

00:08:33.200
00:08:38.308
[no audio]

00:08:38.299
00:08:39.510
Right fine.

00:08:39.500
00:08:44.299
I have given my security group as now
I need to create tags

00:08:44.299
00:08:46.010
for my instance.

00:08:46.000
00:08:46.909
Right?

00:08:46.900
00:08:49.610
So, guys as of now, we are not using
group ID.

00:08:49.600
00:08:52.610
We will see that in this video only.

00:08:52.600
00:08:56.809
No, I want to provide instance tags.

00:08:56.799
00:08:57.600
So, what is the tag?

00:08:57.600
00:08:59.310
You want to create?

00:08:59.300
00:09:04.000
So, guys suppose by default name tag
key is their name key,

00:09:04.000
00:09:06.800
right? So, with that I am going to
create suppose this is

00:09:06.800
00:09:07.600
test server.

00:09:07.600
00:09:09.410
[no audio]
00:09:09.400
00:09:14.600
right suppose I want to create one
more tag and I want to

00:09:14.600
00:09:18.600
take any Rodman suppose anyone
man suppose.

00:09:18.600
00:09:27.610
I am going to take this as Dev
environment Bye.

00:09:27.600
00:09:28.910
Yeah fine.

00:09:28.900
00:09:31.410
Otherwise, I will take some.

00:09:31.400
00:09:32.410
Yeah, no problem.

00:09:32.400
00:09:34.300
Any tags based on your requirement.

00:09:34.300
00:09:36.200
You have to take your tags, right?

00:09:36.200
00:09:38.210
So, I have taken these two tags.

00:09:38.200
00:09:40.400
This is not I mean you can provide any
number of tags.

00:09:40.400
00:09:43.810
That is your wish right fine.

00:09:43.800
00:09:44.510
That's it. Now.

00:09:44.500
00:09:47.300
This is a very simple Playbook to
create your ec2 instance

00:09:47.300
00:09:50.410
with your required Security Group and
required tags.

00:09:50.400
00:09:54.900
Right first, let me run this and see the
output so guys as

00:09:54.900
00:09:56.110
of now see here.

00:09:56.100
00:09:59.110
We don't sorry not here.

00:09:59.100
00:10:00.900
Let me go with my instances page.
00:10:00.900
00:10:03.510
[no audio]

00:10:03.500
00:10:07.800
So here we have two instances with
name key as Node 1 ansible

00:10:07.800
00:10:09.400
controller right now.

00:10:09.400
00:10:11.210
I am going to run this Playbook.

00:10:11.200
00:10:14.310
So before going to run this playbook.

00:10:14.300
00:10:17.010
So, I am going to check it.

00:10:17.000
00:10:20.100
So, I am going to check syntax check.

00:10:20.100
00:10:28.710
[no audio]

00:10:28.700
00:10:31.600
Okay, localhost spell mistake.

00:10:31.600
00:10:35.510
[no audio]

00:10:35.500
00:10:39.410
fine now check it.

00:10:39.400
00:10:40.610
Everything is fine. Now.

00:10:40.600
00:10:43.400
I am going to run my playbook, right?

00:10:43.400
00:10:45.800
See I used somewhere wait.

00:10:45.800
00:10:50.910
Yes, and because of that now your
playbook will wait.

00:10:50.900
00:10:55.500
up to successfully launching of your
ec2 instance

00:10:55.500
00:11:00.500
here somewhere again ins

00:11:00.500
00:11:01.800
Sorry hear me strike.

00:11:01.800
00:11:06.510
[no audio]
00:11:06.500
00:11:11.800
right. So guys syntax check is just the
first in text right

00:11:11.800
00:11:15.700
while running in case if you provided
any spell mistype that

00:11:15.700
00:11:20.010
you can get here while running see
now your playbook is waiting.

00:11:20.000
00:11:23.200
So meanwhile just go and see in your
console refresh it and

00:11:23.200
00:11:27.200
see the output see there is a new
instance is coming up once

00:11:27.200
00:11:30.710
it is successfully running then your
playbook will stop here.

00:11:30.700
00:11:33.610
So up to that you play your playbook
will wait.

00:11:33.600
00:11:37.510
So that is the meaning for wait s in
your playbook.

00:11:37.500
00:11:38.510
Right.

00:11:38.500
00:11:42.310
Okay, we'll wait have to that Let me
refresh it.

00:11:42.300
00:11:45.800
Yeah, now it is running and created
test right named as test.

00:11:45.800
00:11:46.900
You have one more key.

00:11:46.900
00:11:52.810
Just select it and see tags see
environment do have given.

00:11:52.800
00:11:56.110
So, these and observe that your
playbook has been stopped

00:11:56.100
00:11:58.710
because successfully your instance is
up and running.
00:11:58.700
00:12:04.010
So that is the useful by placing weight
as yes in your playbooks

00:12:04.000
00:12:07.300
fine. So, guys once again, I want to
show you more.

00:12:07.300
00:12:11.310
[no audio]

00:12:11.300
00:12:16.300
Playbook So guys here you need to
understand that you provided

00:12:16.300
00:12:19.410
a group as do with python.

00:12:19.400
00:12:23.010
Right, so instead of Group Security
Group name.

00:12:23.000
00:12:25.310
I want to use Security Group ID first.

00:12:25.300
00:12:27.300
Let me take my security group ID.

00:12:27.300
00:12:30.110
[no audio]

00:12:30.100
00:12:34.200
security groups Let me take this ID.

00:12:34.200
00:12:38.000
I will take suppose default. Default
Security Group are willing

00:12:38.000
00:12:39.000
to take same thing.

00:12:39.000
00:12:44.410
[no audio]

00:12:44.400
00:12:47.610
Let me copy this Security Group ID.

00:12:47.600
00:12:51.100
now if you want to provide group ID
inside of your playbook,

00:12:51.100
00:12:54.300
what you have to do is instead of your
group you need to

00:12:54.300
00:13:03.510
use now argument as or key as group
ID.
00:13:03.500
00:13:04.110
Right.

00:13:04.100
00:13:07.000
So, you guys previously we have used
do it python that is

00:13:07.000
00:13:08.410
a group name.

00:13:08.400
00:13:10.610
Now, I want to use group ID.

00:13:10.600
00:13:14.510
So, if you want to use group ID, what
you have to do is simply

00:13:14.500
00:13:19.410
group ID just to provide your ID name.

00:13:19.400
00:13:26.310
That's it say now let me change the
tag so that you can understand.

00:13:26.300
00:13:29.600
So, I am going to do tag name as
who's now here.

00:13:29.600
00:13:31.810
[no audio]

00:13:31.800
00:13:39.110
AWS instance That's it. Now.

00:13:39.100
00:13:40.700
Let me save this and run it.

00:13:40.700
00:13:44.410
[no audio]

00:13:44.400
00:13:46.410
I'm going to run it.

00:13:46.400
00:13:47.410
See once again.

00:13:47.400
00:13:51.800
It is done then only your playbook will
stop now just to

00:13:51.800
00:13:55.400
go and refresh your instances and see
that your new instance

00:13:55.400
00:13:56.710
is coming up.

00:13:56.700
00:13:59.600
So, once it is actually running right you
will get your tag
00:13:59.600
00:14:01.800
name as well because after way you
have mentioned your tag

00:14:01.800
00:14:04.510
name, right?

00:14:04.500
00:14:08.210
Okay, that's been done Let me refresh
it. Now.

00:14:08.200
00:14:11.310
It is running and tag name is AWS
instance.

00:14:11.300
00:14:17.310
And if you go with that security groups
do with python only

00:14:17.300
00:14:20.510
right? So, whether you're going to
provide security group

00:14:20.500
00:14:23.810
name or ID both will give same action.

00:14:23.800
00:14:26.900
But sometimes guys you need to
provide multiple security

00:14:26.900
00:14:32.010
groups for your ec2 instance then how
you can provide multiple.

00:14:32.000
00:14:35.910
security groups for your instances
Right.

00:14:35.900
00:14:37.100
Let me do one thing first.

00:14:37.100
00:14:41.400
I want to submit these to let me start it
all these three.

00:14:41.400
00:14:48.710
[no audio]

00:14:48.700
00:14:49.510
Fine.

00:14:49.500
00:14:55.110
Now what I am saying is so as of now,
you have given your

00:14:55.100
00:15:01.200
security group or ID as one security
group, right either
00:15:01.200
00:15:04.700
this one or this one, but I need to
provide suppose multiple

00:15:04.700
00:15:08.800
security groups or multiple Security
Group IDs while launching

00:15:08.800
00:15:10.410
my ec2 instance.

00:15:10.400
00:15:15.010
Now you can provide this in two ways
one is as a list I mean

00:15:15.000
00:15:18.700
python list you can do in this way see.
1 Security Group ID.

00:15:18.700
00:15:23.010
I'm providing the same thing you can
do with names for your

00:15:23.000
00:15:25.000
group option also, right?

00:15:25.000
00:15:28.010
Let me take one more.

00:15:28.000
00:15:32.600
Security Group ID Now I'm going to
suppose launch wizard

00:15:32.600
00:15:34.810
one Security Group.

00:15:34.800
00:15:40.010
Right just copy this ID come here and
paste it.

00:15:40.000
00:15:44.300
Right now, group ID not single
Security Group.

00:15:44.300
00:15:46.100
I want to provide supports multiple in
this way.

00:15:46.100
00:15:49.210
You can provide a comma then
second ID 3rd ID fourth ready?

00:15:49.200
00:15:51.700
We can provide any number of
Security Group IDs while launching

00:15:51.700
00:15:54.800
your ec2 instances in this way, right?
00:15:55.500
00:15:57.710
Okay. See now.

00:15:57.700
00:16:01.310
You don't have any ec2 instances
other than my

00:16:01.300
00:16:02.300
controller, right?

00:16:02.300
00:16:05.700
That is actually my Local Host just
observe that remaining

00:16:05.700
00:16:07.710
all are terminated.

00:16:07.700
00:16:10.300
Now, let me run our Playbook and see
the difference.

00:16:10.300
00:16:12.610
[no audio]

00:16:12.600
00:16:16.710
So why we are running this we are
running this by providing

00:16:16.700
00:16:20.310
Security Group IDs as multiple
Security Group IDs.

00:16:20.300
00:16:23.910
Yes, you can provide it creating easy
to instance. Yes.

00:16:23.900
00:16:27.810
It is waiting now refresh it new
instance is coming up.

00:16:27.800
00:16:29.610
Yes, this one.

00:16:29.600
00:16:32.300
Okay, once it is done, then we'll go
and refresh it and we'll

00:16:32.300
00:16:37.000
see we have to wait so up to so guys.

00:16:37.000
00:16:41.100
You can also give some wait time out,
but that is not a good

00:16:41.100
00:16:47.610
practice. Yeah done, just to refresh it.
00:16:47.600
00:16:51.000
Okay, AWS ec2 instance initializing
just to go and see your

00:16:51.000
00:16:52.710
security groups.

00:16:52.700
00:16:56.000
Now you're having lunch wizard one
and one more Security

00:16:56.000
00:17:00.200
Group Let Me Show You by expanding
this do with python because

00:17:00.200
00:17:04.310
these to be how provided IDs we
provided IDs. IDs not names

00:17:04.300
00:17:10.000
but by default, your AWS knows that
what group named realtor

00:17:10.000
00:17:14.210
with IDs, right or ID name related with
to your groups.

00:17:14.200
00:17:15.598
So that's it is giving group names.

00:17:15.598
00:17:18.010
So, we provided to security groups.

00:17:18.000
00:17:22.310
So that you are in your playbook is
creating the instance

00:17:22.300
00:17:26.300
with required security groups guys last
thing you have to

00:17:26.300
00:17:27.098
understand here.

00:17:27.098
00:17:29.059
[no audio]

00:17:29.049
00:17:34.410
You can also provide instead of
providing your group IDs.

00:17:34.400
00:17:39.010
I mean as the list of python can also
provide.

00:17:39.000
00:17:46.400
as a sequence of your Amal that is
suppose first one I can
00:17:46.400
00:17:48.609
write this.

00:17:48.599
00:17:51.000
Then second one I can write this.

00:17:51.000
00:17:54.710
[no audio]

00:17:54.700
00:17:55.610
That's it.

00:17:55.600
00:17:59.100
So just to understand I'm going to
change tags opposed here.

00:17:59.100
00:18:02.210
[no audio]

00:18:02.200
00:18:03.500
Prod name.

00:18:03.500
00:18:07.100
I'm going to take suppose this as let
me take something any

00:18:07.100
00:18:13.200
tag, so I want to take this as suppose
node new node, I am

00:18:13.200
00:18:18.900
taking Right.

00:18:18.900
00:18:19.800
Let me run this.

00:18:19.800
00:18:21.810
[no audio]

00:18:21.800
00:18:24.600
So now you don't have any new node
instance here, right?

00:18:24.600
00:18:27.600
Let me go with your instances before
running your playbook.

00:18:27.600
00:18:31.410
[no audio]

00:18:31.400
00:18:33.100
Let me turn my this instance as well.

00:18:33.100
00:18:35.210
[no audio]

00:18:35.200
00:18:37.800
Of course, you can also write your
playbook to terminate
00:18:37.800
00:18:39.710
your ec2 instance.

00:18:39.700
00:18:39.900
Right?

00:18:39.900
00:18:41.100
We'll see that in next video.

00:18:41.100
00:18:57.810
[no audio]

00:18:57.800
00:18:59.410
On second.

00:18:59.400
00:19:00.700
I want to terminate this.

00:19:00.700
00:19:04.910
[no audio]

00:19:04.900
00:19:07.600
Fine terminated right now.

00:19:07.600
00:19:09.300
Go here and run this playbook.

00:19:09.300
00:19:12.810
[no audio]

00:19:12.800
00:19:16.400
So why we are running this just we are
using different syntax

00:19:16.400
00:19:19.500
to provide multiple Security Group
instead of python list.

00:19:19.500
00:19:21.710
We are using a male sequence.

00:19:21.700
00:19:25.500
You can use both now see here
refresh it new instance is

00:19:25.500
00:19:26.510
coming up.

00:19:26.500
00:19:29.010
Yes, right.

00:19:29.000
00:19:30.500
Once this Playbook is done.

00:19:30.500
00:19:33.310
Your tags will create here.

00:19:33.300
00:19:37.110
Yes, done to refresh it and see that.
Right?
00:19:37.100
00:19:38.800
What is the new node?

00:19:38.800
00:19:40.000
This is the instant just now.

00:19:40.000
00:19:43.810
We launched using your playbook.

00:19:43.800
00:19:52.600
right Okay, so guys this is the way
how you can do your required

00:19:52.600
00:19:55.510
thing using this easy to module.

00:19:55.500
00:19:56.900
Thank you for watching this video.
Transcript
00:00:00.000
00:00:04.900
Ansible playbooks to start, stop and
terminate EC2 instances.

00:00:06.700
00:00:09.000
Right. Let me start. First,

00:00:09.000
00:00:10.500
let me connect with my local host.

00:00:10.600
00:00:13.900
So from here, we are going to work
with your AWS cloud.

00:00:16.300
00:00:18.300
Right and I'm here.

00:00:18.300
00:00:20.800
I'm having a user called ansadmin
user.

00:00:22.300
00:00:25.700
So, in our previous videos we have
seen that we created one

00:00:25.700
00:00:27.900
directory called AWS Cloud.
00:00:28.600
00:00:29.700
Let me enter into that.

00:00:32.100
00:00:38.400
So we've done, up to now, simple
playbooks. Now I

00:00:38.400
00:00:44.900
am going to create a third playbook
just to start, stop; first of all

00:00:44.900
00:00:46.900
I need to separate playbooks.

00:00:47.800
00:00:56.500
Okay, let's start EC2.yaml

00:00:57.100
00:00:58.600
I am going to write this playbook

00:01:00.100
00:01:08.100
simply, so this play is used to start an
EC2 instance.

00:01:12.100
00:01:17.000
Then I'm going to take host as
localhost.

00:01:17.500
00:01:19.900
So once again, I'm saying that there is
actually no need for any

00:01:19.900
00:01:22.800
host here because you're going to
work with your AWS Cloud.

00:01:23.000
00:01:26.200
But the thing is you need at least one
host information for

00:01:26.200
00:01:30.300
your ansible playbook and I am going
to write connection: local

00:01:32.400
00:01:39.200
and I don't want to get facts about my
host because

00:01:39.200
00:01:43.200
we are working with AWS Cloud not
about your host, right?

00:01:43.200
00:01:47.000
So gather_facts: false. Then I'm going
to write two tasks.

00:01:47.700
00:01:50.100
So my task is just to start.
00:01:51.300
00:01:57.000
But I'm going to write starting EC2
instance and you can

00:01:57.000
00:01:59.400
start every single instance on multiple
instances.

00:02:00.000
00:02:01.800
Let me do that first. Single instance,

00:02:01.800
00:02:04.800
I'm going to start, so you have to also
use it here.

00:02:04.800
00:02:06.600
Module called EC2

00:02:07.900
00:02:11.800
Right now for your module EC2
instance.

00:02:12.300
00:02:15.400
Sorry for your model is easy to what
instance you are going

00:02:15.400
00:02:19.400
to start right in need to provide the
information about your

00:02:19.500
00:02:22.600
instance that is in terms of instance
IDs.

00:02:24.400
00:02:27.100
So let me do that instance.

00:02:29.000
00:02:32.600
IDs, so guys here you can provide
multiple instance IDs or

00:02:32.600
00:02:33.600
single instance riding.

00:02:34.300
00:02:36.600
So if you want to provide single
instance ID directly can

00:02:36.600
00:02:37.300
provide here.

00:02:38.500
00:02:41.900
If you want to provide multiple
instance IDs, you can provide

00:02:41.900
00:02:46.000
as a list or as a sequence so already
in our previous video
00:02:46.000
00:02:49.200
while creating ec2 instance with
multiple.

00:02:50.400
00:02:52.300
Security Group IDs, right.

00:02:52.300
00:02:56.500
We have followed some rule providing
your security IDs to

00:02:56.500
00:02:59.500
provide your security IDs Security
Group IDs.

00:02:59.500
00:03:03.100
We have given as a list of python or
as a sequence of your

00:03:03.100
00:03:05.300
animal both the ways, you can follow
here also, you can do

00:03:05.300
00:03:08.400
that. So guys as of now suppose, I
don't have any instance

00:03:08.400
00:03:09.400
to provide my instance ID.

00:03:09.400
00:03:12.500
Let me do one thing from our previous
class.

00:03:13.400
00:03:18.300
I am l Playbook I want to create my
instance.

00:03:18.300
00:03:25.100
Let me create so second that is So
before going to that I

00:03:25.100
00:03:25.800
will do one thing.

00:03:26.900
00:03:30.700
Let me edit it and I want to create tag.

00:03:30.700
00:03:32.700
I want to change my tag name here.

00:03:33.800
00:03:36.700
So just simply I'm going to write.

00:03:38.200
00:03:44.500
start stop terminate instance.
00:03:44.500
00:03:47.700
So this instance actually I want to start
or stop or terminate

00:03:48.400
00:03:50.200
fine now, let me run this.

00:03:51.700
00:03:55.300
So guys, I am running this Playbook
just to create your instance,

00:03:55.800
00:03:59.900
right? Now, let me open my console.

00:04:06.900
00:04:08.200
New instance is coming up.

00:04:08.500
00:04:12.100
Right so we are using weight s that's
why it is waiting.

00:04:12.500
00:04:16.200
Once our instance is coming up and
running then your playbook

00:04:16.200
00:04:21.500
stop right now refresh it and see that
so this starts stopped

00:04:21.500
00:04:22.100
and made instance.

00:04:22.100
00:04:25.600
I want to start or stop or turn made
using our playbooks,

00:04:25.899
00:04:29.000
right? So I'm going to copy this
instance ID because I need

00:04:29.000
00:04:30.500
to do start or stop.

00:04:32.300
00:04:35.600
Yes, copy now go and open your third
play book.

00:04:36.700
00:04:38.300
And write your instance IDs.

00:04:39.200
00:04:40.800
So as of now single instance ID.

00:04:40.800
00:04:42.000
I'm providing in this way.

00:04:43.300
00:04:45.200
Right, then in which region it is there.
00:04:46.700
00:04:51.700
so Us East 1 Right then.

00:04:52.600
00:04:53.700
So what is your action?

00:04:54.200
00:04:56.600
Do you want to start or stop or restart?

00:04:57.600
00:04:58.000
Right.

00:04:58.000
00:05:00.100
So as of now first I am going to start.

00:05:01.400
00:05:06.600
Sorry State, you have to provide then
this state value as

00:05:06.600
00:05:14.100
running. So guys we know that ansible
is following idempotent

00:05:14.100
00:05:17.900
rule. That means if already your
required state is reached

00:05:17.900
00:05:20.100
then your playbook won't do any
changes.

00:05:21.800
00:05:22.200
Right.

00:05:22.200
00:05:25.300
So you want to start a war instance
only that instance is

00:05:25.300
00:05:29.700
running. That's why your your
playbook won't restart that

00:05:30.000
00:05:33.600
until unless if you specify restart
option, right?

00:05:33.600
00:05:37.200
So this is the best option suppose if
you if you are if you

00:05:37.200
00:05:41.300
stop or start some instance using
some python or reusing

00:05:41.300
00:05:45.200
some shell script and before going to
do that if it is already.
00:05:46.600
00:05:49.600
Stopped State and if you're trying to
stop with the help

00:05:49.600
00:05:52.900
of your shells give you will get some
exception but here

00:05:52.900
00:05:55.500
that exception you won't get so this is
one of the advantage

00:05:55.500
00:05:58.500
with your unspool playbooks
compared to your shell or python,

00:05:59.300
00:06:01.800
right? So nothing is there that
exception is already taken

00:06:01.800
00:06:02.800
care by your ansible.

00:06:02.900
00:06:04.400
No need to write extra code bias.

00:06:04.900
00:06:07.000
But if you're writing some shell or
python, we need to write

00:06:07.000
00:06:08.200
the code for even exceptional.

00:06:08.200
00:06:09.400
So that's it.

00:06:09.400
00:06:09.700
Nothing.

00:06:09.700
00:06:11.500
Is that okay?

00:06:11.500
00:06:12.100
See here.

00:06:13.200
00:06:16.200
So this is our Playbook, right?

00:06:16.500
00:06:17.600
I am going to run this.

00:06:18.000
00:06:20.600
But anyway already our instance state
is running but we are

00:06:20.600
00:06:24.500
trying to run that right see that what
will happen.
00:06:25.800
00:06:28.000
So, let me check for syntax check.

00:06:33.600
00:06:34.700
Yes, everything is fine.

00:06:35.000
00:06:35.200
Now.

00:06:35.200
00:06:38.000
I want to run my playbook to start my
ec2 instance.

00:06:38.100
00:06:40.900
Make sure that already is in running
State even though it

00:06:40.900
00:06:43.300
is running on if you try to run that no
problem.

00:06:43.300
00:06:46.400
It won't do any modification see
change.

00:06:46.800
00:06:48.700
No because already it is running
straight.

00:06:50.100
00:06:52.500
Right fine now suppose.

00:06:52.500
00:06:55.500
I am going to stop it manually
somewhere here and I will

00:06:55.500
00:06:58.500
try to start with the help of our
Playbook.

00:06:58.600
00:06:59.500
Yes, it will work.

00:07:00.500
00:07:01.900
But of course you can also stop that.

00:07:01.900
00:07:02.600
We'll see that.

00:07:05.900
00:07:09.400
So once it is successfully stopped
then we will run our Playbook

00:07:09.800
00:07:11.200
to start this instance.

00:07:14.300
00:07:16.500
So guys mean by L here.
00:07:16.500
00:07:18.000
I want to write weight as well.

00:07:18.400
00:07:23.300
Wait s so, what is the meaning of wait
s means suppose you

00:07:23.300
00:07:26.300
are going to stop your instance.

00:07:26.300
00:07:29.400
Then your playbook will wait up to the
instances successfully

00:07:29.400
00:07:31.000
stopped. So suppose here.

00:07:31.000
00:07:33.200
We are going to run your instance.

00:07:34.300
00:07:37.300
So your playbook will wait up to your
instance is running.

00:07:38.200
00:07:38.700
That's it.

00:07:40.500
00:07:42.200
Okay, it is stop right now.

00:07:42.200
00:07:46.400
We are going to run our Playbook to
start your ec2 instance

00:07:46.500
00:07:48.000
with the required instance ID.

00:07:49.500
00:07:51.300
So now you're in your playbook is
waiting.

00:07:52.400
00:07:55.100
Now come here and refresh it and see
that your instance is

00:07:55.100
00:07:55.800
coming up.

00:07:57.500
00:07:57.800
Right.

00:07:57.800
00:08:00.300
Once it is successfully running then
only your playbook will

00:08:00.300
00:08:02.900
stop that is because of weight s
option.
00:08:05.800
00:08:09.000
Yes changed one means nowadays
started.

00:08:11.000
00:08:12.200
Nobody's running State now.

00:08:12.200
00:08:14.300
Once again, if you run the or
Playbook, right, it won't do

00:08:14.300
00:08:14.800
any action.

00:08:14.800
00:08:15.300
See now.

00:08:15.300
00:08:18.400
You got here changed one, but here
you've got change 0 means

00:08:18.800
00:08:20.800
already running but you're trying to run
that that's why

00:08:20.800
00:08:22.200
it is not going to be any changes.

00:08:22.300
00:08:25.500
So this is called idempotent of your
ansible.

00:08:27.600
00:08:28.800
Right fine.

00:08:28.900
00:08:29.300
Now.

00:08:29.300
00:08:32.500
What I am doing is I want to start I
want to stop my ec2

00:08:32.500
00:08:33.799
instance. Right?

00:08:33.799
00:08:40.400
Let me copy same code whatever you
are having in your start.

00:08:40.400
00:08:41.799
Just I want to change the state.

00:08:41.799
00:08:42.400
That's it.

00:08:42.400
00:08:47.400
Stop easy to dot m l so you can write y
ml or simply yml.
00:08:47.400
00:08:48.000
No problem.

00:08:48.700
00:08:57.600
So guys, this is like no four Let me
remove this three stop.

00:09:08.500
00:09:08.700
Okay.

00:09:08.700
00:09:14.300
Now let me edit this ML and let me
change my state as stopped.

00:09:21.800
00:09:24.700
Right now, let me run ansible
Playbook.

00:09:26.300
00:09:28.600
so before going to stop just observe
that it is in running

00:09:28.600
00:09:34.100
State now, we are running stop and
Sybil Playbook and we

00:09:34.100
00:09:38.100
kept as weight option as he has the
thread is waiting now

00:09:38.100
00:09:42.900
refresh it and see the CT stopping
once it is stopped successfully

00:09:42.900
00:09:44.300
your playbook will come out.

00:09:49.900
00:09:51.400
Done, right.

00:09:51.500
00:09:55.500
So you guys change one means your
operation is done then

00:09:55.500
00:09:56.200
refresh it.

00:09:56.700
00:09:57.500
It is stopped.

00:09:58.900
00:10:03.200
Right, then we are going to see about
if you want to terminate

00:10:03.200
00:10:04.200
your instance.

00:10:04.300
00:10:06.500
So how you can terminate right?
00:10:06.500
00:10:07.800
Let me do this thing.

00:10:10.500
00:10:15.500
Terminate PC2 guys you can do this
thing for even multiple

00:10:15.500
00:10:16.900
instance IDs at a time.

00:10:17.100
00:10:22.000
The only thing you have your instant
side is key in your

00:10:22.000
00:10:22.900
playbook right here.

00:10:22.900
00:10:25.800
You can provide as a sequence or as
a list your multiple

00:10:25.800
00:10:28.500
Insurance side is right fine.

00:10:28.900
00:10:30.700
Now I am going to run this play book.

00:10:32.700
00:10:37.500
ansible Playbook Kermit easy to this
instance I am going

00:10:37.500
00:10:41.300
to turn it right this is stop state but now
I am going to

00:10:41.300
00:10:56.000
terminate it so right thought of what
happened let me check

00:10:56.000
00:10:59.300
it yeah I think we did not modified
value because already

00:10:59.300
00:11:04.400
in it is stopped really we have given
now we have to provide

00:11:04.600
00:11:09.600
State as terminate I guess if you want
to change your name

00:11:09.600
00:11:12.100
say yes, we forgot to change if you
want to change you can

00:11:12.100
00:11:12.900
change this.
00:11:13.400
00:11:16.500
So terminating ec2 instance.

00:11:24.200
00:11:24.600
Okay.

00:11:25.400
00:11:26.800
Now let me run our Playbook.

00:11:27.100
00:11:30.500
So guys previously whenever we ran
there is no change because

00:11:30.500
00:11:35.100
already that is in stop State and in this
that state as stop

00:11:35.100
00:11:38.700
that side is not doing any action now
we modified that to

00:11:38.700
00:11:41.400
turn it see the output so it is waiting.

00:11:45.100
00:11:46.600
Okay, maybe spell mistake.

00:11:47.000
00:11:48.000
Let me check it.

00:11:57.300
00:12:07.600
State as Yes, turn it only right ERM.

00:12:07.600
00:12:09.200
I anythi terminate?

00:12:12.000
00:12:13.200
What is the problem here?

00:12:17.800
00:12:19.900
Terminate yes love me.

00:12:21.200
00:12:22.100
Restart it.

00:12:26.200
00:12:29.500
State must be one of the present of
sent running.

00:12:31.200
00:12:31.800
Oh, sorry.

00:12:32.400
00:12:35.200
We are giving turn right we have to
avoid actually absent.

00:12:39.200
00:12:40.600
Okay, let me do this.
00:12:41.700
00:12:44.300
So we have to provide not admit we
have to provide optioned.

00:12:47.600
00:12:52.900
In case if you some wrong value then
it is displaying suggestible

00:12:52.900
00:12:55.900
values. You can write some present
optioned running guys.

00:12:55.900
00:12:59.400
You can also restart it restarted will
restart your instance

00:13:00.100
00:13:00.700
right now.

00:13:00.700
00:13:02.500
I'm going to run it and see the output.

00:13:02.900
00:13:05.400
Yes, you know, it is waiting to
terminate your instance.

00:13:05.400
00:13:09.300
Meanwhile just to go and refresh it see
the output here is

00:13:09.300
00:13:10.200
shutting down.

00:13:10.300
00:13:13.000
That means after some time definitely
will go to terminate

00:13:13.000
00:13:15.100
adoption means you're going to
remember get it.

00:13:16.100
00:13:18.100
Right see ya.

00:13:18.100
00:13:18.800
It's done.

00:13:18.800
00:13:22.400
Now refresh it and see the output
terminate.

00:13:23.000
00:13:27.400
So guys, this is the way how you can
start or stop or turn

00:13:27.400
00:13:31.400
it your ec2 instances using your
ansible playbook because
00:13:31.400
00:13:32.800
you can also restart it.

00:13:32.900
00:13:35.800
So just to write your state as restarted
so that you can

00:13:35.800
00:13:37.000
restart your instance.

00:13:38.800
00:13:39.200
Okay.

00:13:40.000
00:13:40.600
Okay guys.

00:13:40.700
00:13:42.200
Thank you for watching this video.
Transcript
00:00:00.000
00:00:02.200
See, in our previous video

00:00:02.200
00:00:06.100
we have seen something like that to
start, stop and terminate

00:00:06.100
00:00:11.100
ec2 instances with separate
playbooks, but now here I want

00:00:11.100
00:00:15.100
to write single playbook, and with the
playbook if I want

00:00:15.100
00:00:20.600
to start, how to start it, stop it, and
terminate.

00:00:20.600
00:00:23.010
So, then how you can write this
playbook, Okay.

00:00:23.000
00:00:25.700
So, let me connect with my host,
because from there
00:00:25.700
00:00:28.400
I need to execute my playbook.

00:00:29.500
00:00:32.000
So assume that this is your local host
where you are having

00:00:32.000
00:00:33.400
your ansible controller.

00:00:33.400
00:00:38.400
So, from our very first class we are
using this user and submenus, alright?

00:00:38.800
00:00:42.500
So, let me enter into that, and we have
created one Directory, right?

00:00:42.500
00:00:46.910
So, that is AWS_cloud.

00:00:46.900
00:00:50.800
That is: $ cd AWS_cloud/

00:00:50.800
00:00:54.000
So, now we have, here we are having
our inventory

00:00:54.000
00:00:56.700
just simply localhost, and we have our
ansible

00:00:56.900
00:00:58.700
configuration file, right?

00:00:58.700
00:01:03.000
We done some default configurations
in very first video, right?

00:01:03.000
00:01:07.500
Fine, now up to now we're having this
many number of playbooks.

00:01:07.500
00:01:10.100
Now, I want to write one single
playbook.

00:01:10.100
00:01:11.600
See if you try now, in our previous
video

00:01:11.600
00:01:13.000
we have done these three playbooks.

00:01:13.000
00:01:16.500
Now, I want to collaborate these three
and I want to exclude them, based
00:01:16.500
00:01:18.700
on our requirement, right?

00:01:18.800
00:01:22.100
So, let me copy first our existing,

00:01:22.100
00:01:28.700
suppose so this I want to create start,
stop and terminate.

00:01:28.700
00:01:32.000
Of course if you want to restart it, you
can restart also, right?

00:01:32.000
00:01:38.200
Now, let me...I want to make the name
as seven or sixth,

00:01:38.200
00:01:40.600
let me write this.

00:01:42.000
00:01:43.700
Sixth playbook I am going to write it
here.

00:01:46.400
00:01:48.100
Now, let me open this playbook.

00:01:48.100
00:01:57.000
So, this play is used to start, stop and
terminate ec2 instance.

00:01:57.200
00:02:00.300
So, as of now we are going to use this
for only single instance.

00:02:00.300
00:02:07.200
Fine, so I'm going to do this here
starting ec2 instance.

00:02:07.200
00:02:12.900
Now, let me copy and paste the same
task two more times because

00:02:12.900
00:02:18.000
I want to add here stop and then
terminate, right?

00:02:18.000
00:02:20.700
So, firstly just to start your ec2
instance.

00:02:20.700
00:02:26.100
So, second is just to stop your ec2
instance.

00:02:26.100
00:02:29.862
So, stopping ec2 instance.
00:02:29.800
00:02:35.500
So, to stop, you have to provide state
as stopped,

00:02:35.500
00:02:37.600
and to terminate your ec2 instance,

00:02:37.600
00:02:40.000
you need to provide state as absent.

00:02:40.000
00:02:44.100
Right, so here terminating ec2
instance. (No audio).

00:02:46.759
00:02:51.500
Right, and one more thing, this
instance ID is from our previous class,

00:02:51.500
00:02:53.900
Now, I want to change our instance ID.

00:02:53.900
00:02:57.500
So, let me connect with my AWS and
let me get it.

00:02:57.700
00:03:00.023
So, I want to get this instance ID.

00:03:00.023
00:03:06.730
Now, I'm going to change instance ID.

00:03:06.730
00:03:11.992
So guys, as of now, whatever the
playbook you are having,

00:03:11.992
00:03:16.000
with that playbook if you run, what will
happen you are having three tasks.

00:03:16.000
00:03:20.032
So, all these three tasks will execute
in sequence.

00:03:20.032
00:03:22.121
So, finally what will happen,

00:03:22.121
00:03:24.700
all the three tasks are going to
execute, but I don't want

00:03:24.700
00:03:29.600
to execute like start, then stop and
then termination, right?

00:03:29.600
00:03:32.000
Based on our requirement among
these three tasks.
00:03:32.000
00:03:35.100
I want to execute any one of any one
of the tasks,

00:03:35.100
00:03:35.900
so, how you can do that?

00:03:36.000
00:03:40.300
So, for that you have an option called
Tags. Right?

00:03:40.300
00:03:42.761
So, let me write my tags.

00:03:42.761
00:03:48.163
So, here suppose I want to start, so I
am giving name as start.

00:03:48.163
00:03:54.054
Then here I want to provide tags as
stop.

00:03:54.054
00:03:58.475
I mean whenever if I pass stop as a
tag, your instance will stop.

00:03:58.475
00:04:10.500
(No audio) Then here I am going to
provide tags as suppose, terminate.

00:04:10.500
00:04:14.000
And one more thing guys, you just
provided your

00:04:14.000
00:04:19.500
tag names, and here also if you run
your playbook by default

00:04:19.500
00:04:23.700
all the tasks will execute even though
if you have tags,

00:04:24.899
00:04:28.300
if you don't provide any tag while
running your playbook

00:04:28.300
00:04:31.400
by default all the tasks will execute.

00:04:31.400
00:04:35.700
If you provide tag, then particular tag
will execute, but my intention is,

00:04:35.700
00:04:39.000
if I don't provide anything, then I don't
want to execute any one of the tasks.
00:04:39.000
00:04:42.110
I mean, while running my playbook,
right?

00:04:42.110
00:04:47.000
Suppose I want to run my playbook in
this way.

00:04:47.000
00:04:50.811
Let me do this, ansible,

00:04:50.811
00:04:52.254
playbook.

00:04:52.254
00:04:55.100
So, I want to provide my tag name, so
I can provide simply like

00:04:55.100
00:04:57.032
- t

00:04:57.032
00:05:00.542
And then, I can suppose write start,

00:05:00.542
00:05:06.800
so that only start will execute, but my
mistake, if I run in this way

00:05:06.800
00:05:09.500
all the three tasks will execute, but I
don't want

00:05:09.500
00:05:12.200
to execute all the three tasks until
unless if you are not

00:05:12.200
00:05:14.500
providing any particular tag.

00:05:14.500
00:05:16.000
so for that you need to add

00:05:16.000
00:05:19.600
one more extra default tag name, that
is called 'never'.

00:05:19.600
00:05:22.851
So, what will happen if I write never
here?

00:05:22.851
00:05:27.356
So, by default this task won't execute.

00:05:27.356
00:05:33.000
Only if you call this task with the help
of a particular tag,
00:05:33.000
00:05:37.890
then only that particular task will
execute.

00:05:37.890
00:05:44.700
That is the feature of never, right?

00:05:44.700
00:05:47.647
I am writing never.

00:05:47.647
00:05:54.000
Suppose now if I run my playbook,
right, so I am going - let me check it first

00:05:54.000
00:06:02.199
syntax check, ansibil, playbook - -
syntax

00:06:02.199
00:06:06.280
check, everything is fine.

00:06:06.280
00:06:10.425
Now, I am going to run my playbook,
see the output what you are getting.

00:06:10.425
00:06:14.600
No task is running, right, this play is
used to start,

00:06:14.600
00:06:19.100
stop and terminate instances, and you
have getting directly play recap.

00:06:19.100
00:06:22.600
So, between these two, you are not
excluding anyone of the task.

00:06:22.600
00:06:27.500
Right, now suppose if I want to start
my instance,

00:06:27.500
00:06:32.500
then simply pass, so see what I am
using: -t start.

00:06:32.500
00:06:38.800
Now observe that output, only starting
ec2 instance, task is executing.

00:06:38.800
00:06:43.200
Right, suppose if I want to stop,
because already is in running status,

00:06:43.200
00:06:47.800
that's why there is no change value,
now suppose if I do stop,
00:06:47.800
00:06:53.400
so, before going to stop, see this is the
instance, now it is in running state.

00:06:53.400
00:06:55.930
Now, I'm going to pass my tag as stop.

00:06:55.930
00:07:00.500
Now if I run this, state is going to
stopping ec2 instance

00:07:00.500
00:07:02.900
previously starting, now it is stopping

00:07:02.900
00:07:06.100
Just go and see in your console, and
refresh it,

00:07:06.100
00:07:09.600
and see that what it is doing, stopping.

00:07:09.600
00:07:13.100
Right, once it is stopped your
playbook will come

00:07:13.100
00:07:18.900
out from... here it is done, now refresh
it, and see the output, stop.

00:07:18.900
00:07:21.300
Now, I want to start it.

00:07:21.300
00:07:30.494
Yes, you simply start, - t, start. (No
audio).

00:07:30.494
00:07:34.000
Now it is going to run, let me refresh it.

00:07:34.000
00:07:35.700
Pending, so it is coming up.

00:07:35.700
00:07:36.500
Right?

00:07:36.500
00:07:39.300
So, once if your playbook is done,
then your instance would

00:07:39.300
00:07:41.300
be running.

00:07:41.300
00:07:42.000
Just wait.

00:07:42.100
00:07:44.500
Yeah, then, refresh it and see the
output.
00:07:44.500
00:07:45.500
Yes, running.

00:07:45.500
00:07:48.210
Now, I want to terminate my ec2
instance,

00:07:48.200
00:07:52.100
so, one of the tag called terminate we
have given inside of

00:07:52.100
00:07:55.700
our playbook, now just run terminate,
now observe the which task

00:07:55.700
00:08:00.479
is executing, terminating ec2 instance
task is executing. (No audio).

00:08:00.479
00:08:08.200
Right, once it is done, let me refresh
here see it is shutting down.

00:08:08.200
00:08:13.800
Just wait, once your playbook is done
with that particular

00:08:13.800
00:08:17.300
task, then we'll go and refresh it see
that, it is done.

00:08:17.300
00:08:20.300
See that, it has been terminated.

00:08:20.300
00:08:27.400
So guys, this is the simple playbook,
right, to start and stop

00:08:27.400
00:08:29.800
and terminate particular ec2 instance.

00:08:29.800
00:08:34.100
But in real time, right, you don't have
directly,

00:08:34.100
00:08:36.700
I mean you will have instance ID's, but
directly you won't

00:08:36.700
00:08:40.900
use instance ID's is to start or stop.
Based on some action,

00:08:40.900
00:08:44.400
you want to start or stop or terminate
your ec2 instances,
00:08:44.400
00:08:52.000
so we'll just assume that. I have some
ec2 instances on my AWS.

00:08:52.000
00:08:55.700
Right? For some of the ec2 instances,

00:08:55.700
00:08:57.000
I don't have any tags.

00:08:57.000
00:09:01.500
So, I have a requirement that if any
one of the instance is

00:09:01.500
00:09:04.633
not having tag, those instances I want
to terminate,

00:09:04.600
00:09:10.500
then, instead of manually search and
placing this instance ID here,

00:09:10.500
00:09:13.500
You have to write some logic, such
that your playbook will

00:09:13.500
00:09:16.400
identify which instances are not having
tags.

00:09:16.400
00:09:21.400
Otherwise, suppose I'm having some
testing run on it.

00:09:21.400
00:09:23.400
So, I have a tag key as test.

00:09:23.400
00:09:29.600
Now, I want to destroy all the
instances which are there in test environment.

00:09:29.600
00:09:32.400
I mean, I want to terminate all the
instances

00:09:32.400
00:09:35.100
which are having tag as test.

00:09:35.100
00:09:39.100
Then you have to write some logic,
such that your ansible

00:09:39.100
00:09:44.700
playbook has to identify the instances
which are having tag as test,
00:09:44.700
00:09:47.300
and those instances it has to
terminate.

00:09:47.300
00:09:50.200
So, this type of things we will see
while going forward.

00:09:50.200
00:09:50.900
Okay?

00:09:50.900
00:09:53.900
So as of now, there is a simple
playbook to start, stop and

00:09:53.900
00:09:55.800
terminate your ec2 instance.

00:09:55.800
00:09:58.900
Okay guys, thank you for watching this
video.
Transcript
00:00:00.000
00:00:07.100
In our previous videos, we've seen
how to start, stop and terminate EC2 instances

00:00:07.500
00:00:12.200
directly by providing the instance IDs.
but here I don't

00:00:12.200
00:00:14.000
want to provide my instance IDs.

00:00:15.200
00:00:19.700
I need to automatically fetch my
instances, based on tags.

00:00:20.400
00:00:24.500
Just assume that you have a small
requirement in your real-time.

00:00:25.500
00:00:32.200
So there is some test servers, but I
only want to run

00:00:32.200
00:00:33.200
the instances on half of them.
00:00:35.200
00:00:41.100
So out of office hours, I want to stop
all the instances. Right?

00:00:41.500
00:00:45.900
So for this I have given tag names
like, just assume

00:00:45.900
00:00:49.600
that key has Env and its value is test.

00:00:50.700
00:00:54.200
Right, so I need to fetch the instance
ideas with

00:00:54.200
00:00:58.500
this tag and I want to stop or start,
whatever it may be.

00:00:59.700
00:01:00.100
Right?

00:01:00.500
00:01:03.800
So every day, before starting work, I
need to start the

00:01:03.800
00:01:06.500
instances, and after completion of my
work with office,

00:01:06.900
00:01:08.200
I need to stop the instances.

00:01:09.400
00:01:12.200
After doing some testing successfully,
I don't want to

00:01:12.200
00:01:16.300
use the test servers, so you can
terminate, just by using

00:01:16.300
00:01:17.100
your tags.

00:01:17.700
00:01:18.100
Right?

00:01:18.300
00:01:22.200
So guys, if you are using ansible in
your environment,

00:01:22.200
00:01:26.400
it's better to use ansible playbook to
start or stop

00:01:26.400
00:01:29.800
and terminate instances, right?
00:01:29.800
00:01:34.200
So here it's very important, based on
tags, how you can

00:01:34.200
00:01:37.200
manage these options.

00:01:37.300
00:01:39.900
So guys, let me connect with my local
host.

00:01:40.500
00:01:40.800
Of course,

00:01:40.800
00:01:42.500
this is also one of the EC2 instance.

00:01:42.900
00:01:45.700
So from there we are going to work,
right?

00:01:46.100
00:01:49.100
From our first video, we are going to
follow this

00:01:49.100
00:01:51.900
user, because with that I'm having set
up.

00:01:51.900
00:01:58.600
[no audio]

00:01:58.600
00:01:59.800
So let me check it.

00:01:59.800
00:02:05.100
So as of now, yeah, we are having
AWS directory, right?

00:02:05.100
00:02:07.600
So in that we have our setup.

00:02:09.000
00:02:13.600
Yes, and one more thing Let Me
connect with my AWS console

00:02:13.600
00:02:16.000
and see that of course, sir.

00:02:16.100
00:02:18.300
See for this.

00:02:18.800
00:02:19.800
I mean as will controller.

00:02:19.800
00:02:21.200
This is actually my Local Host.

00:02:21.400
00:02:24.500
We don't have any tag like EnV test.
00:02:24.700
00:02:29.500
But if you go with remaining two, I
have a key as ENB value

00:02:29.500
00:02:30.200
as a test.

00:02:31.200
00:02:34.500
And for one more thing also This
Server also, that means

00:02:34.900
00:02:37.900
I have to manage these two servers
with my ansible playbook

00:02:38.000
00:02:42.600
automatically. As to identify this IDs
instance IDs, right?

00:02:42.600
00:02:46.000
So let me go and do something here
guys before going to enter

00:02:46.000
00:02:47.800
into this concept suppose.

00:02:47.800
00:02:51.400
If you are going to manage some
nodes just forget about AWS

00:02:51.400
00:02:53.100
Cloud concept with your ansible.

00:02:53.800
00:02:56.400
So if you want to manage some
servers with your ansible,

00:02:56.500
00:02:59.900
right there is a one of the option called
gather facts.

00:03:00.900
00:03:02.500
So what about gather facts?

00:03:03.900
00:03:07.300
So if you write gather facts Anyway by
default, it will be

00:03:07.400
00:03:08.400
it is true only.

00:03:08.400
00:03:10.100
I mean yes only.

00:03:11.200
00:03:15.300
So you sometimes you can disable
that right by making option
00:03:15.300
00:03:16.400
as false or no?

00:03:17.800
00:03:18.300
Right.

00:03:18.300
00:03:19.100
So what is it?

00:03:20.000
00:03:23.100
So gather facts is nothing but getting
information about

00:03:23.100
00:03:24.100
your remote server.

00:03:25.800
00:03:27.100
The same way here.

00:03:27.100
00:03:31.400
You are having one module called
AWS instance facts.

00:03:32.700
00:03:36.600
So this module will fetch the
information about your AWS

00:03:36.600
00:03:39.600
instance has each and every option.

00:03:39.600
00:03:41.300
It will fetch right first.

00:03:41.300
00:03:44.300
Let me write simple Playbook to see
all the instances which

00:03:44.300
00:03:49.700
are there in my database console with
Butler tags, then we'll

00:03:49.700
00:03:52.300
implement this thought stop and
tournament street, right?

00:03:52.500
00:03:58.200
So get easy to info dot m l am writing,
right?

00:03:58.200
00:04:01.300
So this is just simply A playbook this
play.

00:04:02.400
00:04:04.600
Is used to fetch.

00:04:07.200
00:04:15.500
instances info Right, so it need at least
one host.
00:04:17.200
00:04:18.200
So we are taking that.

00:04:20.000
00:04:26.200
then after host information connection
is bad to take as

00:04:26.200
00:04:32.600
local. Then gather facts, so guys this
is getting facts about

00:04:32.600
00:04:33.600
your notes.

00:04:33.600
00:04:35.600
But here we don't have any notes
other than localhost.

00:04:35.600
00:04:40.000
Anyway, I don't bother about facts
about my Local Host.

00:04:41.500
00:04:43.400
So that's why I'm making this as a
false.

00:04:44.900
00:04:47.000
Right now I'm going to write tasks.

00:04:47.500
00:04:55.700
So my task is just getting info about
history to using so

00:04:55.700
00:04:57.900
here you need to use guys based on
your requirement.

00:04:57.900
00:05:01.300
You have different types of models
with your AWS cloud and

00:05:01.600
00:05:06.300
I already showed that different
modules of your AWS Cloud

00:05:06.300
00:05:07.200
for ansible.

00:05:07.900
00:05:09.800
So if you have any doubts just to go
through our previous

00:05:09.800
00:05:14.300
videos and come back here and
continue info about ec2 using

00:05:14.500
00:05:16.900
let me take ec2 instance.
00:05:18.300
00:05:21.300
Facts, this is the one of the module
right now.

00:05:21.300
00:05:23.600
I want to write and I want to use this
module.

00:05:25.000
00:05:26.600
Instance facts.

00:05:27.200
00:05:30.700
So this instance facts needs minimum
first thing region.

00:05:30.800
00:05:32.700
So from which region you want to get.

00:05:36.200
00:05:41.400
Right, then guys using this instance of
using this module.

00:05:41.600
00:05:46.600
You can fetch the ec2 instance
information by default all

00:05:46.600
00:05:48.000
the informations by default.

00:05:48.000
00:05:51.500
You will get it but I don't want to get
the all the instances

00:05:51.500
00:05:54.400
information. I want to get based on
some filter concept.

00:05:54.900
00:05:58.200
What is that filter means based on my
required tags, or you

00:05:58.200
00:06:01.200
can also do something like based on
availability Zone.

00:06:02.300
00:06:05.000
So from which Joan you want to work
with your ec2 instances

00:06:05.000
00:06:08.100
using your ansible like that filter you
have to provide here.

00:06:08.100
00:06:13.000
So as of now, I am going to provide
filters as let me take
00:06:14.000
00:06:21.400
tag tag Sookie is ENB If You observe
here key is EnV value

00:06:21.400
00:06:24.300
is test so that I have to provide in this
format.

00:06:25.300
00:06:27.200
Right, then.

00:06:28.200
00:06:30.500
I need to capture this output.

00:06:31.500
00:06:32.700
Right just use register.

00:06:33.300
00:06:38.800
So right easy to info then the task
which is used to get

00:06:38.800
00:06:42.400
the information about your ec2
instances based on your tax

00:06:42.400
00:06:42.900
is over.

00:06:43.400
00:06:46.100
But if you run this, you won't get any
output so to get your

00:06:46.100
00:06:48.600
output in to display the value which is
there in your ec2

00:06:48.600
00:06:49.500
info variable.

00:06:50.100
00:06:54.200
So this variable output how to display
so for that just use

00:06:55.300
00:06:57.800
Debug module so displaying output.

00:06:57.900
00:06:58.500
I am writing.

00:07:00.600
00:07:05.200
Now the bug right and here simply I'm
using.

00:07:08.500
00:07:11.300
You are easy to underscore info
variable.
00:07:12.600
00:07:16.700
Right, let's first let me check the
syntax check and if there

00:07:16.700
00:07:17.400
are any.

00:07:21.700
00:07:22.600
Woman directly run.

00:07:22.700
00:07:23.200
No problem.

00:07:23.600
00:07:24.400
Everything is good.

00:07:24.400
00:07:26.800
It's got it now see the output.

00:07:28.100
00:07:32.700
So you are getting instances
information of your AWS based

00:07:32.700
00:07:36.800
on some filter that is called tag right
now see here in the

00:07:36.800
00:07:40.800
output you're having instances now in
these instances If

00:07:40.800
00:07:44.600
You observe here somewhere you will
have your instance ID.

00:07:47.300
00:07:52.000
Right and you will also find your what
is the tag based on

00:07:52.000
00:07:54.600
which tag you are going to get this
information somewhere

00:07:54.600
00:07:55.400
you will find.

00:07:59.500
00:08:03.400
Security Group, it's okay corestates e-
tags you're having

00:08:03.600
00:08:06.900
so this tags instance only you're
getting right.

00:08:06.900
00:08:09.100
So that is all about your first instance.
00:08:09.600
00:08:13.000
Now if we go somewhere by down and
if you see so now this

00:08:13.000
00:08:15.300
is about your second instance
information.

00:08:17.000
00:08:20.500
Right now see you're getting all the
details here, but I

00:08:20.500
00:08:23.500
want to get only instance IDs If You
observe here you're

00:08:23.500
00:08:25.500
having your groups, right?

00:08:25.500
00:08:30.100
Subnet ID right see the public DNS
name, but I don't want

00:08:30.100
00:08:31.400
to get all these things simply.

00:08:31.400
00:08:34.500
I want to get my instance side is
because if I know inside

00:08:34.500
00:08:40.700
is then I can start and stop my
instances, right so guys,

00:08:40.700
00:08:44.799
let me modify this get easy to info into
I want to read this

00:08:44.799
00:08:57.100
as a seventh ml script in our course so
start-stop terminate

00:08:59.200
00:09:04.900
Based on tags not a mark right now.

00:09:04.900
00:09:06.900
Let me open this 7th script.

00:09:08.000
00:09:10.300
There is now I am going to display.

00:09:12.100
00:09:17.200
You were easy to information instance
IDs, but here you are

00:09:17.200
00:09:18.700
having multiple instances.
00:09:18.700
00:09:21.400
So whenever if you have multiple
instances, so it's better

00:09:21.400
00:09:24.400
to take for Loop to display your
information.

00:09:24.500
00:09:26.100
I mean any Loop right?

00:09:26.100
00:09:30.800
So here we are having with items with
items.

00:09:31.200
00:09:33.000
So what is the item you want to get?

00:09:33.000
00:09:34.500
So from this variable?

00:09:35.000
00:09:36.600
Let me copy and paste it first.

00:09:37.700
00:09:40.500
So you're having one of the key called
instances we have

00:09:40.500
00:09:45.700
seen in the output instances, right and
here I want to display

00:09:46.500
00:09:49.100
item dot instance ID.

00:09:49.400
00:09:53.300
So inside of each and every
information each and every server

00:09:53.300
00:09:55.200
information, you have somewhere
instance ID.

00:09:55.400
00:09:56.900
You can see that in the output.

00:09:59.800
00:10:03.000
So let me go very first I can show you
see.

00:10:04.700
00:10:06.900
Instanceid so this instance ID.

00:10:06.900
00:10:09.100
I want to display right now.

00:10:09.100
00:10:11.500
Let me run this script and see the
output.
00:10:14.200
00:10:15.800
Oh, it's not.

00:10:17.800
00:10:19.200
When it to run this, right?

00:10:19.200
00:10:24.000
Yes, give me a second ansible
Playbook.

00:10:24.400
00:10:29.500
I'm running somewhere displaying
Maybe.

00:10:31.000
00:10:32.600
Let me check it send texts.

00:10:37.900
00:10:40.700
Item, sorry single curly braces we
have taken.

00:10:43.300
00:10:44.100
Now it's fine.

00:10:46.100
00:10:50.100
Now see the output see you are
getting first of all enter

00:10:50.100
00:10:51.300
in from this information.

00:10:51.300
00:10:54.500
It is displaying only or instance ID is
playing only in your

00:10:54.500
00:10:55.100
instance ID.

00:10:55.100
00:10:59.900
Let me take this is for D and this is 56
E-flite something

00:10:59.900
00:11:01.200
960. Let me check it.

00:11:03.300
00:11:06.300
Yeah, 960 and 0 for f 0.

00:11:07.900
00:11:10.600
Sorry, not this yeah, 960 and 4-D.

00:11:10.600
00:11:13.300
These two are the instant side is so
that we are able to

00:11:13.300
00:11:19.000
fetch using your playbook now in our
hand we are have a logic
00:11:19.000
00:11:20.000
to identify.

00:11:20.100
00:11:22.900
Your instant side is based on keyword
tags.

00:11:23.400
00:11:27.900
Now, I want to implement start stop
and third mate action

00:11:28.800
00:11:29.700
right on this.

00:11:30.400
00:11:31.700
So how you can do this.

00:11:34.000
00:11:35.200
See now.

00:11:36.300
00:11:39.300
I don't want to display actually, so let
me I will do one

00:11:39.300
00:11:40.700
thing comment this code.

00:11:42.500
00:11:48.600
This part now so guys, you know
already we have seen to start

00:11:48.600
00:11:50.900
and stop your ec2 instances what you
need.

00:11:51.200
00:11:53.800
You need simply module, right?

00:11:54.500
00:11:57.300
So if you want already we have let me
copy that that's better

00:11:57.300
00:12:01.500
thing. I think from 6th.

00:12:03.700
00:12:07.500
right So, let me copy one part.

00:12:24.300
00:12:29.600
Right, but here instanceid is not a
fixed value, right?

00:12:29.600
00:12:33.100
We need to modify this instance IDs,
but here we are having

00:12:33.100
00:12:34.200
multiple instances.
00:12:34.200
00:12:36.200
So this action has to complete.

00:12:36.200
00:12:37.600
I mean this task whatever it is.

00:12:37.600
00:12:40.500
They're there has to work on each and
every instance so you

00:12:40.500
00:12:43.000
are able to fetch your each and every
instance using Loop

00:12:43.700
00:12:44.400
right now.

00:12:44.400
00:12:45.900
Let me take your Loop first.

00:12:48.900
00:12:50.300
With this items nothing.

00:12:50.300
00:12:52.100
Is there simply here, right?

00:12:57.800
00:13:00.400
That's it, right.

00:13:00.400
00:13:02.900
So same thing just to copy and paste.

00:13:07.500
00:13:19.800
and use it for now stopping Right.

00:13:19.900
00:13:23.800
So now you have to keep this as
running into stop.

00:13:26.900
00:13:44.000
one more thing for terminate so
terminating so absent Right,

00:13:44.000
00:13:44.600
that's it.

00:13:45.500
00:13:47.700
So, yeah, we need to change key
values guys.

00:13:47.900
00:13:49.300
So we have here start.

00:13:49.600
00:13:52.200
So I want to this simply terminate.

00:13:55.300
00:13:57.000
So I want to stop it.

00:14:01.100
00:14:03.500
Let me modify here named terminate.
00:14:03.500
00:14:04.300
Yes fine.

00:14:05.700
00:14:08.000
Right now I am going to run this play
book.

00:14:09.500
00:14:21.400
seventh Playbook first, let me check
your syntax check everything

00:14:21.400
00:14:22.000
is fine.

00:14:22.600
00:14:22.800
Now.

00:14:22.800
00:14:24.800
I am going to run this play book.

00:14:26.500
00:14:28.600
It won't do anything, right?

00:14:30.000
00:14:33.300
Only accept getting you are instances
facts because for that

00:14:33.300
00:14:36.600
you don't have any tags now, we know
that if you want to

00:14:36.600
00:14:39.800
execute anything you need to pass
your tag start.

00:14:41.300
00:14:43.500
Easy to info is on defined here.

00:14:43.500
00:14:44.400
Let me check it.

00:14:50.500
00:15:05.600
VI Where is easy to inform Define?

00:15:17.600
00:15:18.500
That is there.

00:15:21.900
00:15:23.600
Register is it info?

00:15:27.200
00:15:29.300
Okay, one more thing guys.

00:15:30.700
00:15:34.900
So if you pass some tag know only
that module will execute

00:15:34.900
00:15:37.800
suppose we are passing suppose start
this module will exclude
00:15:37.800
00:15:42.400
but while executing this module, right
so there is no value

00:15:42.400
00:15:46.900
of ECT info that means you need to
exclude this so guys observe

00:15:46.900
00:15:49.600
that here if you want to exclude either
stop or start or

00:15:49.600
00:15:52.600
terminate always he has executed first
this because from

00:15:52.600
00:15:53.800
this you are getting your information.

00:15:53.800
00:15:55.700
That's why I just add your tag here.

00:15:56.600
00:16:00.200
like let me write my tag first.

00:16:01.500
00:16:04.500
Always so irrespective of any task
always.

00:16:06.100
00:16:09.800
I want to run this information in this
module this task first

00:16:10.300
00:16:11.100
now it will work.

00:16:13.400
00:16:17.700
See that starting already instances are
in running status,

00:16:17.700
00:16:23.900
right? Right already instances are in
running status now.

00:16:24.200
00:16:25.700
Let me refresh it.

00:16:28.500
00:16:30.700
Now I am going to do stop action.

00:16:31.100
00:16:34.700
Turn off see the output.

00:16:36.200
00:16:40.100
So stopping ec2 instances running
right now see here if you
00:16:40.100
00:16:45.200
refresh it it is going to stop your first
instance right

00:16:45.200
00:16:47.800
now because this is for Loop it will
take one by one.

00:16:51.400
00:16:53.900
Then once it is come here first task is
done.

00:16:54.200
00:16:56.300
This is the information about your first
instance.

00:16:56.700
00:17:00.700
Once it is done then it will go and do
second server because

00:17:00.700
00:17:02.200
we have given weight as yes.

00:17:03.600
00:17:06.098
If you remove it as is then it will go
sequence.

00:17:12.098
00:17:13.800
Yes, stop now done C.

00:17:13.800
00:17:16.700
Finally you change the word task,
right?

00:17:16.700
00:17:18.000
This is for second server.

00:17:18.000
00:17:20.800
And this is for first server, right?

00:17:20.800
00:17:23.500
So now if I want to start it, yes, I can
start it.

00:17:27.598
00:17:37.500
now starting ec2 instance So once it is
up and running then

00:17:37.500
00:17:38.599
I will go to next server.

00:17:38.700
00:17:39.500
Just wait here.

00:17:43.900
00:17:47.400
Done just refresh it and see that this is
running now.
00:17:47.400
00:17:48.500
It is going to Second.

00:17:48.900
00:17:50.400
So it is working on second server now.

00:17:55.800
00:17:58.000
Once it is done, then it is also over.

00:17:59.500
00:18:00.000
That's it.

00:18:01.200
00:18:05.000
So guys here to start and stop right in
case if you don't

00:18:05.000
00:18:07.800
have any dependencies between two
servers or whatever you

00:18:07.800
00:18:10.700
are doing right you can remove weight
as yes.

00:18:11.800
00:18:15.900
Right fine now finally, I want to
terminate my is two instances.

00:18:22.200
00:18:24.600
Turn meeting is to instance task is
executing.

00:18:25.900
00:18:29.000
So guys here you need to understand
that we are not providing

00:18:29.000
00:18:31.300
instance IDs directly to your playbook.

00:18:31.500
00:18:35.900
We are able to identify through logic
your required instance

00:18:35.900
00:18:38.900
IDs. So that logic is based on tags.

00:18:39.100
00:18:42.900
So you need to understand how we
are using tags to identify

00:18:42.900
00:18:44.300
your instance IDs.

00:18:45.300
00:18:47.700
Right, if you're able to understand that
then you're good

00:18:47.700
00:18:48.700
with this task.
00:19:01.100
00:19:03.400
First one is terminated now.

00:19:03.400
00:19:04.700
It's working on second server.

00:19:04.700
00:19:04.900
Yes.

00:19:04.900
00:19:05.500
It's done.

00:19:05.600
00:19:08.300
Now your playbook also done, right?

00:19:08.500
00:19:15.000
So just observe that simply finally our
Playbook, this is

00:19:15.000
00:19:20.100
the Playbook right simple Playbook to
start and stop on the

00:19:20.100
00:19:23.100
rental unit your ec2 instances based
on your tags.

00:19:24.600
00:19:25.100
Right.

00:19:26.000
00:19:26.700
Okay guys.

00:19:28.100
00:19:29.400
This is all about the bar.

00:19:31.000
00:19:34.200
Simple single Playbook to start and
stop and turn Matisse

00:19:34.200
00:19:36.000
to instances based on tags.

00:19:36.300
00:19:39.300
So not only based on tags guys
suppose if I want to start

00:19:39.300
00:19:45.300
a stop or restart based on suppose
some security groups or

00:19:45.300
00:19:47.900
based on some availability Zone.

00:19:49.100
00:19:50.300
Right, you can do that.

00:19:50.700
00:19:53.100
The only thing you need to apply filters
concept there.
00:19:54.500
00:19:57.200
So what is your requirement based on
the unit of ply your

00:19:57.200
00:19:59.500
filters so that you can achieve your
required task?

00:20:00.000
00:20:00.400
Okay.

00:20:00.800
00:20:01.400
Okay guys.

00:20:01.500
00:20:02.900
Thank you for watching this video.
Transcript
00:00:00.009
00:00:04.730
[no audio] Cleaning up tagless EC2
instances with ansible.

00:00:04.730
00:00:07.864
I mean with playbook, right?

00:00:07.864
00:00:10.355
So this is the concept we are going to
discuss here.

00:00:10.355
00:00:16.346
Okay, let me connect with my host
where I'm having my ansible controller.

00:00:16.346
00:00:21.758
Yes, let me switch into ans, admin
user.

00:00:21.758
00:00:25.898
[no audio]

00:00:25.898
00:00:29.500
Let me switch into AWS cloud
directory.
00:00:29.500
00:00:35.062
So, here we are having all playbooks,
whatever we are doing, right? Fine.

00:00:35.062
00:00:43.900
Guys, now our requirement is, first off
let me open my ec2, sorry AWS console.

00:00:43.900
00:00:49.610
If you observe here very first two
instances, no tags.

00:00:49.610
00:00:50.883
Right, see here,

00:00:50.883
00:00:54.704
for this also, there are no tags
available for these instances.

00:00:54.704
00:01:01.230
Now, my concept is, I want to delete
the instances which are not having any tags,

00:01:01.230
00:01:03.853
then how you can delete them.

00:01:03.853
00:01:04.798
Right?

00:01:04.798
00:01:07.390
So guys, let me start our playbook,

00:01:07.390
00:01:09.801
and before going to write this play
book,

00:01:09.800
00:01:16.444
see already, we have simple concept
to get AWS instance facts.

00:01:16.444
00:01:19.280
Right? I hope it is there with the var

00:01:19.280
00:01:25.502
seventh, right?

00:01:25.502
00:01:28.290
Yes, this is the information I want to
need.

00:01:28.290
00:01:32.143
Let me write it.

00:01:32.143
00:01:37.827
So, this playbook number is, nine.

00:01:37.827
00:01:40.884
So, nine,
00:01:40.884
00:01:49.960
cleanup, tagless instances . yml

00:01:49.960
00:01:54.622
Fine? So here we are going to
terminate the instances.

00:01:54.622
00:02:01.593
This play is used to terminate ec2
instances,

00:02:01.593
00:02:08.324
which are not having any tags. Fine?

00:02:08.324
00:02:09.400
Info?

00:02:09.400
00:02:11.300
Yes, we are getting information.

00:02:11.300
00:02:17.200
So, I'm not going to take filter because
I need to find out

00:02:17.200
00:02:18.513
the tags now.

00:02:18.513
00:02:21.883
Right, see how I'm going to find them.

00:02:21.800
00:02:26.700
First of all, what the other information I
am fetching.

00:02:26.700
00:02:30.615
I mean facts using your ec2 instance
facts module.

00:02:30.615
00:02:38.290
Just I want to display, so displaying
facts. Right?

00:02:38.290
00:02:39.786
You have debug module.

00:02:39.786
00:02:41.037
Let me first debug them.

00:02:41.037
00:02:48.046
So var=ec2 underscore info, right?

00:02:48.046
00:02:57.274
Let me check it for any syntax errors,
ansible playbook,

00:02:57.274
00:03:06.019
- - syntax check. Yes, it's good.
00:03:06.019
00:03:08.916
Now, let me run this and see the
output first.

00:03:08.916
00:03:12.133
[No audio]

00:03:12.133
00:03:14.919
See these, you're getting some
instances information.

00:03:14.919
00:03:18.000
So, actually are having three
instances you're getting information

00:03:18.000
00:03:19.551
for all three instances.

00:03:19.551
00:03:25.006
So, this is your variable, what you are
using to capture your facts,

00:03:25.006
00:03:27.920
So, in that instance is a key,

00:03:27.920
00:03:31.597
in that key, if you observe, just come
down,

00:03:31.597
00:03:35.113
[No audio]

00:03:35.113
00:03:38.090
still you need to come down.

00:03:39.090
00:03:41.039
Yes, up to this.

00:03:41.039
00:03:42.641
This is for one instance.

00:03:42.641
00:03:46.642
If you observe here, one instance is
having tags as name ansible controller.

00:03:46.642
00:03:50.825
Actually, this is our localhost, then if
you come from here,

00:03:50.800
00:03:54.829
just come down and see, actually are
having three instances,

00:03:54.829
00:03:56.200
those three instances information,

00:03:56.200
00:03:57.120
you have to get here.
00:03:57.120
00:03:59.390
Yes, yes.

00:03:59.390
00:04:03.811
Yeah, up to this one more instance.

00:04:03.811
00:04:09.843
Right, no up to this.

00:04:09.843
00:04:12.679
Yeah, we miss somewhere.

00:04:12.679
00:04:15.934
Anyway, last instance having tags as
there are no tags.

00:04:15.934
00:04:19.124
Over here the information is nothing,
right?

00:04:19.124
00:04:23.399
So let me go somewhere up and you
will find one more instance

00:04:23.399
00:04:24.671
tags, here.

00:04:24.671
00:04:29.361
No tags. So no tag in sensor two, or
here.

00:04:29.361
00:04:32.641
Now, I want to display only these two
instances.

00:04:32.641
00:04:36.100
So, before going to terminate, let me
take some care whether

00:04:36.100
00:04:39.261
I am going to work with correct logic or
not.

00:04:39.261
00:04:39.900
Right?

00:04:40.100
00:04:43.141
See, I am going to do something.

00:04:43.141
00:04:50.681
So, first of all to take one by one, right,
let me comment this.

00:04:50.681
00:04:56.721
Yeah, I want to display right, let me...
fine.

00:04:56.721
00:05:00.293
Now I am going to display with Loop.
00:05:00.293
00:05:03.743
With items.

00:05:03.743
00:05:08.854
So, what is my variable? ec2_ info.

00:05:08.854
00:05:12.045
Info is going to take instances.

00:05:12.045
00:05:17.157
Right, so I am going to write simply
here, item.

00:05:17.157
00:05:22.001
So, I need, along with your item, tags.

00:05:22.001
00:05:24.352
For each instance, I need tags.

00:05:24.352
00:05:27.993
Tags is one of the key, for your each
instance.

00:05:27.993
00:05:29.744
Right? Fine.

00:05:29.744
00:05:33.805
First, let me run this and see the
output, you will get same output.

00:05:33.800
00:05:36.000
[No audio]

00:05:35.700
00:05:38.671
Yes, tags values are empty.

00:05:38.671
00:05:42.312
Now, I'm going to write simple logic
before going to display.

00:05:42.312
00:05:44.213
What I have to check is,

00:05:44.213
00:05:49.474
Let me write this, when:

00:05:49.474
00:05:56.535
I need to check out the length of your
tags keys,

00:05:56.535
00:06:02.128
If length of the tag keys, right, if it is
equals to zero,

00:06:02.128
00:06:07.119
so, your each instance information
item in that you are having tags,

00:06:07.119
00:06:09.111
So, in that, you have to check for keys.
00:06:09.111
00:06:12.800
So, this is the directory operation, so
you can easily understand

00:06:12.800
00:06:14.251
if you know the directories of python.

00:06:14.251
00:06:21.191
So for that, I am checking length and if
it is equal to zero,

00:06:21.191
00:06:23.211
I want to display only those instances.

00:06:23.211
00:06:26.252
Right? Now see, I'm going to run it.

00:06:26.252
00:06:28.773
[No audio]

00:06:28.773
00:06:30.828
One, right.

00:06:30.828
00:06:32.810
Let me come up.

00:06:32.810
00:06:37.020
So, this is first instance information.

00:06:37.020
00:06:43.630
This is one more instance information,
up to this part, right?

00:06:43.630
00:06:48.010
See one instance very first instance is
skipping because

00:06:48.010
00:06:50.232
it is having some tags.

00:06:50.232
00:06:52.500
That's why it is skipping that first
instance, and it is going

00:06:52.500
00:06:54.412
to display for remaining two instances.

00:06:54.412
00:06:54.800
Yes.

00:06:54.800
00:06:59.160
Now you are perfect to capture your
required instances with your logic.

00:06:59.160
00:07:03.600
But now, I want to delete my ec2
instance. To delete your ec2 instance,
00:07:03.600
00:07:05.859
you have to use your ec2 module,
right?

00:07:05.859
00:07:10.733
ec2 module and, while deleting your
instances you need instance ID's.

00:07:10.733
00:07:15.574
So, this is the instance ID key you are
having in your output

00:07:15.574
00:07:19.300
See for that, and this is the first
second instance.

00:07:19.300
00:07:22.245
Now see that how I am going to write
this logic.

00:07:22.245
00:07:26.793
So, now I don't want to display, I have
to do action called...

00:07:26.101
00:07:29.501
Now instead of name,

00:07:29.501
00:07:35.543
right, so let me come in here.

00:07:35.543
00:07:37.631
Yeah, either way.

00:07:37.631
00:07:43.283
[No audio]

00:07:43.283
00:07:47.498
Name. So terminating ec2 instances.

00:07:47.498
00:07:51.173
[No audio]

00:07:51.173
00:07:57.395
Instances. Right? So in that ec3
module.

00:07:57.395
00:08:02.300
So in that ec2 module, ok, you need
region name.

00:08:02.400
00:08:04.800
So of course I am going to work with
the us east-1

00:08:05.100
00:08:06.500
You can also verifies this,

00:08:08.300
00:08:14.340
and I need, instance IDs, right?
00:08:14.340
00:08:16.000
See if you want to delete your
instance.

00:08:16.000
00:08:17.400
You should have your instance ID.

00:08:17.400
00:08:21.400
Otherwise you cannot delete, so if
how you'll get your instance ID

00:08:21.400
00:08:25.193
So item, you know item you are
getting right,

00:08:25.193
00:08:28.300
from your item. All right.

00:08:28.900
00:08:30.600
So this is for each instance.

00:08:30.700
00:08:33.900
There is a variable called I copied I
think,

00:08:33.900
00:08:36.500
yeah instance ID. From output.,

00:08:36.500
00:08:38.940
I copied that key instance ID.

00:08:38.940
00:08:43.900
Right, now you are ready to run your
playbook to terminate your ec2

00:08:43.900
00:08:47.809
instances, which are having tags
length as zero.

00:08:47.809
00:08:49.865
Now, let me run this.

00:08:49.865
00:08:53.107
[No audio]

00:08:53.100
00:08:54.039
See the output.

00:08:54.039
00:08:57.372
First part is skipping.

00:08:57.372
00:09:01.700
What is happening for second one, is
doing something.

00:09:01.700
00:09:02.850
Let me check it.

00:09:02.850
00:09:10.331
[No audio]
00:09:10.331
00:09:17.032
Image, message parameter is
required for new instance.

00:09:17.032
00:09:22.000
Any syntax, or, maybe I missed
something.

00:09:22.000
00:09:23.073
Let me check it.

00:09:23.073
00:09:28.784
So sorry, we need to write state, right,
state.

00:09:28.784
00:09:36.914
State. State is absent to terminate
your ec2 instances, right?

00:09:36.914
00:09:44.576
Now first is skipping, second two
instance are terminated, see?

00:09:44.576
00:09:49.200
First part is skipping, you know, you
can see here information

00:09:49.200
00:09:53.400
skipping second two instance of
change means let me go and

00:09:53.400
00:09:55.933
refresh my console, see as of now,
they are running,

00:09:55.933
00:10:00.000
now if I refresh it, they're going to
terminate - shutting down,

00:10:00.000
00:10:01.510
after some time they will terminate.

00:10:01.510
00:10:06.653
Right? Yes, terminated.

00:10:06.653
00:10:10.534
So, guys this is the simple way how
you can clean up or terminate

00:10:10.534
00:10:13.939
your ec2 instances which are having
no tags.

00:10:13.939
00:10:15.000
Right?
00:10:15.000
00:10:18.132
So cleaning up tagless ec2 instances
with ansible.

00:10:18.132
00:10:19.334
Okay?

00:10:19.334
00:10:20.400
Okay guys.

00:10:20.500
00:10:21.400
Thank you for watching this.
Transcript
00:00:00.000
00:00:02.900
So what is the CSV report?

00:00:03.900
00:00:06.600
Suppose I have a small requirement

00:00:06.600
00:00:09.500
that I need to generate some file.

00:00:09.500
00:00:11.300
Of course that is a CSV file.

00:00:12.200
00:00:17.600
So on my requirement is, whatever the
instance I'm having

00:00:17.700
00:00:25.100
in one region, for those instances, I
need to export the

00:00:25.100
00:00:31.100
data of instances like instance ID,
image ID, and I suppose,

00:00:31.100
00:00:33.500
the security group I'm using.

00:00:33.500
00:00:37.600
What is the key I'm using for that?
00:00:39.000
00:00:41.600
What are the tags available for that
instance?

00:00:42.200
00:00:46.600
So this information, for each and every
instance,

00:00:47.100
00:00:50.700
I want to export into CSV and I want to
share with an audit

00:00:50.700
00:00:53.200
team. Right?

00:00:53.200
00:00:58.100
So for something like that, how you
can write a playbook to generate your

00:00:58.100
00:01:00.800
CSV file based on your requirement?

00:01:01.500
00:01:03.100
So that's what we are going to discuss
here.

00:01:04.900
00:01:06.599
Okay, let me go and start it.

00:01:06.599
00:01:09.800
So to start this let me connect with my
EC2 instance.

00:01:10.200
00:01:13.500
This is our local instance where we
have ansible controller

00:01:14.100
00:01:18.000
and we know that we are going to use
ansadmin user, right?

00:01:20.600
00:01:23.400
And let me enter into my database
cloud directory.

00:01:25.600
00:01:29.600
Now here I am going to write some
simple script.

00:01:29.600
00:01:33.300
Before writing your script, see in our
previous

00:01:33.600
00:01:34.600
classes,
00:01:34.900
00:01:39.300
we've seen the concept called EC2
instance

00:01:39.300
00:01:40.900
facts, right?

00:01:40.900
00:01:43.100
So this is the helpful thing for us as of
now.

00:01:43.400
00:01:44.700
Let me take something.

00:01:46.600
00:01:50.600
Let me copy this. Now I am going to
create

00:01:52.100
00:01:54.800
Vi8 playbook, right?

00:01:56.100
00:02:07.200
Generate a CSV report. For that, I am
going to create some yml

00:02:07.200
00:02:08.900
file, I mean playbook.

00:02:09.900
00:02:11.199
Let me copy and paste it.

00:02:11.400
00:02:14.300
This play is used to fetch instances
info.

00:02:14.300
00:02:16.500
Yes, localhost connection gather facts.

00:02:17.400
00:02:19.300
So gather facts false.

00:02:20.500
00:02:23.500
Info about ec2 instances using facts,
right?

00:02:23.700
00:02:25.900
So region I'm using suppose EC u.s.

00:02:25.900
00:02:29.100
East 1 and I am going to capture this
output.

00:02:29.900
00:02:31.600
So for that you need to use register,
right?

00:02:31.700
00:02:33.200
Let me take simply out.
00:02:33.500
00:02:37.400
So as of now, I am not going to write
time in Playbook to

00:02:37.400
00:02:38.900
generate your CSV instead of that.

00:02:38.900
00:02:40.800
Just I'm trying to display the
information.

00:02:42.000
00:02:49.700
info let me take I will take filters.

00:02:51.700
00:02:56.700
Filters as let me take tag, so let me go
with my console

00:02:56.900
00:03:02.900
tag is really key is EnV and value is
test so e and V value

00:03:02.900
00:03:11.000
is test right so displaying the fetch info.

00:03:14.800
00:03:24.200
you think the info of ec2 instances so
as here, you'll have

00:03:24.200
00:03:27.800
a lot of details about your each and
every instance.

00:03:27.800
00:03:30.600
So as of now just I'm trying to display
directly all the

00:03:30.600
00:03:33.200
values of your all instances, whatever
the instances are

00:03:33.200
00:03:39.500
having a party tag values as key key
value as environment

00:03:39.500
00:03:41.400
and value as test, right?

00:03:41.800
00:03:44.100
So let me first check my syntax check.

00:03:48.600
00:03:49.700
Okay, everything is fine.

00:03:49.700
00:03:49.900
Now.
00:03:49.900
00:03:52.100
I'm going to write just observe the
output first.

00:03:53.300
00:03:56.400
So guys here actually you are having
two instances.

00:04:00.600
00:04:02.300
So this is second instance.

00:04:03.500
00:04:05.500
And you have first instance
information here.

00:04:05.900
00:04:09.800
So why you got only 2 mins If You
observe here for this instance

00:04:09.900
00:04:13.700
in tag you're having key as EnV and
value as test same way

00:04:13.700
00:04:14.700
second instance.

00:04:15.000
00:04:16.300
We're having same information.

00:04:16.300
00:04:19.100
But if you go with the third instance,
this is different.

00:04:19.100
00:04:23.500
That's why we are filtering only these
two instances, right?

00:04:23.500
00:04:23.800
Yes.

00:04:23.800
00:04:24.500
We got it.

00:04:24.500
00:04:24.800
Now.

00:04:24.800
00:04:27.700
My requirement is from this
information.

00:04:27.700
00:04:30.100
I need to generate on second.

00:04:30.100
00:04:31.300
I will open my Notepad.

00:04:40.200
00:04:43.000
So I need to write some CSV file, but
the CSV should be like
00:04:43.000
00:04:44.700
in this way serial number.

00:04:47.100
00:04:56.000
instanceid suppose then image ID
suppose key name but all

00:04:56.000
00:04:57.700
the key you are using p.m.

00:04:57.700
00:04:58.200
Key name.

00:04:58.200
00:05:00.000
I want to so likewise.

00:05:00.000
00:05:03.200
You can capture any number of values
based on your requirement

00:05:03.200
00:05:04.500
for each and every instance.

00:05:04.500
00:05:06.500
So as of now, I am going with simple
way.

00:05:07.000
00:05:09.900
So these three parameters I want to
capture for each and

00:05:09.900
00:05:12.800
every instance and I want to store this
information into

00:05:12.800
00:05:13.700
a CSV file.

00:05:17.000
00:05:18.200
See what I'm doing.

00:05:19.700
00:05:24.200
first thing let me enter into your
playbook.

00:05:25.500
00:05:28.500
So guys the information about your
each and every instance

00:05:28.500
00:05:31.600
is there with the resistor output
variable.

00:05:31.700
00:05:34.400
I mean, we raised our right without
variable in this your
00:05:34.400
00:05:37.900
entire information is there for each and
every variable for

00:05:37.900
00:05:39.000
each and every instance.

00:05:39.800
00:05:43.000
Now, what I am doing is just I'm using
here template concept.

00:05:44.100
00:05:45.300
Let me write something.

00:05:46.700
00:05:58.200
template so for template I'm taking
source as generate CSV

00:05:58.200
00:06:01.000
dot G2 and destination.

00:06:01.100
00:06:10.100
I am giving ec2 instances info dot CSV
Right now I will go

00:06:10.100
00:06:14.500
and write template for this such that
this template will

00:06:14.500
00:06:17.900
generate your CSV file and this
template we use variable

00:06:17.900
00:06:23.700
as out right fine get before going to
that into understand

00:06:23.700
00:06:24.800
from your output guys.

00:06:27.200
00:06:28.400
Okay, I will do one thing.

00:06:28.500
00:06:31.000
Let me show your output.

00:06:31.000
00:06:31.300
Yeah.

00:06:34.000
00:06:39.700
for time being I will do one thing just
wait, so I'm going

00:06:39.700
00:06:43.900
to use debug itself as of now because
I need to show first

00:06:43.900
00:06:45.900
output. Let me copy this values.
00:06:52.500
00:06:57.600
so lonely bug you're very close to out
from this audience

00:06:57.600
00:06:58.500
understand something.

00:06:59.000
00:07:01.500
Let me first show that required things.

00:07:05.800
00:07:09.200
Money to save this values and already
we have written code

00:07:09.200
00:07:10.900
right fight now guys.

00:07:10.900
00:07:13.600
If You observe in the output, this is a
map.

00:07:13.600
00:07:16.900
Basically you're out is a map because
of this curly braces

00:07:17.200
00:07:18.200
from this out.

00:07:18.200
00:07:19.400
You are required information.

00:07:19.400
00:07:21.100
Is there under instances key.

00:07:22.400
00:07:26.900
Under instances If You observe you
have different keys, right

00:07:26.900
00:07:31.600
like instant image ID instance ID
suppose key name, right.

00:07:32.100
00:07:35.700
So all these informations you need to
take one by one how

00:07:35.700
00:07:37.000
you can do this for that.

00:07:37.000
00:07:40.200
We are going to write simple template
right?

00:07:40.300
00:07:42.700
So now I'm going to modify our
Playbook.

00:07:47.800
00:07:49.100
Let me copy this code.
00:07:50.600
00:07:53.200
And let me paste it here fine.

00:07:54.100
00:07:54.400
Now.

00:07:54.400
00:07:57.500
I need to write some simple Ginger
template such that that

00:07:57.500
00:08:00.500
template will generate you are
required information.

00:08:00.800
00:08:02.400
I mean your CSV file.

00:08:03.700
00:08:06.600
So first guys, I need serial number.

00:08:06.600
00:08:09.300
I mean first server second server
thoughts are were right.

00:08:09.400
00:08:12.500
So if You observe you are so here, I
need to write suppose

00:08:12.500
00:08:15.300
for server information second server
third server.

00:08:16.200
00:08:20.300
So for that I'm going to take initialise
one constant variable.

00:08:20.800
00:08:23.700
So guys in ginger template if you want
to Define any variable

00:08:23.700
00:08:26.300
or Loops or any syntax has always
you have to start curly

00:08:26.300
00:08:27.700
braces and percentile.

00:08:28.700
00:08:32.900
Then set I am writing serial number
equals to initially one.

00:08:32.900
00:08:36.299
I am writing then close that variable
declaration.

00:08:37.100
00:08:40.900
Now, I want to take one by one
instances information from
00:08:40.900
00:08:44.900
your out variable which is generated
by your ansible playbook

00:08:45.700
00:08:49.100
with the help of ec2 instance facts,
because out variable

00:08:49.100
00:08:54.100
we are using to store output of your
ec2 instance facts now

00:08:54.100
00:08:54.700
from that.

00:08:54.700
00:08:57.100
I need to take one by one that means I
need to use for Loop

00:08:57.100
00:09:03.500
here. Right, so I am going to use for
each in your out dot

00:09:03.900
00:09:08.600
instances. Right in that instances you
are having different

00:09:08.600
00:09:10.600
instances information for each time.

00:09:10.600
00:09:13.200
You are going to get one instance with
the help of this for

00:09:13.200
00:09:17.100
Loop, right and one more thing before
going to write my information.

00:09:17.100
00:09:21.200
I want to write the CSV information in
this way serial number.

00:09:23.100
00:09:31.800
instance ID then image ID and
suppose we are going to work

00:09:31.800
00:09:32.900
with key named as well.

00:09:33.000
00:09:37.900
So these are the Fields of my CSV file
fine.

00:09:38.100
00:09:39.300
So very first thing is serial.
00:09:39.300
00:09:42.800
Number your serial number will is
there inside of your variable

00:09:42.800
00:09:45.700
called right cereal on the score
number?

00:09:47.700
00:09:51.200
Fine, next I want to write instance ID.

00:09:51.300
00:09:55.000
So guys in this each you have your
information about your

00:09:55.000
00:09:55.800
each instance.

00:09:55.800
00:10:00.000
So from that you need to get very first
time instanceid,

00:10:01.100
00:10:03.200
right? I want to write this information to
file.

00:10:03.200
00:10:06.000
So whenever if you want to write any
variable value or text

00:10:06.200
00:10:10.000
into file So if it is information straight
forward you have

00:10:10.000
00:10:10.700
to write in this way.

00:10:10.700
00:10:13.100
If it is a variable you have to write
curly braces such that

00:10:13.100
00:10:16.800
the variable value will store interior
destination location.

00:10:18.600
00:10:23.500
Then next thing you need the from,
uh, you need image idea

00:10:23.500
00:10:24.000
as well.

00:10:25.200
00:10:25.600
Right.

00:10:25.800
00:10:30.900
So after that you need from each you
are key name as well.
00:10:31.200
00:10:32.700
So these are the fields you are taking.

00:10:34.300
00:10:39.000
Fine, so guys this first for Loop will
take one instance

00:10:39.000
00:10:41.900
information from here, and it will write
that information

00:10:41.900
00:10:43.800
to destination with this format.

00:10:44.000
00:10:46.700
So after that violating second instance
information, I need

00:10:46.700
00:10:49.800
to change my serial number 122.

00:10:49.800
00:10:50.800
I want to change.

00:10:51.800
00:10:52.200
All right.

00:10:52.200
00:10:56.800
So if you want to change value from 1
to 2, so what you have

00:10:56.800
00:11:00.800
to do is, you know to increase your
value, right?

00:11:00.900
00:11:07.800
So to increase your value But Me
Right percentile set your

00:11:07.800
00:11:13.400
serial number equals to serial number
plus one.

00:11:15.100
00:11:15.500
Right.

00:11:15.500
00:11:20.100
So cereal underscore number one.

00:11:21.500
00:11:23.000
Then close that percentage.

00:11:24.500
00:11:26.400
That's her right now.

00:11:26.400
00:11:29.200
Let me go and run it so before going to
run.
00:11:29.600
00:11:31.900
Let me see your file first.

00:11:31.900
00:11:32.800
This is your file.

00:11:32.800
00:11:36.500
It is going to generate easy to info it is
easy to instance

00:11:36.700
00:11:40.500
info dot CSV now see that we don't
have any CSV file here.

00:11:40.800
00:11:41.100
Now.

00:11:41.100
00:11:45.500
I am going to run our Playbook this
one now see the output

00:11:45.500
00:11:46.700
what you are going to get it.

00:11:49.500
00:11:50.500
Template errors.

00:11:50.900
00:11:52.600
Yeah, got it.

00:11:54.800
00:11:55.700
So we did a mistake.

00:11:55.700
00:11:58.400
That is actually we need to provide
some space here.

00:12:18.700
00:12:29.700
template errors pulse no innermost
block that oh, sorry.

00:12:29.700
00:12:31.900
We need to close for Loop.

00:12:39.400
00:12:43.500
and for Loop that's it.

00:12:48.000
00:12:48.300
Okay.

00:12:48.300
00:12:51.000
Now it's going to just get sad he has
been generated right

00:12:51.100
00:12:51.800
now see that.

00:12:56.200
00:12:59.600
This information if you open that what
you are getting C
00:13:00.200
00:13:03.900
serial number and you are getting this
entire information.

00:13:07.200
00:13:11.300
So intense ID maybe image ID is
same but inside is different.

00:13:12.500
00:13:14.100
Rights, actually while launching this
instance.

00:13:14.100
00:13:18.200
I use Army as the side is also you are
getting same ID right

00:13:18.200
00:13:21.800
now what you have to do if you see
guys if we generate any

00:13:21.800
00:13:24.900
information in terms of CSV, and if you
open that CSV file

00:13:24.900
00:13:27.900
in by using Excel sheet automatically,
your data will be

00:13:27.900
00:13:30.000
rearranged that is the advantage with
CSV.

00:13:30.300
00:13:32.300
So that's why most of the cases in
your real time.

00:13:32.300
00:13:35.100
You're going to generate reports as in
terms of CSV.

00:13:36.600
00:13:39.800
So if you want to verify that I will do
one thing I will

00:13:39.800
00:13:42.500
download that into my Windows host
there.

00:13:42.500
00:13:45.000
I will open in terms of Excel sheet.

00:13:45.900
00:13:49.000
Let me do one thing so I am going to
copy this.
00:13:51.600
00:13:57.400
Ec2 instances in for two home ec to
use are there I am going

00:13:57.400
00:13:59.200
to copy it now.

00:13:59.200
00:14:09.700
Let me easy two right Yes, now, let me
give the execution

00:14:09.700
00:14:12.400
pom or sorry all permissions for this so
that I can download

00:14:12.400
00:14:21.000
this. Right.

00:14:21.200
00:14:26.100
Now if You observe for this file or
having all file permissions

00:14:26.100
00:14:30.100
now hard I will do is I will exit from
here now.

00:14:30.100
00:14:32.200
I am going to use SCP - hi.

00:14:32.300
00:14:40.200
Otherwise, I will do this thing SCP - I
yes, so from here,

00:14:40.800
00:14:41.900
this is the file.

00:14:42.200
00:14:45.700
I am going to generate into I'm going
to download it into

00:14:46.100
00:14:47.200
my Local Host.

00:14:52.200
00:14:54.000
Yes, it has been downloaded.

00:14:54.000
00:14:54.200
Now.

00:14:54.200
00:14:55.900
Let me open my window already.

00:14:55.900
00:14:57.500
We are in desktop itself, right?

00:14:57.600
00:14:58.500
Let me run this.

00:15:00.700
00:15:02.100
Let me run this file.
00:15:02.400
00:15:04.100
Yes it is there now.

00:15:04.300
00:15:07.400
If I open sea same content, you're
having whatever you got

00:15:07.400
00:15:08.300
from your playbook.

00:15:08.700
00:15:11.100
Now, this is there on my desktop now.

00:15:11.100
00:15:14.600
I'm going to open this with Excel
sheet.

00:15:19.300
00:15:21.600
Just close it see that.

00:15:23.000
00:15:26.000
Forgetting your information exactly
now in case if you want

00:15:26.000
00:15:28.900
to I mean format it you can format it.

00:15:30.100
00:15:32.800
And once you have this data, you can
share this with your

00:15:32.800
00:15:33.600
audit team.

00:15:40.800
00:15:43.900
Just decorate if you need.

00:15:45.300
00:15:45.900
That's it.

00:15:50.400
00:15:50.800
So guys.

00:15:50.800
00:15:57.700
This is the simple way how you can
generate your Report into

00:15:57.700
00:15:58.900
CSV format.

00:15:59.500
00:16:02.900
So this is very very important in your
real time for audit

00:16:02.900
00:16:04.900
purposes, right?
Transcript
00:00:00.000
00:00:01.600
Friends, here

00:00:01.600
00:00:05.600
our concept is ansible world see
basically the ansible world

00:00:05.600
00:00:10.209
is useful to encrypt your playbooks
including roles and variables,

00:00:10.200
00:00:13.810
but why we need to include playbooks
very simple.

00:00:13.800
00:00:17.600
We know that we are using ansible for
automation and while

00:00:17.600
00:00:19.910
implementing playbooks for your
automation.

00:00:19.900
00:00:23.900
There is a possibility that some
playbooks can contain credentials
00:00:23.900
00:00:27.910
or SSL certificates information or any
other sensitive data

00:00:27.900
00:00:31.600
now saving search since to data. As a
plain text is a bad

00:00:31.600
00:00:36.900
idea because one wrong commit to
GitHub or laptop theft can

00:00:36.900
00:00:40.309
cause an organization huge loss.

00:00:40.300
00:00:42.500
Let me take a very simple example
suppose.

00:00:42.500
00:00:47.410
I have a playbook using that we can
launch AWS ec2 instance.

00:00:47.400
00:00:50.700
And if you observe my playbook in my
playbook somewhere I

00:00:50.700
00:00:54.910
provided my AWS account access
keys.

00:00:54.900
00:00:59.410
No, I assume that if I commit this
playbook to my GitHub

00:00:59.400
00:01:02.100
suppose my GitHub is public
repository.

00:01:02.200
00:01:05.700
Then anybody can get my access
keys and they can access my

00:01:05.700
00:01:07.510
AWS account.

00:01:07.500
00:01:11.700
It is danger for me or assume that you
are working with an

00:01:11.700
00:01:14.100
organization. Anyway in organization

00:01:14.100
00:01:17.110
we are using private repositories.
00:01:17.100
00:01:24.110
Now if you commit this playbook into
GitHub or any repository

00:01:24.100
00:01:30.110
other team members can access your
team AWS account credentials.

00:01:30.100
00:01:33.500
Right, so that's why whenever you
have some sensitive data

00:01:33.500
00:01:38.300
in your playbook, instead of commit
your playbook as a plain

00:01:38.300
00:01:42.000
text we can encrypt this playbook and
we will commit that

00:01:42.000
00:01:46.910
playbook so that nobody can see your
playbook information.

00:01:46.900
00:01:50.200
Until unless if they know what is the
password you use to

00:01:50.200
00:01:52.700
encrypt this using your ansible vault.

00:01:52.700
00:01:55.010
[no audio]

00:01:55.000
00:02:02.410
Right so simply we need a way to
store secret securely.

00:02:02.400
00:02:07.800
So ansible vault is the answer to this
and ansible vault can

00:02:07.800
00:02:11.900
encrypt anything inside of a mail file
using a password of

00:02:11.900
00:02:13.609
your choice.

00:02:13.600
00:02:18.300
So while encrypting your playbooks
you can select your required

00:02:18.300
00:02:21.300
password to encrypt your data and
you have to remember that
00:02:21.300
00:02:25.109
password to decrypt your playbook.

00:02:25.100
00:02:28.510
Now, let me go with your playbook.

00:02:28.500
00:02:29.800
So suppose first.

00:02:29.800
00:02:33.510
I will run this play book directly so that
I will show you

00:02:33.500
00:02:37.200
how this playbook is going to launch
an ec2 instance

00:02:37.200
00:02:41.609
See as of now.

00:02:41.600
00:02:49.600
your playbook Is a plain text now I am
running this ansible

00:02:49.600
00:02:51.810
- playbook.

00:02:51.800
00:02:55.510
Launch ec2 instance with keys.yml.

00:02:55.500
00:02:59.910
That is my playbook name just after
the output.

00:02:59.900
00:03:02.510
So it is going to connect with my AWS
account.

00:03:02.500
00:03:05.500
So there it is going to launch an ec2
instance.

00:03:05.500
00:03:07.400
Let me open my AWS account.

00:03:07.400
00:03:11.010
[no audio]

00:03:11.000
00:03:18.109
Let me refresh here. Yeah now it is
launching an ec2 instance.

00:03:18.100
00:03:19.300
That's fine. Now.

00:03:19.300
00:03:23.900
What I will do is the same playbook
now, I will encrypt using
00:03:23.900
00:03:25.709
ansible vault.

00:03:25.700
00:03:29.500
So first thing just check with your
ansible vault different

00:03:29.500
00:03:33.000
options. So these are the different
options.

00:03:33.000
00:03:35.000
You can perform using your ansible
var.

00:03:35.000
00:03:38.600
If you want to encrypt the existing
ansible file, you can

00:03:38.600
00:03:40.109
use encrypt option.

00:03:40.100
00:03:43.700
So whatever the encrypted using your
ansible vault that if

00:03:43.700
00:03:46.609
you want to decrypt because how to
use decrypt option.

00:03:46.600
00:03:49.400
So if you want to create a fresh file
with encrypted, then

00:03:49.400
00:03:52.109
you have to use ansible vault with
create option.

00:03:52.100
00:03:53.810
Let me go with one by one.

00:03:53.800
00:03:56.700
So first thing as of now, whatever the
playbook we have that

00:03:56.700
00:03:58.609
is plain text.

00:03:58.600
00:04:03.109
Now suppose I want to encrypt this
using ansible vault see

00:04:03.100
00:04:07.310
how we can do it simply ansible vault.

00:04:07.300
00:04:10.700
Encrypt then provide your playbook.
00:04:10.700
00:04:13.010
[no audio]

00:04:13.000
00:04:14.200
Now it is asking a password.

00:04:14.200
00:04:15.800
You have to remember this password
suppose.

00:04:15.800
00:04:18.600
If you forget this password, then you
cannot decrypt or you

00:04:18.600
00:04:21.810
cannot run this playbook using your
ansible.

00:04:21.800
00:04:25.899
Now, let me provide a password as
ansible and just confirm

00:04:25.899
00:04:32.300
it. Now our playbook has been
encrypted see now try to open

00:04:32.300
00:04:33.010
your playbook.

00:04:33.000
00:04:37.110
It has been encrypted now, it is not a
plain text.

00:04:37.100
00:04:39.500
Now if you want to see the content of
this playbook you have

00:04:39.500
00:04:42.600
to know what is the password you
have given while encrypting

00:04:42.600
00:04:45.900
this using your ansible world or if you
want to run this

00:04:45.900
00:04:47.300
playbook you have to know.

00:04:47.300
00:04:50.700
What is the password you have given
for this while encrypting

00:04:50.700
00:04:52.200
using your ansible vault.

00:04:53.900
00:04:57.300
No, let me run this play book directly
see whatever the encrypted
00:04:57.300
00:04:59.100
playbook you have that playbook
directly.

00:04:59.100
00:05:02.409
You can run without decrypting.

00:05:02.400
00:05:07.409
See as of now our playbook is
encrypted playbook.

00:05:07.400
00:05:10.010
I can directly run this play book and I
can launch my ec2

00:05:10.000
00:05:13.800
instance. Because the playbook
purposes previously we have

00:05:13.800
00:05:18.810
seen using this we are able to create
database ec2 instance.

00:05:18.800
00:05:22.900
Now so before launching before
running that playbook, let

00:05:22.900
00:05:25.510
me show you once again my editors
console.

00:05:25.500
00:05:30.310
So here I have only one ec2 instance
now.

00:05:30.300
00:05:35.210
Directly I am running my ansible
playbook encrypted playbook,

00:05:35.200
00:05:38.100
but before running just observe with
your ansible play

00:05:38.100
00:05:41.100
book. What are the available options
now?

00:05:41.100
00:05:44.610
If you see somewhere you are having
option for your playbook

00:05:44.600
00:05:48.610
as --ask-vault-pass.

00:05:48.600
00:05:51.500
So what I will do is directly first, I will
run my encrypted playbook.
00:05:51.500
00:06:05.000
[no audio]

00:06:05.000
00:06:06.211
Vault secrets found.

00:06:06.200
00:06:09.100
So you have to provide the password
whatever the password

00:06:06.840
00:06:06.409
Now see the output attempting to
decrypt but no

00:06:09.100
00:06:12.510
you have given while encrypting your
playbook that password

00:06:12.500
00:06:15.909
you have to provide while running your
ansible playbook.

00:06:15.900
00:06:19.200
So how we can provide that so we are
having an option called.

00:06:19.200
00:06:21.909
[no audio]

00:06:21.900
00:06:26.500
Let me show you that ansible
playbook - hatch the very first

00:06:26.500
00:06:31.310
option you are having - - akd-vault-
pass.

00:06:31.300
00:06:32.800
Now, let me run my playbook.

00:06:32.800
00:06:37.110
[no audio]

00:06:37.100
00:06:39.909
Now while running it will it will ask
vault password.

00:06:39.900
00:06:43.700
So whatever the password you have
given to encrypt this playbook

00:06:43.700
00:06:46.900
that password if you provide now your
ansible playbook will

00:06:46.900
00:06:48.610
execute your playbook.
00:06:48.600
00:06:51.500
Now, I have given password as
ansible now see that it is

00:06:51.500
00:06:55.300
running. So once it is completed then
automatically you are

00:06:55.300
00:06:59.610
new ec2 instance will come up with
your AWS.

00:06:59.600
00:07:04.110
Now, let me refresh it and see that.
That's it.

00:07:04.100
00:07:09.200
So in this way, you can encrypt your
existing playbooks now

00:07:09.200
00:07:11.610
suppose if I want to decrypt that
playbook.

00:07:11.600
00:07:19.110
Yes, we have an option called ansible
vault decrypt.

00:07:19.100
00:07:25.000
then just provide you are-- playbook
name now it is asking

00:07:25.000
00:07:27.900
password if you provide password
now, it has been decrypted

00:07:27.900
00:07:32.310
now see the playbook automatically it
has been decrypted.

00:07:32.300
00:07:34.310
That's it.

00:07:34.300
00:07:38.610
Now, not only playbook you can also

00:07:38.600
00:07:42.600
create any file which consists of
variables for your playbook.

00:07:42.600
00:07:48.100
Suppose instead of providing my
credentials in this playbook,

00:07:48.100
00:07:51.100
what I will do is this credentials I will
provide in one
00:07:51.100
00:07:56.300
file. See that you have given this now
this variables I will

00:07:56.300
00:07:57.300
use in my playbook.

00:07:57.300
00:07:58.600
I have one more playbook here.

00:07:58.600
00:08:02.600
I use in terms of variables my access
keys. Now here, you

00:08:02.600
00:08:04.800
now need to encrypt this playbook, but
you have to encrypt

00:08:04.800
00:08:08.100
this variable file because here you
have credentials now

00:08:08.100
00:08:12.610
you can also encrypt this file which
consists of variables.

00:08:12.600
00:08:15.409
Let me do that.

00:08:15.400
00:08:19.300
So I have f file in which I have my
variables.

00:08:19.300
00:08:24.110
I mean my access case in terms of
variables now instead of

00:08:24.100
00:08:28.000
encrypting your entire playbook what I
did I provided my

00:08:28.000
00:08:31.000
credentials into one file. Their I define
the variables now,

00:08:31.000
00:08:32.500
I will encrypt only this file.

00:08:32.500
00:08:41.510
Yes, you can do it so ansible vault
encrypt only this file

00:08:41.500
00:08:44.809
just remember the password. That's it.

00:08:44.799
00:08:49.900
Now see that only your aws_keys.yml
variable file has
00:08:49.900
00:08:51.799
been encrypted but your original file.

00:08:51.799
00:08:55.500
Is there as it is now, what I will do is I
will run this

00:08:55.500
00:08:57.310
playbook.

00:08:57.300
00:09:05.010
And see that ansible - playbook
launch ec2 instance with

00:09:05.000
00:09:06.010
from a file.

00:09:06.000
00:09:06.900
I mean variables.

00:09:06.900
00:09:08.900
I mean keys I define in a file right now.

00:09:08.900
00:09:13.700
Let me run the run that see it is
showing that attempting

00:09:13.700
00:09:17.510
to decrypt but no vault secrets found.

00:09:17.500
00:09:20.810
Anyway, this is plain text to file, right?

00:09:20.800
00:09:25.700
But whatever the variables you use
that variable file we

00:09:25.700
00:09:28.700
encrypted that's why he also you have
to provide you are.

00:09:28.700
00:09:32.310
[no audio]

00:09:32.300
00:09:41.200
-- ask-vault-pass. Sorry.

00:09:41.200
00:09:44.710
[no audio]

00:09:44.700
00:09:46.900
Now see that he's asking a password
now.

00:09:46.900
00:09:48.810
I have given that.

00:09:48.800
00:09:52.400
Now go to your AdWords account see
that it will launch new
00:09:52.400
00:09:56.410
instance. So now third instance is
coming.

00:09:56.400
00:09:58.000
That's it. That's fine.

00:09:58.000
00:10:02.400
So this is the way how we can encrypt
any playbook or a playbook

00:10:02.400
00:10:05.500
which consists of only variables. Okay.

00:10:05.500
00:10:09.600
Now we know two options from your
ansible vault they are like

00:10:09.600
00:10:14.300
encrypt and decrypt but we have
different options. Now.

00:10:14.300
00:10:15.600
Let me go with create option.

00:10:15.600
00:10:20.100
The very first option see actually
encrypt is used to encrypt

00:10:20.100
00:10:21.610
the existing playbook.

00:10:21.600
00:10:25.000
But if you want to create a playbook
directly in the encrypted

00:10:25.000
00:10:28.400
format, see I am going to create a new
playbook that should

00:10:28.400
00:10:29.600
be in the encrypted format.

00:10:29.600
00:10:35.210
Then you have to use ansible vault
create.

00:10:35.200
00:10:38.510
I'm creating demo.yml file.

00:10:38.500
00:10:43.710
I mean playbook so you have to
provide the password for this.

00:10:43.700
00:10:47.510
I am giving some ansible password
now see that editor is
00:10:47.500
00:10:49.600
open now create any playbook.

00:10:49.600
00:10:53.810
It may be a playbook which consists of
only variables.

00:10:53.800
00:10:55.800
Or directly can write your playbook as
well.

00:10:55.800
00:10:57.710
Just simply I'm writing.

00:10:57.700
00:11:02.200
I just I define two variables see that
now I created a play-

00:11:02.200
00:11:03.710
book called demo.

00:11:03.700
00:11:10.410
yml now see that the content of your
email file demo.yml is encrypted.

00:11:10.400
00:11:12.010
So that is the purpose of create.

00:11:12.000
00:11:16.010
So while creating if you want to
encrypt you how to use create

00:11:16.000
00:11:18.810
ansible vault option.

00:11:18.800
00:11:23.400
No, I already created a playbook in the
encrypted format. Now.

00:11:23.400
00:11:30.910
I want to see the content ansible-vault-
view.

00:11:30.900
00:11:34.700
Then you are encrypted yml file now.

00:11:34.700
00:11:36.400
It will ask your vault password.

00:11:36.400
00:11:42.010
Then you have to provide that
password. That's it.

00:11:42.000
00:11:46.700
Suppose if you want to edit the
existing encrypted email
00:11:46.700
00:11:51.710
file then ansible vault edit again, it will
ask the password.

00:11:51.700
00:11:54.600
You have to provide the password.
That's it.

00:11:54.600
00:11:56.910
[no audio]

00:11:56.900
00:12:02.410
Fine then. Let me go with other
options as well.

00:12:02.400
00:12:08.710
So create decrypt edit view encrypt
then let me go with rekey

00:12:08.700
00:12:12.200
and encrypt sting directly just to
encrypt a string now.

00:12:12.200
00:12:13.700
Let me go with rekey option.

00:12:13.700
00:12:18.110
What is the purpose of rekey. See
that?

00:12:18.100
00:12:21.800
Suppose you encrypted a file using
ansible vault with your

00:12:21.800
00:12:23.000
required password. Now.

00:12:23.000
00:12:25.300
I want to change the ansible vault
password.

00:12:25.300
00:12:28.310
Then you have to use your

00:12:28.300
00:12:34.700
rekey option. Rekey suppose for this
file I use ansible as

00:12:34.700
00:12:37.200
the password. I mean world pass.

00:12:37.200
00:12:38.600
So now I want to change it first.

00:12:38.600
00:12:42.100
You have to provide the old password
then provide new vault
00:12:42.100
00:12:45.000
password. Let's say I am providing
password as some demo

00:12:45.000
00:12:50.900
1 2 3 then just to confirm it now see
that your vault password

00:12:50.900
00:12:55.110
has been changed with the help of
rekey option. That's it.

00:12:55.100
00:12:58.400
Now the last option is see as of now
suppose if you want

00:12:58.400
00:13:01.600
to run your ansible playbook, I mean,
which is encrypted

00:13:01.600
00:13:06.400
then you are using ansible playbook
then your playbook name.

00:13:06.400
00:13:08.610
[no audio]

00:13:08.600
00:13:17.000
and then - - ask vault pass then you
have to provide your

00:13:17.000
00:13:22.110
password for this but instead of
providing password here.

00:13:22.100
00:13:24.610
You can store your password into one
file.

00:13:24.600
00:13:28.010
Let's say I am creating a file called my
pass.

00:13:28.000
00:13:29.700
So here I am storing my password.

00:13:29.700
00:13:31.710
[no audio]

00:13:31.700
00:13:35.400
Now that password file you can
directly provide while running

00:13:35.400
00:13:38.400
your ansible playbook in the command
line itself, but
00:13:38.400
00:13:41.800
how we can provide. See? As of now,
we have two options to

00:13:41.800
00:13:46.010
provide that but going forward you will
have only one option.

00:13:46.000
00:13:48.310
Let me show you that.

00:13:48.300
00:13:51.600
See ansible playbook help
somewhere.

00:13:51.600
00:13:55.600
You are having - - vault ID or -- vault
password

00:13:55.600
00:13:59.900
file. So as of now you have both
options going forward in

00:13:59.900
00:14:01.700
the updated versions of ansible.

00:14:01.700
00:14:05.310
You may have only - - vault ID.

00:14:05.300
00:14:08.410
But as of now you can use both now.

00:14:08.400
00:14:10.600
Let me copy either that one.

00:14:10.600
00:14:12.710
[no audio]

00:14:12.700
00:14:15.000
See that now I am running.

00:14:15.000
00:14:17.310
[no audio]

00:14:17.300
00:14:19.700
Instead of this - - ask-vault.

00:14:19.700
00:14:21.800
So if you go with -- ask vault pass you

00:14:21.800
00:14:24.300
have to provide the password you
have to type it but instead

00:14:24.300
00:14:28.200
of that if you go with just provide the
the file name in
00:14:28.200
00:14:30.400
which you have your password now, it
will run.

00:14:30.400
00:14:33.910
[no audio]

00:14:33.900
00:14:37.610
Or let me cancel it.

00:14:37.600
00:14:40.710
So instead of that you can also take
one more option called

00:14:40.700
00:14:42.100
- - vault ID.

00:14:42.100
00:14:51.910
[no audio]

00:14:51.900
00:14:54.710
Let me copy it.

00:14:54.700
00:14:55.800
Now instead of this.

00:14:55.800
00:14:58.310
[no audio]

00:14:58.300
00:15:03.410
You can simply take - - vault ID. That's
it.

00:15:03.400
00:15:06.600
I cancel that so you can use any one
of that option to provide

00:15:06.600
00:15:09.000
your password in terms of a file.

00:15:09.000
00:15:11.100
You can store your password in your
file and you can pass

00:15:11.100
00:15:15.000
that by using these two options. That's
it.

00:15:15.000
00:15:18.010
[no audio]

00:15:18.000
00:15:23.000
And see actually in real-time.
Generally.

00:15:23.000
00:15:28.110
We don't encrypt the entire playbook
instead of that.
00:15:28.100
00:15:31.200
What we will do is what our the
sensitive data we have that

00:15:31.200
00:15:34.910
data. We will store into a separate file
like variable file

00:15:34.900
00:15:37.900
that file we will encrypt using ansible
one. That's it.

00:15:37.900
00:15:40.310
[no audio]

00:15:40.300
00:15:42.100
Okay guys. Thank you for watching
this video.
Transcript
00:00:00.000
00:00:06.500
Prince here. We are discussing
ansible roles. Basically ansible

00:00:06.500
00:00:10.400
roles are useful to reuse your
playbooks, but ansible itself

00:00:10.400
00:00:12.800
has two ways to reuse your
playbooks.

00:00:12.800
00:00:16.000
They are using include and roles.

00:00:16.300
00:00:19.500
If you remember, we already
discussed include or import

00:00:19.500
00:00:21.300
option to reuse your playbooks.

00:00:21.300
00:00:24.400
And we also saw the difference
between include and import
00:00:24.400
00:00:29.000
options. And here we are working with
roles, compared to include,

00:00:29.000
00:00:32.500
roles are the best way to reuse your
playbooks, because

00:00:33.200
00:00:36.300
ansible-roles follows some directory
structure. Because of

00:00:36.300
00:00:39.000
that, directory structure will get some
advantages.

00:00:39.100
00:00:42.000
That's why roles are a very important
oncept in ansible.

00:00:42.700
00:00:44.800
Now, let me explain about the roles
here.

00:00:45.300
00:00:49.000
Now before going to implement, if you

00:00:49.000
00:00:52.600
remember, somewhere we use this
playbook to install and configure

00:00:52.600
00:00:57.900
your tomcat and here we have three
parts. One is to update

00:00:57.900
00:01:02.900
your record, second one is install and
configure

00:01:02.900
00:01:06.599
the path for Java and third one is for
Tomcat.

00:01:07.400
00:01:11.100
Now, what I will do is I will implement
this playbook by

00:01:11.100
00:01:13.200
implementing three roles first.

00:01:13.200
00:01:16.300
Let me create three rules. One role is
to update your record,

00:01:17.000
00:01:20.700
second role is to install and configure
your Java and third
00:01:20.700
00:01:24.700
rule is to install and configure your
Tomcat.

00:01:26.300
00:01:31.000
See, I said that ansible role follows
some directory structure.

00:01:32.100
00:01:35.200
But don't worry, you don't need to
create the data structure.

00:01:35.300
00:01:36.900
To create your data structure,

00:01:36.900
00:01:39.600
we have ansible command, that is
ansible galaxy.

00:01:40.400
00:01:43.500
But before going to create your
ansible rules first, I am

00:01:43.500
00:01:44.600
giving the basic steps.

00:01:45.500
00:01:47.200
We have ansible.cfg here

00:01:47.500
00:01:50.100
in this location, I mean from where you
are working.

00:01:50.700
00:01:54.500
There, just create a directory called
roles.

00:01:56.200
00:01:59.300
Instead of roles, if you go with any

00:01:59.300
00:02:04.300
other directory name, then in your
ansible.cfg,

00:02:04.300
00:02:07.700
you have to provide the path for your
roles.

00:02:08.300
00:02:10.800
But if you go with default name as
roles, you

00:02:10.800
00:02:17.100
don't need to give the path. See that? I
did not give it
00:02:17.100
00:02:20.300
any path here, but there is a roles path
if you provide some

00:02:20.300
00:02:23.300
any name, or if your roles are there in
the different location

00:02:23.400
00:02:26.600
from your ansible dot dot c f g then it's
better to provide

00:02:26.600
00:02:27.500
your path here.

00:02:27.900
00:02:28.400
That's it.

00:02:28.900
00:02:29.700
Now, that's fine.

00:02:30.200
00:02:33.100
Now we created rolls now, let me
enter into roles.

00:02:34.100
00:02:40.200
Now here I am going to create the first
role as update repose.

00:02:41.400
00:02:46.300
So ansible Galaxy that is the
command to create a rule and

00:02:46.300
00:02:49.700
you have to initialize or roll roll named
as I am taking

00:02:49.700
00:02:56.400
update Repose and I am providing - -
offline why because

00:02:57.300
00:03:01.400
actually ansible is maintaining ansible
Galaxy.

00:03:02.200
00:03:05.600
There are maintaining a Repose in the
trip.

00:03:05.600
00:03:10.400
Oh, we have a predefined rules in
case if the same name is

00:03:10.400
00:03:11.000
there in the dress.

00:03:11.200
00:03:13.500
As Reed will download that repository.
00:03:13.500
00:03:15.900
That's why we are working with offline.

00:03:16.100
00:03:16.500
That's it.

00:03:17.300
00:03:19.500
I will show you that so if you want.

00:03:20.900
00:03:22.000
Let me take.

00:03:24.000
00:03:30.500
and symbol Galaxy see that Galaxy
Dot ansible.com.

00:03:31.300
00:03:34.200
So here we have different types of
report.

00:03:34.400
00:03:38.000
I mean rolls suppose if I go with some
cloud.

00:03:40.100
00:03:44.100
See that so these all are predefined
rules directly.

00:03:44.100
00:03:46.400
You can download that and you can
work with that in case

00:03:46.400
00:03:49.100
if you want to create your own roles,
then you have to follow

00:03:49.400
00:03:53.000
- - offline fine now, let me run it.

00:04:00.300
00:04:00.700
Sorry.

00:04:06.600
00:04:15.400
Where We Are Cedar update Repose
was created successfully

00:04:15.400
00:04:19.600
the role update Repose and
immediately see the direct structure

00:04:19.600
00:04:20.200
for that.

00:04:21.500
00:04:24.000
See, we have different directories and
different files.
00:04:25.399
00:04:29.400
Defaults files handlers matatus
templates test.

00:04:29.400
00:04:31.000
Where's okay.

00:04:32.000
00:04:34.800
Now first, we are creating update
Repose.

00:04:34.900
00:04:37.700
Now if You observe suppose in your
play book for update Repose,

00:04:37.700
00:04:39.400
we don't have any variable
straightforward.

00:04:39.400
00:04:41.800
We have a task, right?

00:04:42.000
00:04:46.200
That's why what I am doing is Under
your task directory.

00:04:46.200
00:04:49.000
You have a main dot m l so in this only
how to write your

00:04:49.300
00:04:50.800
tasks. Now.

00:04:50.800
00:04:54.100
What I am doing is Task forget about
remaining things in

00:04:54.100
00:04:56.900
case if our requirement is just go and
touch remaining otherwise

00:04:56.900
00:05:00.700
always the main important thing is
Task directory under 30

00:05:00.700
00:05:05.600
have may not a mammal so Update
report.

00:05:05.600
00:05:07.800
So here under tasks directory.

00:05:07.900
00:05:11.800
You have main dot Tamil go and write
only your task.
00:05:11.900
00:05:17.100
Don't draw start with - host gather
facts task gather facts

00:05:17.100
00:05:21.100
task don't write all those things just
right forward, right?

00:05:21.100
00:05:22.400
You're required task.

00:05:22.500
00:05:22.900
That's it.

00:05:25.200
00:05:26.200
Just give me a second.

00:05:26.300
00:05:29.000
I'm getting indentation because I'm
copying the thing.

00:05:34.800
00:05:35.400
That's it.

00:05:35.400
00:05:36.200
Only task.

00:05:36.200
00:05:36.900
I have written here.

00:05:37.700
00:05:38.700
Let me save it.

00:05:39.600
00:05:46.000
So as of now we created one rule right
now come out from

00:05:46.000
00:05:49.000
your rules will create remaining two
roles later.

00:05:49.800
00:05:50.000
Now.

00:05:50.000
00:05:55.200
I am creating am I required Playbook
see roles are not the

00:05:55.200
00:05:59.300
complete Playbook roles have only
implementation of your

00:05:59.300
00:06:00.200
tasks part.

00:06:00.900
00:06:01.600
Now VI.

00:06:02.400
00:06:03.300
I am creating.
00:06:05.300
00:06:15.800
and configure Tomcat, Java and
update your Repose now see

00:06:15.800
00:06:21.000
that I am taking - - I mean so yeah,
this is my main Playbook

00:06:21.300
00:06:26.000
- name using roles.

00:06:26.400
00:06:32.400
That's it the now let me take host as
suppose I have app

00:06:32.400
00:06:40.500
servers. Group in my inventory, then I
don't want to collect

00:06:40.500
00:06:43.300
facts gather facts false then.

00:06:44.800
00:06:46.600
I want to run with root become.

00:06:46.600
00:06:50.200
Yes now generally if you go with the
tasks you are writing

00:06:50.200
00:06:52.600
tasks and then you are implementing
your task part.

00:06:53.200
00:06:58.300
Now I am going with roles that why
just write rules and right

00:06:58.300
00:07:00.500
here - Your Role name?

00:07:00.500
00:07:01.700
So what is our role name?

00:07:04.800
00:07:09.800
update repos Sorry.

00:07:16.600
00:07:17.500
Update the post.

00:07:17.500
00:07:18.000
That's it.

00:07:18.600
00:07:21.300
Now, let me save it and run it.

00:07:25.000
00:07:25.700
See the output.

00:07:27.000
00:07:28.100
Update Repose.
00:07:28.300
00:07:33.000
It is including that updating Repose
update Repose my role

00:07:33.000
00:07:35.300
in the Des going to exclude updating
Repose.

00:07:35.900
00:07:36.400
That's it.

00:07:39.300
00:07:41.700
Okay, so it will take some time to
update that repo.

00:07:41.800
00:07:42.800
Just wait for that.

00:07:45.000
00:07:46.200
But I am passing this video.

00:07:46.200
00:07:47.800
Once it is done then I will be back.

00:07:49.700
00:07:53.600
Okay, it's done now in our Playbook.

00:07:53.600
00:07:57.100
We completed one part this part now.

00:07:57.100
00:08:01.300
The next thing is we need to install
and configure your Java

00:08:01.300
00:08:02.800
path. Right?

00:08:02.900
00:08:06.800
And if You observe this Java is taking
two variables.

00:08:08.200
00:08:11.600
Now what I am doing is first, let me
create a role for Java

00:08:12.200
00:08:14.300
so ansible Galaxy.

00:08:15.800
00:08:18.500
In it initialize your roll roll name
suppose.

00:08:18.500
00:08:21.600
I am taking instead of taking directly
Java.

00:08:21.700
00:08:25.400
It's bad to take your project name
underscore Java something
00:08:25.400
00:08:28.700
like that because generally in real time
will take in this

00:08:28.700
00:08:34.500
way. So I am taking suppose x y z
project Java then - - offline

00:08:35.700
00:08:37.799
But as of now, we are under different
path.

00:08:37.900
00:08:41.600
So I have to create this role under
roles directory, right?

00:08:41.600
00:08:47.400
So that's why I'm taking roll / now go
to your rolls see

00:08:47.400
00:08:49.200
that we have Java.

00:08:49.600
00:08:51.500
Let me move in the x y z Java.

00:08:52.799
00:08:55.900
And here anywhere by default, you will
get all different

00:08:55.900
00:08:58.600
directories right as of now, you know,
what is the purpose

00:08:58.600
00:08:59.300
of tasks?

00:08:59.500
00:09:03.100
So task is the directory in which you
have to write your

00:09:03.100
00:09:08.800
required tasks to install your particular
role now under

00:09:08.800
00:09:10.700
tasks. Anyway, you have main dot m l
now.

00:09:10.700
00:09:12.000
Let me open it again here.

00:09:12.000
00:09:14.500
Also, you have to write a main task to
install your Java.
00:09:15.600
00:09:18.400
Now, what I will do is directly I will
write copy and paste

00:09:18.400
00:09:21.200
this but I will copy and paste line by
line because I will

00:09:21.200
00:09:34.800
get indentations otherwise Just give
me a second.

00:09:39.400
00:09:41.000
So this is installation part.

00:09:42.400
00:09:43.800
Now you have one more task here.

00:09:44.400
00:09:49.600
That is setting the default Java as your
Java on your host.

00:09:52.500
00:09:54.200
So you have to use Alternatives
module?

00:09:57.700
00:09:59.600
Then what is the name for that?

00:10:02.500
00:10:06.000
Guys, we explain about this
completely booked in our previous

00:10:06.000
00:10:09.400
videos just go through that once and
come back and observe

00:10:09.400
00:10:13.500
this. Implementation part so that it is
very easy to understand

00:10:13.500
00:10:14.700
about your roles.

00:10:15.800
00:10:16.300
That's it.

00:10:17.200
00:10:20.700
But if You observe its requires two
variables required Java

00:10:20.700
00:10:23.900
and set Java will Define that first.

00:10:23.900
00:10:29.900
I completed the task for your to install
your Java fine now
00:10:30.500
00:10:31.600
to Define your variables.

00:10:31.600
00:10:35.400
We have two places one is defaults
one more is Vas.

00:10:37.100
00:10:40.100
So if you don't Define any variables,
then it will automatically

00:10:40.100
00:10:43.000
pick from defaults in case if a different
default variables

00:10:43.000
00:10:46.300
here now, I want to Define
underwears.

00:10:48.200
00:10:53.300
VI verse sorry, that is a directory under
wires.

00:10:53.300
00:10:53.600
Again.

00:10:53.600
00:10:58.400
You have main dot animal now here
we have defined only variables.

00:11:02.400
00:11:04.300
So our variables are required, Java.

00:11:07.500
00:11:09.100
Let me provide some indentation.

00:11:10.300
00:11:12.500
Then one more thing is set Java.

00:11:12.700
00:11:13.200
That's it.

00:11:16.300
00:11:16.700
Done.

00:11:17.700
00:11:18.800
Java part is done.

00:11:19.700
00:11:20.100
Now.

00:11:20.900
00:11:26.100
Come back your play book original
Playbook where you have

00:11:26.100
00:11:30.100
install and configure right just include
your one more Java.
00:11:30.200
00:11:33.800
I mean, sorry one clue one more roll
that is in XYZ.

00:11:33.800
00:11:34.500
Java roll.

00:11:35.000
00:11:36.500
Now it will update your repo.

00:11:36.700
00:11:37.900
It will install your Java.

00:11:37.900
00:11:38.400
That's it.

00:11:40.200
00:11:42.000
So if you want to run you just run it.

00:11:43.900
00:11:45.000
But it will take some time.

00:11:46.600
00:11:47.900
You have to wait for that.

00:11:49.100
00:11:51.600
Anyway, I will I will pause the video
once it is done then

00:11:51.600
00:11:52.400
I will be back.

00:11:55.900
00:12:02.100
it's done its included Your raipur Role
and your Java role

00:12:02.600
00:12:07.900
and is it has been done now now the
next thing in your actual

00:12:07.900
00:12:14.500
Playbook is you have to download
your required Tomcat, right?

00:12:14.500
00:12:15.900
And then you have to extract it.

00:12:16.300
00:12:18.900
And then you have to rename it and
you have to copy some

00:12:18.900
00:12:21.600
template. I mean some Z2 file.

00:12:21.900
00:12:25.600
So what I will do is first I will create a
role for that.
00:12:26.500
00:12:31.500
So let me create a rule and symbol
iPhone Galaxy initialization

00:12:31.800
00:12:36.300
then under rolls XYZ Tomcat.

00:12:36.300
00:12:37.100
I am creating.

00:12:39.000
00:12:41.000
- - offline that's it.

00:12:42.000
00:12:45.000
It has been created Now navigate into
your roles.

00:12:46.600
00:12:52.700
XYZ Tomcat roll Now as of now we
know about the issues of

00:12:52.700
00:12:56.800
tasks and where's of course defaults
also because both wires

00:12:56.800
00:13:00.600
or default both are useful to Define
your variables and compared

00:13:00.600
00:13:03.100
to defaults verse as the highest
priority.

00:13:03.200
00:13:03.600
That's it.

00:13:05.200
00:13:08.000
Now if you want to see you can see
under defaults also have

00:13:08.000
00:13:12.400
main dot HTML you can Define here
right defaults file for

00:13:12.400
00:13:13.300
your rule.

00:13:14.100
00:13:14.700
That's fine.

00:13:16.300
00:13:22.600
no, let me Define variables first.

00:13:22.700
00:13:24.900
So the required variables for you are
Tomcat.

00:13:24.900
00:13:30.400
Is these three now?
00:13:32.300
00:13:33.300
Under wires.

00:13:33.500
00:13:36.300
You have main bottom l so here I am
defining.

00:13:37.900
00:13:44.400
three variables just let me adjust my
indentations.

00:13:52.400
00:13:53.100
Save it.

00:13:54.800
00:14:03.600
fine now next the first task is
downloading required Tomcat,

00:14:04.400
00:14:09.500
right? So let me copy this so very hard
to update your tasks.

00:14:11.000
00:14:14.900
Under tasks their entry you have main
dot ml then here you

00:14:14.900
00:14:17.100
can write about tasks.

00:14:18.200
00:14:18.800
Be clear.

00:14:18.800
00:14:20.900
We are writing only tasks.

00:14:21.900
00:14:26.500
Right now again, let me adjust my
indentations.

00:14:34.500
00:14:36.900
Then you have one more task.

00:14:36.900
00:14:41.100
I mean some other tasks also we are
having extracting downloaded

00:14:41.100
00:14:41.900
Tom Cat.

00:14:50.100
00:14:52.200
Let me adjust indentations once again.

00:15:11.300
00:15:14.400
Okay, then we have one more thing.

00:15:18.100
00:15:19.700
Rename Tomcat home.
00:15:26.700
00:15:29.600
see if you want to understand about
roles first try to implement

00:15:29.600
00:15:34.800
your playbook in terms of Normal
Playbook then try to convert

00:15:34.800
00:15:37.200
that into rolls now.

00:15:38.400
00:15:42.800
we have one more thing as This one
right?

00:15:42.800
00:15:46.900
I mean now here you have to
understand one more important

00:15:46.900
00:15:48.100
point just first.

00:15:48.100
00:15:50.400
Let me copy this then we'll discuss
about it.

00:15:52.000
00:15:57.300
So what we have here is we have a
gender template right the

00:15:57.300
00:15:59.900
whenever if you have a ginger
template anywhere, you're using

00:15:59.900
00:16:04.300
model called template to copy that but
whatever the ginger

00:16:04.300
00:16:07.600
template file you are using in your
script only Ginger to

00:16:07.600
00:16:11.500
template files that always you have to
write under templates

00:16:11.500
00:16:16.400
directory. That means before using
that Ginger file in your

00:16:16.400
00:16:18.900
roles. You have to copy this file.

00:16:19.300
00:16:21.700
You have to copy that Ginger to file.
00:16:23.000
00:16:25.800
Into templates directory you have
templates directory here,

00:16:25.800
00:16:31.200
right? Templates directory so
templates directories are useful

00:16:31.200
00:16:36.100
to copy to store your Ginger template
files.

00:16:36.300
00:16:42.800
So that anywhere playbook in your
tasks directly.

00:16:42.800
00:16:46.300
You can write templates / your file
name Jinja file and suppose.

00:16:46.300
00:16:49.100
I assume that you are having some for
five Ginger files.

00:16:49.200
00:16:52.500
No problem all files you can place in
templates and you can

00:16:52.500
00:16:56.700
use your source as templates / service
dot I mean, whatever

00:16:56.700
00:16:59.500
the template Ninja file you want that
file you can place

00:16:59.500
00:17:02.800
here but before going to use here, this
file should be there

00:17:03.000
00:17:04.098
under templates.

00:17:04.400
00:17:06.300
So that is the directory structure
usage.

00:17:07.598
00:17:09.200
Now, let me copy that file here.

00:17:09.400
00:17:19.800
So actually I how so copy server dot
XML to under rolls XYZ

00:17:19.800
00:17:24.000
Tomcat templates That's it.
00:17:24.598
00:17:24.700
Now.

00:17:24.700
00:17:26.200
Let me navigate into.

00:17:28.599
00:17:33.599
Fine now now we know what is the
usage of templates and verse

00:17:33.599
00:17:35.599
on the task then go with files.

00:17:35.900
00:17:38.099
See if you want to copy some static
files.

00:17:38.800
00:17:42.700
We are using suppose copy module,
right and before going

00:17:42.700
00:17:46.400
to copy some static file for your
required role first place

00:17:46.400
00:17:51.400
your static files in this and while using
your copy module,

00:17:52.500
00:17:53.500
Let me show you that.

00:17:56.200
00:17:58.400
So suppose just assume that instead
of template you're using

00:17:58.400
00:18:02.000
copy module, right and Source, you
have to write this as

00:18:02.000
00:18:05.100
a files then the file, which is there in
your files directory

00:18:05.100
00:18:07.200
of particular role then destination.

00:18:07.300
00:18:12.500
You are wish I mean you are required
is Nation only so here

00:18:12.500
00:18:15.300
also have to provide some indentation
I missed that.

00:18:15.800
00:18:16.500
Yeah fine.
00:18:17.500
00:18:18.000
That's it.

00:18:19.000
00:18:21.000
Now one more thing.

00:18:21.600
00:18:23.300
We have starting Tomcat, right?

00:18:24.800
00:18:28.000
So this task you can write directly in
this.

00:18:29.500
00:18:33.400
Or if You observe here handlers, there
is also their handlers

00:18:33.400
00:18:37.700
directs directory now under handlers.

00:18:38.100
00:18:39.000
I am writing that.

00:18:40.200
00:18:45.100
under handlers See that how I am
writing, of course directly

00:18:45.100
00:18:50.800
you can place in your tasks main file
itself, but I am writing

00:18:50.800
00:18:52.000
under handlers.

00:18:52.300
00:18:55.900
If you remember handlers concept you
can easily understand

00:18:55.900
00:18:58.300
this so simply I am writing here.

00:18:59.400
00:19:00.500
Start Tomcat.

00:19:01.400
00:19:05.800
I'm giving that name and copy this
name copy this name.

00:19:07.400
00:19:10.900
You know how to call handlers in your
normal playbooks with

00:19:10.900
00:19:15.600
notify same way in your main dot ml
tasks section asked directory

00:19:15.600
00:19:16.600
in may not ml.
00:19:17.500
00:19:22.100
So once if it done everything right so
some very hot to call

00:19:22.100
00:19:23.600
that with notify.

00:19:26.600
00:19:27.100
That's it.

00:19:28.100
00:19:28.400
Now.

00:19:28.400
00:19:32.600
We completed our entire playbook in
terms of roles.

00:19:33.200
00:19:35.200
Now come back to your original
Playbook.

00:19:36.100
00:19:40.500
So be clear roles are the not complete
playbooks roles are

00:19:40.500
00:19:45.700
having only task part and the required
variables finally

00:19:45.700
00:19:49.500
how to implement your own Playbook
to to complete your required

00:19:49.500
00:19:53.900
tasks in that you have to include your
required roles.

00:19:53.900
00:19:54.400
That's it.

00:19:56.800
00:19:59.600
- XYZ Tomcat, that's it.

00:20:00.100
00:20:02.800
So this is the way how we can convert
our playbooks into

00:20:02.800
00:20:06.600
roles. And what are the advantage is
by using you are rules.

00:20:06.700
00:20:07.200
That's it.

00:20:07.500
00:20:08.500
Now, let me run this.
00:20:09.700
00:20:13.100
and observe the output So anyway, it
will take some time

00:20:13.100
00:20:16.000
guys. Once again, I am passing that
once it is done then

00:20:16.000
00:20:16.800
I will be back.

00:20:20.000
00:20:21.400
See that it has been done.

00:20:22.000
00:20:25.900
So this is the simple way to convert
your entire Playbook

00:20:26.000
00:20:26.900
into roles.

00:20:28.200
00:20:28.800
Right.

00:20:28.900
00:20:30.000
So be clear.

00:20:30.900
00:20:34.700
We are implementing roles only for
tasks part.

00:20:35.300
00:20:36.700
I mean tasks part.

00:20:38.500
00:20:42.000
In case if you want to implement a
comparative or complete

00:20:42.000
00:20:44.600
Playbook, then you have to write your
Playbook by including

00:20:44.600
00:20:45.300
your roles.

00:20:46.400
00:20:49.400
right Just simply in this way.

00:20:50.000
00:20:52.200
So likewise you can Implement any
number of roles and you

00:20:52.200
00:20:53.900
can include any number of roles here.

00:20:54.700
00:20:55.100
Okay.

00:20:55.200
00:20:56.600
Thank you for watching this video.

You might also like