Customizing the Vagrantfile
Articles,  Blog

Customizing the Vagrantfile


Hello and welcome to todays video presentation
on customizing a Vagrantfile on Oracle Linux. In this video we will cover the Vagrantfile. We will talk about what goes into the file
and how to edit it. We will define a Vagrantfile with multiple
machines, a custom configuration and provisioning. So let’s get started….. A Vagrantfile defines the machines used within
your project and how each of those machines are configured and provisioned. The name is derived from the actual file name
used within Vagrant Each Vagrant project is expect to have only
one Vagrantfile When looking for the Vagrant file, Vagrant
starts in the current working directory and searches up the directory tree until one is
found. When you run the vagrant up command, Vagrant
loads a series of Vagrantfiles from default locations and merges them. This merge order allows the ability to ship
a default config with a box and later override specific settings based on your personal use
case. To get started with this demo, It is expected
that you already have Vagrant and VirtualBox installed. Open your terminal to create your project
directory. This is where you store your Vagrantfile and
any files used during provisioning. I have already created this demo which we
will review. Start in our home directory and cd to demo
slash proxyjump. If these directories do not exist you can
create them with mkdir -p demo/proxyjump I have already created a Vagrantfile using
touch Vagrantfile. Next open the Vagrantfile with your favorite
editor. I will be using vi for this demo. Once in the Vagrantfile we see Vagrant uses
Ruby as indicated by the file header. We then created a variable to indicate we
are using Vagrant API version 2. To document our configuration, comments are
defined by a hash mark # at the beginning of the line. If we want to add specific plugins we can
use the next few lines to check if they are installed and if not, download and install
them. In this sample we are using the vagrant-reload
plugin to allow for the reloading of the VM during provisioning And vagrant-proxyconf plugin to configure
the VM to use proxies defined in the host env. When processing the Vagrantfile, Vagrant works
from the outside in when reading the different blocks. Keeping the configuration in this block format
also makes the file easier to read. The outer “config” block starts with the
Vagrant dot configure statement which takes the API version as a parameter. All items belonging to this block begin with
the config name. Lets walk through them. vm dot box defines our box image of Oracle
Linux 8 Latest dot box_url is where to download the box box_check_update decides if we check our box
for updates on every vagrant up ssh dot insert_key uses the Vagrant default
insecure keys for SSH authentication And vm dot synced_folder with disabled set
to true disables a synced folder between the host and the VM To save time during startup in this demo,
the vguest dot auto_update is set to false. This disables the up time check to ensure
the VirtualBox Guest Additions are up to date and match your host. The Oracle Linux 8 box defaults to 2048 MB
of RAM. In this “v” block we tell the provider
VirtualBox to only use 256 MB. Now that we have the basics we can begin to
configure our 3 VM which we will call client, bastion, and server. Each machine will define: a hostname a host-only network interface an internal network interface or two As well as provisioning steps to configure
ssh. Vagrant uses the virtualbox__intnet: network_name
option to designate internal networks verses the host-only configuration. Your VM will also have the default NAT network
which VirtualBox puts on the IP address of 10.0.2.15 as a default. For the provisioning statements, the file
option is used to copy a file to the VM while the shell option will execute a command on
the VM Lastly we define our proxies, set the ssh
forwarding ports on the NAT interface and then additional provisioning using an Ansible
playbook The forward ports will auto resolve conflicts
when multiple VMs are used provided the auto_correction option is set to true. Now that we have reviewed the file, close
the file and quit vi using colon q bang ! Enter Typing ls will show your Vagrantfile as well
as the files used for provisioning. Issue vagrant up and the deployment will start. During startup and provisioning you will see
Vagrant move through each machine. Vagrant will define the NAT, hostonly and
internal adapters and assign the port forwards for NAT. Finally it will complete each of the provisioning
steps. For fun, If you have the cowsay package installed,
you will see ascii cows documenting each step of your Ansible playbook. In this video we created a Vagrantfile which
defined 3 VMs and 2 separate private networks. We then provisioned those systems with pre-defined
ssh-key pairs to ensure secure communication between them. Vagrant has many additional configuration
options available for the Vagrantfile. Details can be found on their website in the
online docs. Thank you for watching and I hope you enjoyed
this video. To find additional resources on Oracle Linux
please check out: Our Oracle Linux Curriculum at http://education.oracle.com/linux Oracle Cloud Infrastructure at http://cloud.oracle.com And attentional training on Oracle Linux on
Oracle Cloud Infrastructure at https://bit.ly/2pfqzUM

Leave a Reply

Your email address will not be published. Required fields are marked *