0% found this document useful (0 votes)
19 views5 pages

Ansible Playbook Basics for DevOps

The document outlines a DevOps training session focused on Ansible, Kubernetes, and Jenkins, emphasizing the importance of linking these tools in the syllabus. It details the process of creating and executing Ansible playbooks, managing Docker containers with Kubernetes, and setting up a web server. The instructor also mentions future classes on Jenkins and microservices, along with the integration of SonarQube for static code review in pipelines.

Uploaded by

Aditya Rai
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

Ansible Playbook Basics for DevOps

The document outlines a DevOps training session focused on Ansible, Kubernetes, and Jenkins, emphasizing the importance of linking these tools in the syllabus. It details the process of creating and executing Ansible playbooks, managing Docker containers with Kubernetes, and setting up a web server. The instructor also mentions future classes on Jenkins and microservices, along with the integration of SonarQube for static code review in pipelines.

Uploaded by

Aditya Rai
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Alright.

So guys, I hope all of you taking my DevOps classes and tools classes also
parallelly you're completing it. I'm assuming that because we are somewhere trying
to link these things and finish our syllabus. Because once we finish Ansible, see
Ansible, I'm going to now teach you to one extent. But again, I'll be taking
classes later on Ansible, which will take at least some seven to eight classes for
me.

Okay? For now, dev ops to yes. Yes. But Kubernetes, developers will access Jenkins.
Jenkins servers access Right?

For Ansible tools training Kubernetes if you finish, which will manage all your
docker images, docker containers sorry. Correct? When there are lot of containers,
see right now we are seeing one container. We started application one container is
there, but in microservices multiple containers will be there, we need to manage
those containers. So we have something called a docker compose, but the docker
compose I did not add that in my syllabus because that is kind of people they don't
use that, instead of docker compose people will go with kubernetes, Are you
understanding now?

That's a better option for us basically, if you want to, work further with your
pipeline. Okay? So you will be responsible for creating a pipeline. For pipeline is
all things, you have an idea about it, which means you have a major idea about what
DevOps. Now let's start to that.

So yesterday, I was talking about Ansible and what went wrong. See, firstly let me
these are all the services that's already running. Let me just go back here and,
let's see whether it's still running. Yeah. It's still running.

Right? So let me clear the screen. You know, what is the problem that happened
yesterday is when I do a p w d, right, when I do a p w d, right, p w d, you just
observe, I'm pointing to the wrong directory. Now this is not the one where I've
installed my Ansible software. Though I'm switching to Ansible, I'm doing a switch
user to Ansible, the directory that I'm pointing is wrong.

That's why yesterday whatever we were trying to execute that was not working.
Right? So we should use your c d tilde. And when you do that p w d, now I'm
pointing to the directory where my Ansible commands I can run. Are you
understanding now?

Now once you have done this, we can now use our playbook. So this is the first
playbook which will perform a pick, right? So how to create this playbook guys? So
I'm going to go here, I'm going to go here and I'll create one file vi and let's
call this as okay book hyphen zero one dot y m l, fine. Hit on enter, go to insert
and let me paste this in here and then escape colon w q.

So you should point to the right folder where your Ansible software is running. And
then after that if you do Ansible ansible hyphen playbook playbook space. Now you
see that here, that's what we are supposed to ansible playbook and then you give
the viable file name. What is viable file name? Book and head on enter.

Now you see that it will start running our playbook. Did you understand now what
went wrong? Everybody see it has performed a ping. But if you notice now this ping
that I'm doing it, it is on the manage notes. I'm not doing this ping on our
controlled note.

Fine? So let's clear now. Seve way. Let's create some more playbooks and let's try
to understand that now. Now before I create a playbook, there are few more things
we can do it like syntax check.
If you want to check the syntax, then you can just hear further, okay, give this
particular thing, and that will help you to check the syntax of your playbook. Is
it proper or not? Right? Same way, we have one more thing here is to list all the
host. Can you tell me how many host do we have actually?

How many host do we have? There are two host. What are the two host? Web servers
and right. We created two manage nodes.

Are we getting their IP addresses? Yes or no? Correct. So you notice I'm all
connecting to my managed host and I'm able to perform the required task. Same way.

Now let's go here and, let's do our thing now. We look at, step okay option. With
our playbook, we can look at the step option. Now what is the step option with a
playbook? The step option, okay, the playbook will help you to run the things one
step at a time.

But now perform task task gathering. Do you wanna do that? Yes. If you say
continue, see, it will run everything together step by step. The first step is
executed, gathering the facts.

Then after that, it says perform task ping. So first it basically did some
gathering of things, it connected to our manage nodes and now it will perform the
module ping. So if I now say yes, it is now performing on ping and I got the
output. But in case, if I use here continue c, it will just run everything at once.
Okay, there's another option, when the line by line and you can see every line what
it is doing and where things needs to be modified.

That will help us okay to understand the things in a better way. Okay. Now let us
continue further we'll create our next you know yml file we'll create our playbook
which can create what text file but inside all the managed post. How do we do that?
So in order to do that now, I'm going to go here and I'm going to type v I okay
book hyphen zero two dot y m l and now click on insert and just paste this in here.

Can you please read that and tell me what's happening here? Here? Right? These are
all in readable formats if you look at now. Can you read this and tell me what is
that happening here?

First is what name? What are we giving here? Create a file. Then after that there
is a file attribute. Now the file attribute comes under task or comes under name?

Comes under the task, right. Now where is that file? It is present in a given path.
So path comes under file or comes under name? Under file.

So that is a path where the file should be created. But where it should be created
host all, Which is the host now? All managers. If I give web servers there, it'll
create this file only in a web server. If I give the d b server, it will create the
file only in d b server.

Is this clear? Now I will click on escape and then colon w q, is this clear? Now
let us run this playbook, how to run the playbook now? Ansible ansible hyphen what
is it? Hyphen playbook and then after that book zero two tab, look at that.

Now if I go to my managed notes, you will see that there is changed one. What does
changed one it means? It has created a file, right. Let's try seeing that here now.
So how do I see the file now firstly p w d, okay so now we will do c d del okay now
you do l s hyphen l, see that because this is the path I have given inside ansible
pulldown, correct?
Now who created this one now? Control node created this, see this here now, again
go here. Now what you will do c d tilde then after that l s hyphen l. Right? C d
tilde, I did not switch the user only first name.

Switch user, ansible. Right? Let's give the password. Password is Ansible only that
I have given. Now do a c d tail and then after that let's do here l s hyphen l.

You know why am I doing c d tail? Because I want to point to the root directory of
that user and I'm getting this. I hope this part is clear. Everyone clear with this
part? Okay.

Control or make yoga because what I've given here, create this in host. Look at my
playbook. What is given here? The third example now in that file, let us copy the
content. Right?

Now whatever file I created now, the manage node, the control node can put these
things in your managed host, okay or manage notes or whatever it is. So let's go
here now. So we will now type here vi book hyphen zero three dot yml insert. Paste
this here, please read this and tell me what it is doing now. What's happening?

It is copying the content to d one dot t x t. Correct? Inside your managed notes.
So colon w q, see this here? Ansible playbook is what?

Three? Check this out. Copying content. It's doing that. Content copy done.

Now go here. See your cat command for the file name name, t one dot t x t. Right?
Type your cat command t one dot t x t. Is this clear?

Everyone got this now? Okay. Good. Now the next thing, observe. Now the next
playbook, we will just install some web servers.

Let's try to do that. So I will just take part of it firstly and we will execute
this part by part for understanding now. So we will install a web server now vi,
what is it book hyphen zero four dot yml, insert insert this command. Now see this
here. What does it mean now?

Can you tell me what does it mean now? Are you able to read this? What it says in
the host web server, is it all or only web server? Only web server. What has become
true?

Yesterday you saw that I use hyphen b. What happened while using hyphen b? I was
running that command with pseudo privileges. Okay? So if you you know, there are
certain things you wanna do it, it has to be done with pseudo privileges.

So how do I give pseudo rights? To run this script, I should give pseudo rights. So
we use pick up. When we use pick up, it gives pseudo rights. Then after that, there
is a task, install h t t p d package, name h t t p d, state latest.

Okay? Now escape colon w q. Now which playbook we are going to run? We are going to
run the playbook that happens to be four. Okay?

Hit on enter. Let's see what's happening now. Let's observe here. Direct the facts.
What it did now.

Write failed zero, okay two it has now installed because I had already installed
that there. Okay, I was just looking at it, the commands out there whether it's
right or wrong, so I've already installed that. But in your case this this will not
come as okay to it will come as changed one. Okay? In my case this is already
installed now, is this clear?
Okay. The next thing the next thing now, I'm going to here start the server, right?
So I will use this now hyphen name hyphen name. So let's use this particular task.
Let's go here to our vi playbook four, insert I and then after let's hit on enter,
paste this here, paste this here, right?

Let's do a proper indentation. Fine? Okay. Looks fine everything. So what this will
do, this will install h t t p d and this will start h t t p d server.

Now h t t p d server runs on which port? 80. It runs on which port number? 80 port
number. So if I now go here, let's start this.

Right? Zero four. Now see that it is going to run on which port number? It's going
to run on the port number that is going to be a b, correct. Now I cannot access
that port number until and unless you go to your manage node manage node one and
you enable manage node one and you go to security, select the security groups and
ensure that you go to edit inbound rules and enable h t t p d eighty.

I've already done that. Correct? So we will do it again. We'll click on edit
inbound rule, add rule, then after that you will give here the port is 80 and then
you're going to select here ipv four anywhere and then click on what? Same.

Is this clear? Everybody got it? Now you can check that on that port but for which
you will require the public IP address of that instance. Manage node one, let's go
to details, select the public IP address, paste this here colon a d. Already there
is some default content, let us see that whether port a d colon a d, okay.

Secure connection. I think I missed something here. IP address. Let's take the IP
address, let's paste this here. Yeah.

Sorry. I should not be giving your 80 port number. Now this file I had edited it,
but I'll show you how I edited this. Okay. You'll get a different message.

Now in order to edit that file further what I did? Simple. So I'll just go to Vi
Book 04 Y M L open that up. And I will add one more thing here now. That is
hyphename copy index file.

Now this index file should be present in your control node. Okay. So I will show
you. First we copy this. Go here.

Insert mode. Then after enter. Here paste. Right? Now hit on go here.

Hit on tap. Right. This fine, This fine, yeah. Then okay? Okay, everybody clear
with this?

Now this file is not there. So what am I doing now? I'm copying this file. I'll
create one file index dot HTML in my Linux server and I put the content in that and
will copy that. So I just copy this one and just look at the indentation, is
everything correct?

The state started is not correct I feel that yes. Let me just check that once, that
state started correct Okay. And now escape colon w q. Is this clear? State latest
index.

Vi book hyphen zero five dot yml insert and paste this here. Is this clear? Escape
colon w q okay. Now you will open up your vi index dot html. Okay.

Now once I do this index dot html, what is the next thing now? Let me go to the
insert mode and you can change this here. Pankaj sir academy Bengaluru. Okay?
Escape colon w two.

So what will happen now? When I run this playbook zero five, when I run this
playbook zero five, automatically, that index page will be picked and that will be
deployed. Is this clear everyone? Yes? Directly dials up I'll take it.

It's a very simple and basic file. Okay, is this clear everyone? Everybody got
this? There you go. Actually, for now, we have covered all your concepts in a very
proper manner that is your Terraform, all the services in AWS.

Right? Now there is a bit of more syllabus, okay, of Ansible which I'll not take it
immediately. I think another four five classes is required, but this should be
sufficient for now to begin with. Now we will start with Jenkins kits, which has
been started in your tools training. So here dev ops training you have taken, their
tools training you have taken.

Now tomorrow we will create one pipeline, then I'm going to take Kubernetes later.
When I take Kubernetes classes, then one complete pipeline creation you should be
able to do that. Is this clear? And then further when we start with your classes in
microservices, there I will be using these concepts and that will give you more
clarity about how DevOps is going to be used in the project. Okay.

Everybody got it? Tegan? Any questions, queries? Sonar cube is another thing. We'll
have to look at it.

Sonar cube and loggers. These two things we people have to see that because
whenever you create a pipeline, sonar cube will be used point number one. Point
number two, with sonar cube we people will have to also work, static code review
will be a part of your pipeline. Okay. So with this, we should be able to create
back end development with AWS skills or good resume.

You might also like