Cooking up the perfect lab environment with Vagrant
Recently at work, I was tasked with preparing a demo of Oracle Linux Manager and showcasing several features of the software. This is an easy enough thing to do, but there are several barriers to entry that stand in the way before you can access the web GUI for Oracle Linux Manager.
For starters, Oracle Linux Manager requires Oracle Linux 7; it’s not yet certified on Oracle Linux 8. So, I set out to download the ISO for Oracle Linux 7 and proceeded to create a VM in VirtualBox and installed the OS. I then wanted to SSH into the box, so I had to go into the settings menu for that VM and configure port forwarding from the host to the guest. At this point, I was able to SSH in, and then followed the installation instructions for Oracle Linux Manager. It’s not that bad setting things up, but there were several speed-bumps along the way. For instance, I needed to decide on a database to use. Oracle supports only Oracle Database for use with Oracle Linux Manager, but for the sake of brevity (and since this was only ever intended as a lab demonstration of Oracle Linux Manager), I decided to use PostgreSQL.
With so many manual steps, I’d be inclined to keep my newly created virtual machine and take care of it like a pet. They say containers are like cattle, and virtual machines are like pets. That is, until you’ve started using tools like Vagrant. Vagrant does a good job making your virtual machines blend in with the cattle – thanks to how easy it is to recreate your virtual machines using Vagrant, you no longer need to care for them the way you had to previously if you weren’t using Vagrant.
This recipe will walk you through the process of creating a lab environment using Vagrant.
Getting ready
You will need the following for this recipe:
• Oracle Linux
• Oracle VM VirtualBox
• Vagrant
Refer to the Technical requirements section at the beginning of this chapter if you need help installing Oracle VM VirtualBox and Vagrant.
How to do it…
Vagrant is a tool used for managing the lifecycle of virtual machines. In this recipe, we’re going to create a Vagrant box that automatically installs and configures Oracle Linux Manager. Oracle Linux Manager requires Oracle Linux 7. In this case, we can use the official Oracle Linux 7 Vagrant Box as our base:
$ vagrant init oraclelinux/7 https://oracle.github.io/vagrant-projects/boxes/oraclelinux/7.json
Great, that has pulled in a nice base file for us to start with. Let’s look at the Vagrantfile file to see what’s inside:
# Vagrantfile
Vagrant.configure(“2”) do |config|
config.vm.box = “oraclelinux/7”
config.vm.box_url = “https://oracle.github.io/vagrant-projects/boxes/oraclelinux/7.json”
end
The actual Vagrantfile generated by the init command contains 69 lines of code, but 65 of those lines are comments, hence I removed them to help make this recipe more easily comprehensible.
As we can see from this Vagrantfile, all we need is those four lines to launch an Oracle Linux 7 instance in VM VirtualBox. If you want to test it, enter the vagrant up command and when it’s up and running, you can simply enter the vagrant ssh command to access the VM and see how it works. Once finished, type vagrant destroy to bring down the VM. Now, let’s dive into ways to make this more useful; because I want to be able to type vagrant up and have not only an Oracle Linux VM, but also want that same command to result in a working copy of Oracle Linux Manager.