Sandbox Environment with Vagrant

Loading

In this blog, we will take you through the process of configuring a small Ansible environment using Vagrant. Vagrant provides a solution for creating disposable or sandbox virtual dev environments, all within a single Vagrantfile, which closely mimics the production environment. We define everything we need in a VM in the Vagrantfile and Vagrant will take care of configuring those in the VM.

Vagrant uses a concept of base images for operating systems that are customised and stored in a public Vagrant repository, and for this configuration, we will be using the standard RHEL9 image.

Lab Configuration

We have the following VMs created which will be later used for the Ansible Tower configuration.

HostnameRoleIP Address
aapAnsible Automation Provider10.0.2.50
haproxyLoad Balancer10.0.2.51
webserver01Web Server10.0.2.52
webserver01Web Server10.0.2.53
dbDatabase Server10.0.2.54

How to Manage Vagrant

Here are some useful Vagrant commands to manage our VM’s.

vagrant versionShow version of Vagrant
vagrant init <image name>Initialize the Vagrantfile eg: generic/rhel9
vagrant up <VM name>Launches the VM
vagrant halt <VM name>Shutdown the VM
vagrant reload Restarts the VM
vagrant statusShow the current state of the VM
vagrant sshssh connection to VM
vagrant destroy <VM name>Delete the VM

Prerequisites for Installing Vagrant

Vagrant is a wrapper utility that works on top of Virtual machine solutions like Oracle Virtualbox, HyperV, VMware, Docker etc.

Create a Lab Environment with Vagrant

Create a directory to define and hold the configuration necessary for Vagrant to run. Our defined Vagrant file is added to this location and Vagrant uses the configuration in the Vagrantfile to build out the VM’s

Define the Vagrantfile for Multiple Vagrant VMs

Define the following for our webserver config web01config.sh & web02config.sh

Start the virtual machines by running the following command:

Show the status of all virtual machines by running the following command:

Connect to the VM via ssh command

(Visited 29 times, 1 visits today)

By Ash Thomas

Ash Thomas is a seasoned IT professional with extensive experience as a technical expert, complemented by a keen interest in blockchain technology.