Introduction
Let's discuss what we need to know about the RHCE certification exam!
VMWare and Red Hat Enterprise Linux
In this video we discuss how to download and configure the VMWare virtualisation software that we will use to build our lab environment. Once that is done, we'll sign up for a free account with Red Hat and download a valid copy of Red Hat Enterprise Linux.
Knowledge Check
You must pay for a Red Hat annual license in order to use RHEL.
Setting Up the Lab Environment
In this video we walk through the creation of 3 different virtual machines - all running Red Hat Enterprise Linux. One machine, the "control node", will be configured to use Ansible. This machine, in turn, will be used to automate and manage the other 2 virtual machines in the network. Let's walk through the setup process!
Knowledge Check
Which of the following commands were used to register the RHEL machine (choose all that apply)?
SSH Configuration
Ansible is an "agentless" automation solution. This means that the devices being managed by Ansible do not have to install any special software locally. However, in order to be managed by Ansible these devices will require SSH connectivity. In order to facilitate a smooth automated workflow we want to configure our devices to authenticate without the need to enter in passwords every time a connection is established. As such, in this video we walk through how to generate a public-private cryptographic key-pair to enable SSH key-based authentication.
Knowledge Check
Which command was used to transfer the SSH public key over to the managed nodes?
Ansible Basics
In this video we discuss some of the basic concepts behind Ansible. How does Ansible operate? What are the main components of the Ansible architecture? Let's dig in and find out!
Knowledge Check
Match the following components of the Ansible architecture
This interactive assessment is available in the full learning experience.
Configuring Ansible
In this video we walk through some very basic configurations to get Ansible up and running. We discuss the values specified in the Ansible configuration file. Next we create an Ansible inventory using the INI format to specify the two RHEL devices we plan to manage.
Knowledge Check
Which of the following configuration files will Ansible treat with the highest priority?
Validation
In this section, we aim to validate that we understand all the vital information discussed within this skill. Give it and go and test your knowledge!
Knowledge Check
Before sitting the RHCE exam, all candidates are required to hold a valid and current RHCSA certification.
Knowledge Check
The RHCE exam focuses on performing RHCSA-level tasks in an automated fashion using Ansible.
Knowledge Check
Which of the following describes how Ansible operates (choose all that apply)?
Knowledge Check
The Ansible inventory can be specified using which of the following formats (choose all that apply)?
Knowledge Check
Ansible playbooks are written using which file format?
Knowledge Check
Which command was used to modify the file used to define superuser access?
Knowledge Check
When modifying the "sudoers" file, which of the following configurations was used to allow the "ansible" user to elevate privileges without having to enter a password?
Knowledge Check
Is this your first time using Ansible?
This interactive assessment is available in the full learning experience.
View Transcript
Introduction
0:00Hey friends and welcome to the Red Hat Certified Engineer course here on CBT N
0:05uggets.
0:05So what I want to do to begin is to first discuss the general exam objectives
0:11pretty
0:11much what should we actually be tackling within this particular course and
0:15discuss the format
0:16of the course as well as who this course actually should be for.
0:20So with that said let's dive in and look at some of the details.
0:24Now the very first thing to state about the RHC examination is that if you want
0:29to be
0:29eligible and achieve this particular certification you must first have a valid
0:35and current RHCSA
0:37certification.
0:38So if you've not quite yet got your Red Hat Certified System Admin
0:42certification then
0:43fear not we do actually have the RHCSA examination course here on CBT Nuggets
0:48also.
0:49So once you've got that box ticked and you are a valid RHCSA Certified Engineer
0:55you
0:55are therefore eligible to set this particular course. Now important to
0:59understand the RHCE
1:01certification is a performance based exam. There are no written questions, only
1:06written
1:07tasks that you have to perform on a virtual machine.
1:11So the question is what type of tasks should you be expected to know.
1:14Now really traditionally in older iterations of this particular exam you could
1:19expect to
1:19see very advanced Linux admin topics.
1:22However in the new modern version of the examination the actual tasks which you
1:27are asked to perform
1:28are really not that advanced. It is very much the type of content that you
1:33would expect
1:33to see in the RHCSA certification. The difference here in the RHCE exam is that
1:40we are performing
1:40all of these types of tasks that we would do in this particular exam.
1:44But now we are being asked to do those tasks via automation using Red Hat Ans
1:49ible Engine.
1:50So whilst the RHCSA examination might ask you to configure new users on the
1:54system the
1:55RHCE exam will ask you to do the same type of thing this time using Ansible.
2:01Now if we go into the actual objectives here we get a little bit more detail
2:04about what
2:05should actually be studying. Here are the actual tasks that we are expected to
2:08understand.
2:09Notice these are very very similar to what we see in RHCSA. Configuring local
2:15storage,
2:15managing users, basic security, configuring file systems, that type of thing.
2:20But doing
2:20it with this understanding of automation. So we are going to be looking at all
2:23of these
2:24components of Ansible. Things like the inventory, how we can use modules, what
2:28variables are,
2:28how to use loops and conditional statements, that type of thing. We are going
2:32to learn
2:32how we can use rows within Ansible and leverage something known as Ansible
2:36Galaxy. And how
2:37we can set up what is known as the Ansible control node which is basically the
2:41device
2:42on the system that is running Ansible that is performing the Ansible automation
2:46. And
2:47we are going to learn how we can perform those tasks on these managed nodes. So
2:51very important
2:51we will get to see how we can actually use SSH keys for passwordless
2:55authentication,
2:56how we can elevate a privileges on these managed devices that type of thing. We
3:00will talk about
3:00something known as Ansible Navigator, we will talk about creating plays and
3:04playbooks.
3:04As well as a whole bunch of other details including how we can also templatise
3:08configuration
3:09files and protect secret data using a utility known as Ansible Vault. So we are
3:15going to
3:15have a lot of fun within this course. However the very first thing that we are
3:18going to
3:18have to do is to begin building out our lab environment and that begins by
3:22getting a
3:23copy of Red Hat Enterprise Linux.
VMWare and Red Hat Enterprise Linux
0:00So friends, one of the very first things that we have to do is we have to get a
0:04hold of
0:04Red Hat Enterprise Linux.
0:07This is the Linux distribution that we're going to be using in order to install
0:11Ansible.
0:11So with that said, let's just dive in.
0:13Now the first thing to say with respect to Red Hat Enterprise Linux is that you
0:18can actually
0:18run this and say for example a cloud environment, or if you so wish you could
0:22run this as a bare
0:24metal installation, pretty much meaning that you could just install it on your
0:28regular hardware,
0:29your laptop, your PC, whatever it may be, and run it just as a regular OS but
0:33that is not
0:35the way that I'm going to recommend that you begin your lab process.
0:38Instead, I'm going to suggest that you make use of virtual machines.
0:42Now perhaps you happen to have some type of software on your computer already,
0:45maybe you're
0:46using something like say VirtualBox.
0:48And if you are, feel free to use that virtualization solution.
0:52In my case though, my personal favorite and the software that I'm going to
0:56recommend you
0:57use is VMware.
0:58So in this particular video, we're going to go through the installation of
1:02getting VMware
1:03available to us.
1:04And then we're going to see how we can actually get a working copy of Red Hat
1:08Enterprise Linux
1:09in order to perform our labbing.
1:11So let's do with the first part of the problem and talk about VMware.
1:15Now the first thing to say is if you happen to be using a Windows machine as
1:19your host
1:19computer, what you should actually search for is VMware Workstation Player.
1:24And if we click on this link right here, notice this is the platform for
1:28running virtual machines
1:30on a Windows or Linux PC.
1:31So once again, even if your host machine happens to be a Linux machine and you
1:35want
1:35to run virtualization software on that machine, then just like with Windows,
1:39you would download
1:40VMware Workstation Player.
1:41Now notice it says you can buy a commercial license.
1:44We don't have to worry about that right here if we just scroll on down.
1:48We can actually try the player for free if we so wish.
1:50This is for non-commercial purposes for your own labbing, that type of thing.
1:54So if you're on Windows, click this link.
1:56If you happen to have a Linux machine as your host machine, you be click this
1:59one instead.
2:00Now in my case, I happen to be using a Mac.
2:02So we have to download VMware Fusion.
2:05So in this case here, we click this link.
2:08Notice it says here that VMware Fusion 13 allows support for Intel or Apple
2:13Silicon,
2:14meaning that if you happen to have an older MacBook with an Intel processor,
2:17you can use
2:18this solution.
2:19Or if you happen to have one of these M1 or M2 MacBooks, the new ones, you can
2:23all
2:24also use VMware Fusion 13.
2:26So in this case here, what I'm going to do, given that I have an M1 MacBook, I
2:30'm going
2:31to click Register for a Personal Use License.
2:33Now it takes us to this page here, VMware Fusion Personal Use License.
2:38If you already have a VMware account, you can just select "I have an account."
2:42If you haven't got that account set up, you first want to create that account
2:45very, very
2:46important.
2:47So all you would do is click this link here.
2:49And what you're going to have to do is to provide some information about
2:52yourself, such
2:53as your email address.
2:54Now just be aware, you can't just put in some dummy email, make sure it is a
2:58real email,
2:59because you're going to have to click a verification link within that email in
3:03order to activate
3:03that account.
3:04So really make sure you can access that email when it pops in.
3:07Then if you scroll on down, you can give your name, your address, job title,
3:10that type
3:10of thing.
3:11Fill out the capture and agree to the terms.
3:13And once you have done that, you will get an email in your inbox and you can
3:16click the
3:17link to verify your account.
3:19Going back to this particular page, you can now select "I have an account."
3:22So let's click this link here.
3:24And all you would do would be to enter that email registered with this account
3:27and pop
3:28in your subsequent password.
3:29So I will just log into mine right now.
3:31Perfect.
3:32Now I've logged in if I just scroll on down.
3:34Now it takes me to my license information.
3:36Now over here, this is where the license key happens to be now, because I don't
3:40want to
3:41share my license with absolutely everyone that's watching this video.
3:44I have just obscured this.
3:46But once you have registered, you will have your own license key.
3:49So all you want to do is to copy that particular key.
3:51Once you have done that, we can now go and click "Manually Download."
3:55And then simply save the download.
3:58And when the download completes, just double click.
4:01Run through all the prompts in the installation wizard and when you are asked,
4:04simply supply
4:05and copy in your own personal license key.
4:08And once you've done that, you will be presented with an interface quite like
4:11this.
4:12There on the left hand side, I've got a whole bunch of virtual machines that I
4:15have created
4:15prior to this course.
4:17If you have a brand new installation, you will not expect to see these down the
4:19left
4:20hand side, don't worry about it.
4:22We're going to create our own Red Hat Enterprise Linux from scratch using this
4:26VMware software.
4:27So now we have access to our VMware virtualization solution.
4:30What we now want to do is to get our hands on a Red Hat Enterprise Linux image
4:34in order
4:34to create that real machine.
4:36So with that said, let's do it.
4:38So in order to get this ISO image, we need to create a Red Hat account.
4:42The first place I'm going to go to is to developers.retat.
4:46So let's click this link right here.
4:48Now in the top right, if I just click log in, what I can do is pass in my Red
4:52Hat account
4:53details right here.
4:55However, if you do not already have that Red Hat account, you would just go
4:58down to
4:59the bottom here and register for a Red Hat account.
5:01So let's just click this link here and you will have to provide some basic
5:05login information
5:06such as your login ID.
5:08So choose a username, give it a password, fill in the personal information,
5:12your first
5:13name, last name, email that type of thing.
5:15Then accept the terms and choose create my accounts.
5:18Now once you actually have a valid Red Hat account, what I'm going to do is
5:22search for
5:23Red Hat Enterprise Linux downloads.
5:25So if you click this link right here.
5:27Now this part is important if you happen to have a regular Windows machine or
5:31an older
5:32MacBook, basically if you happen to have an Intel processor, you can just
5:36select download
5:37rail at no cost right here.
5:39In my case though, because I'm using an M1 MacBook, similarly if you happen to
5:43be using
5:43an M2 MacBook, the newer one, anything Apple Silicon, you're going to have to
5:48get a very
5:48specific version of rail and that is the ARM version, the ARM architecture.
5:53As such, we are going to select more ways to try.
5:56So depending on what you have at home, choose whatever one is appropriate.
5:59In my case here, I'm going to click this link.
6:01So if I just scroll on down right here, the one I want to get is Red Hat
6:05Enterprise Linux
6:07ISO for servers and workstations.
6:10So notice in my case here, I can choose the ARM 64 button, in fact you can also
6:14choose
6:15the regular Intel version if you so want from this page here too.
6:18Now when I click this particular link, if you aren't already logged in, it's
6:22going to
6:22prompt me to login.
6:23This is why it is very important that we have that Red Hat account created.
6:27So click the page, once you've logged in, you'll be presented with a download.
6:32In my case here, I will just choose save and now I'm going to be downloading
6:36Red Hat Enterprise
6:37Linux with the ARM architecture.
6:39So now whilst that download, we will soon have access to Red Hat Enterprise
6:43Linux as well
6:44as our virtualization solution in VMware, what we now want to do is to begin
6:48setting
6:48up our lab environments.
Setting Up the Lab Environment
0:00So friends, now that we have access to Red Hat Enterprise Linux, as well as our
0:04virtualization
0:05software, what we want to do is to create three different virtual machines.
0:10Now in the case here, we're going to have one particular virtual machine which
0:14is going
0:14to act as our Ansible Control node.
0:17Pretty much this is going to be the machine that is responsible for managing
0:21all other
0:21machines.
0:22Don't worry about the terminology too much, we'll talk about an in an upcoming
0:26video.
0:26So this is going to be the machine that is responsible for doing all the
0:30automation.
0:30And quite simply Ansible is just software that we're going to install on a Red
0:34Hat Enterprise
0:35Linux machine.
0:36So once again, the first VM is going to be a Rail based and quite honestly, the
0:40next
0:41two machines, machines two and three are also going to be Rail based.
0:46Now just a point of note with respect to using Ansible, the machines that Ans
0:50ible manage
0:50do not all have to be Red Hat Enterprise Linux.
0:53They could for example be Ubuntu, they could be Rocky Linux, whatever it may be
0:58.
0:58The reason why we're using two more additions of Rail has quite simply on the
1:02examination,
1:03you can expect to be managing and dealing with Rail systems.
1:06So it just makes sense to have an entire lab environment all working with Rail.
1:11So like I say, we'll have three different Rail machines, the fourth Rail
1:14machine we
1:14will install Ansible.
1:16In this case here, I'm going to recommend that you install a graphical user
1:19interface
1:20based Rail machine.
1:22This makes things easier to operate.
1:23Now with respect to the machines that are going to be managed by Ansible, if
1:27you happen
1:27to be struggling for resources, then you could get away with just using a
1:31minimal install.
1:33This pretty much means that you're just going to get a basic command line
1:36interface, no
1:36nice graphics, no web browser, that type of thing.
1:39But honestly, it's going to be more than enough to practice working with Ans
1:42ible.
1:43Now in my case, the two other additional machines right here, I am also going
1:47to install them
1:48with a graphical user interface.
1:50The reason why I'm doing that is because I have plenty of resources on my
1:53personal computer
1:55and for the purposes of recording, visually for you at home watching, it just
1:58makes it
1:59nice that if you happen to be looking at a graphical user interface.
2:01But like I say, if you're struggling for resources by all means you can do that
2:05minimal
2:06install for those two.
2:07So let's first walk through the creation of our first machine here, which is
2:11going to
2:11have Ansible installed on it.
2:13So I will pull up my VMware.
2:16Depending if you happen to have a Windows based installation, the interface
2:19might look
2:19a little bit different, but ultimately the configurations are going to be the
2:23same.
2:24The first thing we want to do is to create a new virtual machine.
2:26So I will go to file here and then choose new.
2:29In the case here, I'm going to install from a disk or image.
2:31This is going to be the real image that we just downloaded in the previous
2:35video.
2:35Let's click continue.
2:36So in my case here, I will just choose the real image and then select continue.
2:41So right now we have some default settings as it transpires by default, I'm
2:45using 2Gig
2:46of RAM and 20Gig of hardware space that is going to be plenty fine for me.
2:51So if you so wish you can just choose finish.
2:53But if for example, if you happen to have more resource to despair, no harm in
2:57choosing
2:57customized settings, let's just give the device a name, which is called this
3:01rail control
3:02click save and then you can go into process as a memory.
3:05If you so wish you can crank the memory up to whatever you need.
3:08Allocate more processes that type of thing if you so wish but the default
3:11should suffice.
3:13So with that now done, I will just click play and then I'm just going to arrow
3:16up to actually
3:17install red hat enterprise Linux and just hit enter.
3:20Now just give it some time to boot up and load.
3:22Now the very first time we're going to have to do is to choose your own
3:25language.
3:26In my case here, I'm going to be selecting English and English United Kingdom,
3:30choose
3:31whatever is appropriate for you and then choose continue.
3:34Now the first thing I'm going to do is to choose the installation destination.
3:37Let's click this link here and then I'm going to select this 20 gig hard drive
3:41that I have
3:42cut out for this particular virtual machine.
3:44Once I have that highlighted, I'm going to click again to make sure I see a
3:48tick.
3:48There we go.
3:49And in the case here, I'm not going to worry about data encryption or storage
3:52configuration.
3:53I will leave that automatic and leave the others unchecked.
3:56Let me now just select done.
3:58So with that now done, it says automatic partition and selected.
4:01That's a good sign.
4:02The next one I'm going to go to is network and host name.
4:05So all I want to do is to make sure this ethernet connection is toggled on
4:08right now.
4:09It's on.
4:10If it was off, it would be gray.
4:11In this case here, I want to make sure it is blue.
4:14Once that is done, I will now select done.
4:16Then I'm going to go to software selection.
4:19In the case here, this is going to be my Ansible control mode.
4:22I'm going to recommend you select server with GUI to get that graphical user
4:26interface.
4:27With respect to the other installations, when you're making machine two and
4:30three, if you
4:30so wish, feel free to choose minimal install.
4:33I would select the graphical installation.
4:35So let's choose done.
4:36The next thing I'm going to do is to go down to root passwords.
4:39Let me just give a very bad password or password one, which is absolutely not
4:44secure.
4:45But nevertheless, just for lab and environments, let's just keep it simple.
4:47So again, I will say password one and then I will select done.
4:51Okay.
4:52So now we see the root password is set and then I will go down to user creation
4:56.
4:56Let's click this here and let's just give this a name.
4:59I'll just call this nugget user and I will also make this user and
5:02administrative.
5:03So we can use the pseudo commands and again, just to keep things all simple, I
5:07will just
5:07choose the password or password one.
5:09Like I say, never ever do this in a real live environment.
5:12That's just because it's a lab and any virtual machine.
5:15In the case here, though, I will click done.
5:16It gives me the warning.
5:17Let's click done again to accept it.
5:19And now what I want to do is I want to choose begin installation.
5:23So just give this some time to begin installing all the necessary information.
5:26And most it does that.
5:27I will just temporarily pause the video.
5:29Perfect. Everything has now installed.
5:31What I will now select is reboot system and give it a moment to just reboots.
5:35Okay.
5:36So now we are presented with a login page.
5:38Let's click on our nugget user and I'll type in password one.
5:41Now the first thing it's going to say is do we want to take the tour in this
5:44case here.
5:45I'm just going to select no thanks.
5:47Now notice up the very top here, it says please register your system to receive
5:51software
5:52updates.
5:53If you want to download external packages, easiest way to simply get this done
5:57is to well
5:58register the system.
5:59So let's do that.
6:00So the first thing I will do here is just click X and I'm going to go to my
6:04terminal.
6:05Now you can probably tell that the text is very, very small.
6:08What I want to do is to customize things.
6:10So I'll go to this option here and then go down to preferences.
6:13I will then go to unnamed and then I'll click custom fonts.
6:17And then all I'm going to do is to bump up the font size.
6:21Then I will just choose colors.
6:22I will uncheck this box and then I can select my own color theme.
6:26So in this case here, I will just make the background black and I'll make the
6:29text.
6:30Let's say a red color since it is red at now.
6:32This is certainly not necessary, but just to make things a little bit easier to
6:36follow.
6:36I'm just going to rename the actual computer itself.
6:39So I will just say siddle hostname cTL set hyphen hostname and I will just call
6:45the device
6:46red box.
6:47Now I'll type in my admin password, which is going to be password one.
6:50Now right now the name has not changed.
6:52But if I happen to close the terminal, go back up to activities, open up a
6:56brand new
6:56one.
6:57Notice the name has now changed now with respect to registration.
7:01We're only going to concern ourselves with registering the device that is going
7:05to be
7:05running Ansible, which in my case here is this particular machine.
7:09So what I'm going to do is say sudo subscription manager and then the word
7:13register.
7:14Now I'll have to type in my admin password, which is password one.
7:17And now what I'm going to have to do is to provide my red hat enterprise Linux
7:21details.
7:22Remember we created our accounts.
7:23So all I will do is type in my email associated with my red hat account, which
7:26in my case
7:26here is IPV zero.
7:28If I enter, what I'm now going to have to do is to provide the password that is
7:33associated
7:34with my red hat account.
7:35So this is not the password one that I created on this machine.
7:38It's the actual password that we created when we signed up with red hat.
7:42So I'll type it in and to enter give it a moment to register.
7:46And now it says the system has been registered.
7:48What I now want to do is to say sudo subscription manager, attach and to enter
7:53and we can see
7:53the registration has been successful.
7:55Perfect.
7:56So if I just say sudo dnf repo list, we now have access to these particular
8:00repositories.
8:01And now what I want to do is I want to install Ansible core.
8:04So let me just clear the screen and I will now say it's sudo dnf install and
8:08let me just
8:09access out to clear the screen.
8:11And I will just say Ansible hyphen core.
8:13If I hit enter, give it a moment to pull in the information, I will just say
8:17why and to
8:18enter and there we go.
8:20So with that now done, what I should be able to do is to say Ansible dash dash
8:24version.
8:25And we actually see the Ansible version information right here.
8:28Now you'll notice for the purposes of recording, just to make things a little
8:31bit easier on
8:32the eye, I changed the color of the prompt.
8:34But that is certainly not anything you have to worry about yourself.
8:37What I'm now going to do is simply shut down the machine right now.
8:40So if I say shut down dash H now and to enter, we have now created our control
8:45machine.
8:46Let's now quickly spin up a device that is going to be managed by Ansible.
8:49So let's go to fail and new once again, follow the same procedure, install
8:53image and just
8:54walk through the same type of process.
8:56Choose a disk.
8:57If you want to use a minimal install, you can reduce these resources greatly.
9:01But for me, I'm just going to leave them at the defaults.
9:04And I will just call this rail blue box.
9:06The name itself doesn't actually matter, but just choose anything you so wish.
9:10So I'll pull this up, choose install and I'm just going to follow the same type
9:14of options
9:14and continue.
9:16So like I said with software selection, feel free to choose minimal install if
9:20you so wish.
9:21Same again when it comes to the root passwords.
9:23I'm just going to keep things really simple, choosing password one and I will
9:27select done
9:27and done again for the user creation.
9:30I'm again going to select nugget user and again, keeping it simple, just use
9:34password
9:34one again, making this user the administrator.
9:37Once that's done, begin installation.
9:39So once again, reboot the system.
9:41So on this particular box, we do not have to worry about registering the system
9:46nor do
9:46we have to worry about actually installing Ansible.
9:49And all I did on this particular device was change the host name to blue box to
9:53make it
9:54easier to follow.
9:55Now what I'm going to do is stop the video and in the meantime, I will create
9:59one more
9:59managed device in the exact same way that I created the blue box.
10:03The only difference being is that it's going to have a different host name
10:06known as yellow
10:07box.
10:08From now, I will stop the video, continue the task and I will see you in the
10:12very next video
10:12where we talk about SSH authentication.
SSH Configuration
0:00So friends, in this particular video, what we're going to do is set up SSH keys
0:05so that we can
0:06authenticate into our managed devices, that is going to be the blue box and
0:10yellow box
0:11from the Ansible control node without having to enter any passwords. And now it
0:17's not just that.
0:18What we want to do is on each of our machines, that is the Ansible control node
0:22, as well as
0:23the managed devices, we want to create a user called Ansible. And this is going
0:28to be a dedicated
0:29user account for Ansible to operate. Now it's not absolutely essential that you
0:34create
0:35a Ansible user, but realistically for managing things such as security, having
0:39this dedicated
0:40account really does keep things a lot cleaner. So the very first thing is we
0:44will create that
0:45Ansible account, we'll say it's sudo user ads dash M, and I will just say Ans
0:49ible. And then I
0:50will say it's sudo pass wd and then specify the account I want to create the
0:55password for,
0:56which is Ansible. If I hit enter, now what I'm going to do is specify the
1:00password that I want
1:01to use for the Ansible account. Now just to keep things really, really simple,
1:05I will alter
1:06as call the password Ansible. Okay, once again, not exactly best practices, we
1:10can see we're getting
1:10a warning that this is a bad password, but nevertheless, let's just stick with
1:14the word
1:14Ansible again. Okay, so we now have created this Ansible user, let's do the
1:19same thing on the
1:20other two machines. So I'm here on the blue box, let me just say sudo user ad
1:26dash m Ansible,
1:27type in the password of password one for super user privileges. And now I will
1:31create the
1:32password for the Ansible user so sudo pass wd Ansible. Again, the password is
1:36simply going to be the
1:37word Ansible. And let's just confirm that and to enter. Now let's go to the
1:42yellow box. Once again,
1:43let's just create the Ansible user and we'll give the Ansible user password of
1:48Ansible and once
1:48again just confirm that password. Now what I also want to do is to give the Ans
1:52ible user account
1:54access to the sudo command without having to type a password. Once again, we
1:58will handle this a
1:59little bit different in a real environment, but for simplicity and for the
2:03purposes of the
2:03examination, we are absolutely fine to do so. So let's just say sudo vice sudo.
2:07And if we scroll
2:08all the way down just below this part here that says route all equals all, all
2:13I'm going to do
2:13here is say Ansible, which is the name of the user accounts, and then say all
2:17equals a name
2:18within parentheses all. And then I would just say no pass wd colon and then the
2:24word all. So if I
2:25just write and quit, let's do the same thing on blue box and yellow box. So
2:29once again, sudo vice
2:31sudo and just type in the exact same information again. Perfect. So colon
2:35writing quits. And lastly,
2:37on the yellow box machine, we just sudo vice sudo and again, just type in the
2:41exact same content.
2:43Once again, saving with a wq. So if on my main machine, I just type ipadder, we
2:48can see the ip address
2:49happens to be 192168160.133. And we want to be able to reach the blue box and
2:56yellow box. So
2:57let's see what their IP addresses are. So once again, we just do ipadder on the
3:02blue box, we can
3:02see this is 192168160.134. And over on the yellow box, we are on 160.135. What
3:11I actually want to do
3:12now is to create some SSH keys for login. Now what I'm going to do is I'm going
3:16to create these keys
3:17as the answerable user sources, sudo su hyphen answerable and I enter, we can
3:22now see the username
3:23has changed to answerable right here. And what I'm going to do is say SSH hyp
3:28hen key gen and
3:29enter. That's going to tell me the file where it's going to save automatically.
3:33That is fine. So
3:34I'll just hit enter. It's going to ask me for a passphrase. Now in the real
3:38world, once again,
3:39we absolutely want to be adding a passphrase but for simplicity for the
3:43examination.
3:44Absolutely find you to leave this blank. So let's just hit enter and enter
3:47again. And now we have
3:49automatically generated our SSH key pair, the public key as well as the private
3:54key. Now what
3:54we want to be able to do is to share the public key with the blue box and the
4:00yellow box. This
4:01is going to allow us to authenticate in as the answerable user to those devices
4:05without having to
4:06type in the password answerable, which is going to be much, much better for us
4:10when working an
4:11in automated fashion. So all I will say is SSH hyphen copy ID. And then I will
4:17say answerable at
4:18192.168.168.134, which is the first machine the blue box machine. If I enter, I
4:25will say yes.
4:26And I will type in the password of answerable the very first time I'm doing
4:29this authentication.
4:30Perfect. We have now added the key to that particular machine for the blue box.
4:35And similarly, if I arrow up and do 135, I answer, I now say yes to add the
4:40fingerprint. I type in
4:42answerable again. I now log into the yellow box and transfer my public key over
4:47to that particular
4:48device. So now moving forward whilst I'm on the red box itself, the answerable
4:52control node,
4:53if I now just want to authenticate into that particular device, say for example
4:57, the blue box,
4:58I can just say SSH, answerable, and then type in the IP address of 192.168.134.
5:05And to enter,
5:06notice we authenticate straight away without having to type in the passphrase.
5:10I'm now on the
5:10blue box. See that right there? And again, if I exit out, arrow up, type 135, I
5:15enter,
5:16automatically, we just slide directly into the yellow box without having to
5:20type the password.
5:20That is exactly what we want. So now we have the basic setup of our lab
5:24environments. We have
5:25our three virtual machines. We have now created a dedicated answerable user for
5:29all three devices
5:31and have now configured passwordless SSH key authentication. With that now done
5:36,
5:36we are ready to begin talking about answerable.
Ansible Basics
0:00So friends, let's talk a little bit about what Ansible actually is.
0:04Well quite simply, at its most basic level, Ansible is an automation tool that
0:09has been
0:09developed by Red Hat.
0:11So think about the tasks that you would do as a Linux administrator.
0:15Perhaps you're managing 1000 servers and you want to go in and maybe modify the
0:19DNS
0:20settings, as opposed to having to log in to each device one by one by one.
0:24To manually make those configuration changes yourself, utilising a tool such as
0:29Ansible,
0:30you can have that change be automated all at once and have the system updated
0:34in the
0:35blink of an eye.
0:36Now the way Ansible operates, it uses something known as a push model.
0:40Let me just describe what that looks like.
0:42So imagine over here we had a Red Hat based system.
0:44This could just be a virtual machine and on that system you happen to install
0:49Ansible
0:50Looker.
0:51Here is going to be the machine that is going to manage all of the devices in
0:54the network.
0:55To say for example you had a whole ton of different servers that you're
0:58managing.
0:59One could be an Ubuntu machine, one could have it be Red Hat enterprise Linux
1:03as well,
1:03one could be Fedora, one could be Kali Linux, it doesn't actually matter.
1:06The point is if you happen to be a system administrator responsible for
1:10managing all
1:11these devices, having Ansible installed on one particular control mode will
1:15allow you
1:16to connect all of these devices at the same time and push out those updates.
1:21Now the reason why we refer to Ansible as using a push model to make its
1:24configuration
1:25changes is if you happen to have let's maybe say two machines over here that
1:28you're managing,
1:30the cool thing is that these devices here that happen to be managed by Ansible,
1:34this
1:34device here, these machines do not have to install any particular software you
1:39don't
1:39have to install Ansible here or here.
1:42You simply install Ansible on the device that is going to be performing the
1:46automation
1:47in that Ansible enabled device simply pushes out those changes to these
1:51different nodes.
1:53So all happens from here and is pushed outward towards the network, that is
1:56what we're referring
1:57to.
1:58Now as we move through this particular course there's going to be a strong
2:00emphasis on
2:01something known as YAML, pretty much this is a file format that is designed to
2:05be very
2:06human readable but it allows us to actually utilise programmatic logic, just
2:10like you
2:11can do so with say for example Python code except this time the code that we're
2:15writing
2:16quote unquote really doesn't look like code, it is very very easy on the eyes,
2:20really
2:20really easy for system administrators to look at and understand.
2:24Now with respect to Ansible the actual architecture can be broken down into
2:28four core components.
2:30The first component is the configuration file, typically this is going to be
2:34called Ansible.cfg
2:36and using this particular file you can specify global system settings, we'll
2:41get to see
2:41what this looks like in the very next video.
2:44Crucially though within the configuration file we can also specify where abouts
2:48we can find
2:49the next component of the Ansible architecture and that is the Ansible
2:54inventory.
2:55Now the inventory basically tells Ansible what devices should be managed.
2:59Now in our lab environment we have created two particular machines that are
3:03going to
3:03be managed by Ansible so in order to let Ansible know about this we would
3:07specify information
3:08about those devices in the Ansible inventory so that could include things like
3:12the IP addresses
3:13of those particular devices or maybe their host names, that's how Ansible knows
3:17which
3:17devices it should actually be connecting to.
3:20Now as you progress throughout this course we're going to learn that the
3:22inventory can
3:23be really really valuable, it can use things such as groups as well as by the
3:27way groups
3:28within groups otherwise known as nested groups but for now as our introduction
3:33we don't
3:33have to worry about that quite just yet, just understand that as a part of the
3:37Ansible
3:37inventory and it's one of the reasons why Ansible is so powerful.
3:41Now the third component I want to talk to you about, this is something known as
3:45variables,
3:46this is a very well known concept within programming because when we happen to
3:50be automating things
3:52whilst a lot of the information might be very repetitive we can just
3:55effectively have the
3:56automation system push out the same changes to all devices, we understand that
4:01with respect
4:01to particular configurations on particular systems we have a requirement for
4:06some configurations
4:07to be unique, basically they're not going to be the same, they're actually
4:10going to be
4:11varied depending on the device we are connecting to.
4:14So say for example we're managing two devices right here, let's just call it
4:17device one
4:18and device two and let's just say this is our Ansible machine right here that
4:21can connect
4:22to these devices.
4:23Now some things may be very common perhaps we're going to push out the same
4:26change to
4:26both devices, maybe that'd be safe for example some DNS server information
4:30perhaps they're
4:31both going to be updated to use the server 8.8.8.8 that is absolutely fine,
4:36however maybe
4:37at the same time whilst we're giving both devices the same DNS we want to
4:42update their
4:42IP address information and the IP addresses on these devices actually have to
4:47be unique
4:47we can't give the same IP address to both devices, as you're going to see the
4:51way we
4:51solve for this particular problem is via the use of these variables now we can
4:55have things
4:56known as host variables which are variable values unique to a particular host
5:01in the
5:01inventory but we can also have group variables these could be values unique to
5:05a particular
5:06group of devices perhaps we happen to have four devices in the UK and all of
5:11those UK
5:11devices have to get a particular NTP server that is different from all of the
5:16servers
5:16in the United States we can specify those UK unique values as a group variable
5:22and target
5:22all of the UK devices in the inventory.
5:25Once again we'll get to see this in more detail later on as we progress now the
5:29fourth and
5:30final component here this is known as the playbook and really this is how we
5:34tie everything
5:35together it is inside the Ansible playbook which happens to be written in YAML
5:40where
5:40we actually tell Ansible what it is we want it to do this is where we write our
5:45instructions
5:46you know like go and configure a DNS server go and update the NTP
5:49configurations go and
5:50create a whole bunch of new users on all of these devices so now we have a
5:54rough idea
5:55about what Ansible is and what it can do what we want to now do is to begin
5:58setting up our
5:59system so that we can then slowly begin automating tasks across our managed
6:04devices now in this
6:05particular skill we're not going to be looking at playbooks quite just yet or
6:09the concept
6:10of variable values but in the very next video we're going to be talking about
6:13the creation
6:14of that Ansible configuration file as well as the construction of our Ansible
6:19inventory
6:20once we have done that we will run Ansible against those devices to test for
6:24basic connectivity
6:26and that will have our lab up and running and put us in a really good place to
6:29continue
6:30on this journey throughout this course when we will begin using these playbooks
6:34to automate
6:35a whole bunch of really cool and useful tasks so with that said let's get going
6:39.
Configuring Ansible
0:00Okay friends, so let's get hands on with Ansible.
0:03So the first component that we are going to talk about is that Ansible
0:07configuration file.
0:08So if you happen to search for Ansible configuration file, you can click this
0:13top link right here.
0:14And notice it says here that certain settings in Ansible are adjusted with this
0:20particular
0:21file Ansible.cfg. Now one thing to note, Ansible is going to seek to find this
0:26particular configuration
0:28file in a variety of different places, each with a greater priority than the
0:32other.
0:33Now it says here the pass where the configuration file is searched and listed
0:36as in the reference
0:37documentation. If we just click this link here, this here is effectively the
0:42locations and priority
0:43levels in which Ansible will look for this particular configuration file. So
0:47the first thing is that
0:48if you happen to set your own environment variable and point it to a particular
0:52location,
0:53this is the first and primary location where Ansible is going to seek to find
0:57this particular
0:58file. Now if you have not set this environment variable, the next place it's
1:03going to be checked
1:04is for a file called Ansible.cfg in the current directory. So whatever you
1:09happen to be running
1:10Ansible from, it's going to say hey, is there a file in the same directory
1:14right here called
1:15Ansible.cfg and if it is, then it's going to look to use the configuration
1:20specified within that
1:21particular file. Now if you do not have the Ansible configuration file within
1:26the current directory
1:27where Ansible happens to be running, the next location is going to be in the
1:32user's home directory.
1:33So we can see this via the tilde character, which we know is their home
1:36directory. Now if
1:37you've got a key now, you'll notice that we happen to have a dot before the
1:41word Ansible.
1:41Denoting that in this case here, this would actually be a hidden file. Now
1:45suppose you have not created
1:47any of these environment variables or the files in these particular directories
1:51, the general
1:52system way configuration file is going to be found in the exit directory and
1:55then into the
1:56Ansible folder and the file itself will simply be just called Ansible.cfg. That
2:01is the order of
2:02operation. Now in my case here, the practice that I tend to follow is just
2:05simply putting an
2:06Ansible.cfg file within the directory in which I am working. You can specify
2:11anything you so
2:12wish, but that is the practice that I am going to be following. If you don't
2:16use that particular
2:17practice, just at least understand the order of operations and where Ansible is
2:20going to look to
2:21find that particular config. Now if we search Ansible inventory, let's collect
2:26this link here.
2:27If we scroll on down, we can see some examples of Ansible inventories. Here we
2:31happen to have
2:32what is known as an Ansible inventory in the I and I format. The way we
2:36construct this is we
2:37specify our group names in square brackets. We have a group here called web
2:42servers and inside of
2:43the web servers just below, we specify the actual nodes which belong to that
2:47particular group.
2:48So food.example.com and bar.example.com, they happen to be web server devices
2:54and below we have to have
2:55a grouping of database servers, DB servers, and the nodes belonging to that
2:59particular group is
3:01one dot example.com, two dot example.com, and three dot example.com. Now in my
3:06opinion,
3:07this happens to be the easier way to happen to construct your Ansible inventory
3:11, just as
3:11really simple, doesn't cause any hassle. But ultimately, I would say it's best
3:16suited for
3:17simple inventories. If you just happen to have some groups, a few nodes
3:20belonging to those groups,
3:22then it is a very good way to structure your Ansible inventory. Below though,
3:26we can see the same
3:27type of information specified in the YAML format. Now the interesting thing
3:32here is with respect
3:33to YAML, we have a lot of emphasis on indentation. We'll talk about that a lot
3:37more in an upcoming
3:38skill. But basically, the indentation is very, very important if you happen to
3:42get the indentation
3:43wrong. The way the information is ingested is going to be completely different.
3:47And in fact,
3:48it can just be invalid and well not work. So in my opinion, this is a little
3:52bit more complex
3:53because an armor rose to follow is easier to get the syntax wrong. However, if
3:57you happen to have
3:58groups within groups, i.e. nested groups in a much more complex inventory,
4:03having that information
4:04represented in YAML format is actually a lot easier to look at visually because
4:08you can easily see
4:10via the indentation, which group belongs to which group. And to quickly assess
4:14visually,
4:15the order of the hierarchy. Now like I say for error purposes, it's going to be
4:19really quite
4:19simple. So I'm just going to stick to the i and i format. If you so wish, if
4:23you're more comfortable
4:23with YAML, then feel free to construct your inventory in that manner. So with
4:29that said,
4:29let's go and begin configuring our Ansible configuration file. Once again, I'm
4:33going to specify mine
4:35within my working directory. So right now I'm inside of the Ansible Home
4:39Directory for the Ansible
4:40user. If we do a listing, we can see we have no files or directories within
4:44here. So what I'm
4:45going to do is I'm going to create a particular file just called Ansible.cfg.
4:49If I create that,
4:50do a listing, now that file exists. But as we know, there is no content within
4:54that particular
4:55file. Let's add to it. So I will just say them Ansible, CFG. If I hide for
5:00insert, I can go into
5:01insert mode. And similar to the Ansible inventory, this is also going to be
5:05written via the i and i
5:06format. So I'm going to say within my square brackets, I'm going to create my
5:10default group,
5:10which is going to effectively denote my default settings. Now the first
5:14directive I'm going to
5:15give is specifying where abouts my inventory can be located. Now by default, if
5:19you did not
5:20specify an inventory location, the default is going to be in the Etsy directory
5:25. And then within
5:26the Ansible directory, there should be a file called hosts. So if we don't
5:30specify it here,
5:31Ansible will look to this particular file. But in order to keep things simple,
5:36I'm going to
5:36specify the Ansible, she looked within the current directory for a particular
5:40file called inventory.ini.
5:42Now I'm going to specify the directive for the remote user. This is basically
5:46going to be the
5:47username. The answer was going to use in order to access the remote machines.
5:52Now remember,
5:52we created a dedicated Ansible user account on the devices that we're going to
5:56manage.
5:57So right here, we're going to specify that Ansible should actually use that
6:00particular account
6:01when logging in. Now I'm going to say host key checking, we're going to specify
6:05that as false.
6:06We don't really care about key checking. And then I'm going to say deprecation
6:09warning pretty much
6:10very often. Ansible is going to give you warnings about modules and whatnot
6:14that happened to be
6:15outdated. We don't want to have to worry about that. So I'll just leave these
6:18warning messages
6:19set to false. So these are our default configurations. What I now want to do is
6:23to specify how Ansible
6:24can actually elevate privileges. You know the way you do when you happen to
6:28have a shell within a
6:29device, you can just say, so do and then type in the super user password. That
6:34is how we could
6:34perform an administrative system wide task. In the case here, we want to tell
6:38Ansible how to do that.
6:39So I'm going to say with 10 miles square brackets, once again, privilege
6:43escalation,
6:44basically how we can escalate our privileges. What I'm going to say is become
6:48equals true,
6:49which means we are going to seek to become the root user. I will specify how we
6:53actually elevate
6:54our privileges by specifying the become method. And I'll say we do that via the
6:58sudo commands.
6:58And then I'll say the become user is simply the root user. And I will say
7:03become ask pass.
7:05And I'll set that to the value false. We don't want to be asking for passwords
7:08after all.
7:08So with that now done, if I press escape and then colon wq to writing quit and
7:13then hit enter,
7:14we have now written this configuration file. Now as per the configuration file,
7:18we specified
7:19that there should be a file called inventory.ini within the same directory
7:23right now that doesn't
7:24exist. So let's just create it by saying touch inventory.ini. If I don't LS and
7:29now that file exists,
7:30and we want to actually specify the content of that file. Okay, so the very
7:34first group that I'm
7:35going to create is going to be the all group that is going to comprise of all
7:38of my devices in the
7:39way specify this group is by using square brackets. Now below here, I will just
7:43add in all of my
7:44devices. Now there are different ways we can solve this particular problem. Let
7:47's maybe say we've
7:48got the blue box here, I can tell Ansible is IP address by saying Ansible
7:52underscore host.
7:53And then given IP address of the actual device, so 192 168 dot 160 and do 134.
8:00And then for the
8:00yellow box, I would just say yellow box, then specify the Ansible host value is
8:04going to be
8:05the IP address of 192 168 dot 160 dot 135. This is perfectly valid. What you
8:11can also do by the way,
8:13which I would not recommend is just putting in the IP addresses of the devices
8:17themselves
8:17without any type of resolution going on. So basically you can get away with it,
8:22but I certainly
8:22wouldn't recommend you do that. Now the way I'm going to show you is we can
8:26also do it another way.
8:27If I just delete this right here, and I just specify the names of the hosts I'm
8:32going to be
8:32managing. So I've got my blue box and my yellow box. Now right now here, we do
8:36not have any IP
8:38address information. We're going to have the system resolve this via my Etsy
8:42host file on the
8:43control mode. So let's just save this right here. And if I say pseudo vim
8:46forward slash Etsy,
8:47forward slash hosts and enter, here's what I'm going to do. I'm going to type
8:51in IP address
8:52of my devices to have a static mapping. So 192 168 dot 160 dot 134. This is
8:58going to be my
8:59blue box. So I will type in the domain for blue box, let's just make one up of
9:03blue box dot example
9:04dot com. This doesn't actually exist by the way. And we can also have an alias
9:08shorthand of blue box.
9:10Similarly, I will say 192 168 dot 160 dot 135. And this one here is going to be
9:17yellow box dot
9:18example dot com and have the shorthand alias of yellow box. So now we have this
9:23static mapping on
9:24the system. So when Ansible looks up the name of blue box or yellow box, which
9:29it finds within
9:30its inventory right now, it's going to know to resolve that to the
9:34corresponding IP addresses.
9:36If I just happened to say, for example, paying blue box, notice what is
9:39actually happening.
9:40We're getting the resolution right here. We're actually getting back the
9:43correct IP address.
9:44And similarly, if I ping the yellow box, now we're getting the correct
9:48resolution and response
9:50from that particular machine. And if you swished, if you had many more devices,
9:54you could add in
9:55more groups. So for example, a UK group, and then add in all devices that were
9:59part of the UK group,
10:00if you swished, and again, add the USA group, like devices three, four and five
10:04. But as you know,
10:05right now, I don't have any of those devices. So let me just remove them for
10:09the moment.
10:09So with that now configured Ansible is ready to rock. We are all set up and
10:14ready to automate
10:15our lab environments.
Team training path
Turn this skill into assignable team training
This free skill is a preview of the courses your team can assign, track, and report on with CBT Nuggets.
$708
seat / year