Now let's take a look at hands on demonstration and how we can set up and start our virtual machines
and verify once they are started up that we've got connectivity.
Now we are going to set up our virtual machine so we can run Vagrant and Virtual Box on pretty much
any of our operating systems on Windows, macOS and Linux.
As you remember, it's free and there is no charge for Vagrant or Virtual box.
So so ensure that you have those installed.
Once you've got them installed, then create yourselves a working directory.
I've just set up, I've just created a top level called Vagrant in my home directory and a sub directory.
So they are really work as project directories so we can create the virtual machine configuration files
within our project directory.
We've got a vagrant file, so if you go through and just list out the contents of this, we've got a
vagrant file and we've got an Ansible playbook to help configure these systems.
Both the playbook and the vagrant needs to be in your working directory.
And of course you can use Git clone to just grab this directory and run vagrant from here.
The address for this repository is GitHub.com, the Labs eight Vagrant.
We'll take a look at their contents, but we can clone their contents.
Let's just move out to to my home directory.
So just city on its own.
I run a get clone and then http as going through the github.com and looking at my repository.
So.
So this particular directory got a copy of vagrant file and the ubuntu dot yaml file for you to use
so you don't have to worry about creating them by yourself.
When I take a look inside of the vagrant file, the main configuration that we are looking at is then
a configuration block that is shared for all of our virtual machines and we are using the Ubuntu slash
focal 64 image.
We're going to provision both so that we can install extra configuration options using ansible.
So ansible will be installed on our local systems and our virtual machine guests and we'll run them
the ubuntu dot yaml playbook.
Each of the systems has been assigned to gigs of RAM and two virtual CPUs.
As we then take a look at ubuntu one where set in the hostname and the IP address of that and then the
specific configuration block for ubuntu to where we are setting up its host name to be ubuntu two and
the 1922 address the playbook itself.
If I go through and look at the ubuntu dot yaml file, so the ansible is going to do some further configuration
making sure that where we update our package cache and upgrade any software that needs upgrading.
We are added in the ubuntu ssh server configuration file just to make sure that we can use password
based authentication by default.
It is disabled in this VMs and then we'll restart the SSH server.
Now it's easier doing this through Ansible so we don't have to get into the detail too much of what
we're looking at.
We'll learn more about this as we go through any vagrant commands.
Them that are issued from this directory are going to work with our vagrant file so I can run them my
vagrant command and do a box update, which is just going to make sure that we've got the up to date
version of the virtual machine images.
I can then go through and do a vagrant up.
If I don't specify the machine name, it's going to bring all of the machines up or both of them.
In this case, if there were more virtual machines, for example, five virtual machines, it would
bring up five virtual machines with this vagrant up command.
And if you want to bring up only one virtual machine, you run vagrant up Ubuntu one for example, or
Ubuntu two.
So let's move this on the top of the screen by enter and control.
Just move you to the top of the screen and clear the screens, contents and.
We can then go through and run our Vagrant app command.
It's going to start our virtual machine, so it will clone the virtual box image and then start both
of our virtual machines and then run the previous scripts, which we are running through Ansible.
You can leave this running for a little while and then come back as we come back.
We're able to see the results of what's been happening so we can see the finished configuration, the
Ubuntu to system and previously we would have configure the Ubuntu one virtual machine guest.
So we are up and running, but let's go through and begin by cleaning our screen.
And then the convenient thing that we have with vagrant is then I can just go.
Vagrant.
Ssh.
I don't need to really worry about the system that I'm connected to its IP address.
I don't have to worry about passwords as key based authentication has already been set up, but I do
need to specify to which system I want to connect.
For example, Ubuntu one.
So that then gets us into the system and we are now up and running on Linux.
So everything then is going to be a load helper and you guys are going to be much more happy looking
at Linux than my standard macOS desktop.
So here we are.
Anyway, let's take a look that the configuration worked for us.
If I go through and run and P and proc command, it just becomes a very simple way for the number of
processors.
So I've got two processors.
There is what we had configured.
If I want to check the amount of memory that we've got, I can use three and then this age to display
it in a human readable format.
And we can see that when we set to gigabyte, that gives me roughly 1.9 gigabytes available within our
virtual machine.
So this is the global configuration that was set in our vagrant file, and we can see that it's working
well for us.
When I look at the IP address that I have.
So IP dash four address so we can see them that I've got the 1922.168. 56.101 address.
We can also see that I should be able to pin the remote system so pin 19221.168. 56.102.
And that will that will be the Ubuntu two system that I'm connecting to.
If I don't specify the number of pins to send, it just continues.
But I can use control plus C to stop those pins being sent once I'm happy I've got communication.
If I then go through and use exit, I leave the system and I return back to the MAC system and we're
back then in the Mac OS and I no longer Linux, but at least we've learned how we can get our system
up and running.
I can also use the Vagrant and Status Command to take a look at what's happening with our virtual machines
and we can use that and we can see that they are both running and I can keep them running, but if I
no longer need them, I can use Vagrant hold to power them off.
If I need to start all over again, I can use vagrant up.
I can use a vagrant destroy to destroy and delete those virtual machines.
Now, for the moment I'm going to keep my virtual machines running because we are not really finished
with them at the moment.
Now, if besides this configuration, you need to run some script on this, on the on these both virtual
machines or on one of these virtual machines, you can use VM dot provision configuration and you need
to specify the path to the provisioning script.
Also, if you need to forward some port, for example, if you install like let me show you this Jenkins
configuration file, I'll seed into the parent folder and then seed into the Jenkins folder.
I'll open up this vagrant file.
And as you can see, we've got provision here, the provisioning script path, and we can also forward
port from our vagrant virtual machine to our host machine so we can access this.
Box and our host Virtual Machine.
For example, if we run this virtual machine, we can access this host by typing local host column 88
on our host machine, and we'll get this Jenkins instance as a lab environment.
Now, let me run this virtual environment as well.
I'll type vagrant up.
Jenkins first, make sure that I'm in a Jenkins directory and I'll pause here and wait until this virtual
machine is up and running.
And when it's up and running, I can run the following command.
Vagrant Global status.
And as you can see, we've got three virtual machines up and running, namely Ubuntu one, Ubuntu two
and Jenkins virtual machine.
And now if you want to halt or destroy or start some virtual machine outside of our virtual environment
of our work and folder.
So to say project folder, we can go ahead and run vagrant, destroy and use the virtual machines ID
number so I can select it, press command C and insert it in my vagrant command, namely vagrant destroy
followed by the ID.
Sometimes you can get some screen shares.
That vagrant is being taken by another process and you can not perform this action.
In this case, you could just kill the process of Vagrant.
But first you type piece pipe vagrant and then you type kill Dash nine and the process ID it will kill
the vagrant process and you can run it again.