Vagrant Overview for MariaDB Users

You are viewing an old version of this article. View the current version here.

Vagrant is a tool to create and manage development machines (Vagrant boxes). They are usually virtual machines on the localhost system, but they could also be Docker containers or remote machines. Vagrant is open source software maintained by HashiCorp and released under the MIT license.

Vagrant benefits include simplicity, and a system to create test boxes that is mostly independent from the technology used.

For information about installing Vagrant, see Installation in Vagrant documentation.

In this page we discuss basic Vagrant concepts.

Vagrant Concepts

A Vagrant machine is compiled from a box. It can be a virtual machine, a container or a remote server from a cloud service.

A box is a package that can be used to create Vagrant machines. We can download boxes from app.vagrantup.com, or we can build a new box from a Vagrantfile. A box can be used as a base for another box. The base boxes are usually operating system boxes downloaded from app.vagrantup.com.

A provider is responsible for providing the virtualization technology that will run our machine.

A provisioner is responsible for installing and configuring the necessary software on a newly created Vagrant machine.

Example

The above concepts are probably easier to understand with an example.

We can use an Ubuntu box as a base to build a Vagrant machine with MariaDB. So we write a Vagrantfile for this purpose. In the Vagrantfile we specify VirtualBox as a provider. And we use the Ansible provisioner to install and configure MariaDB. Once we finish this Vagrantfile, we can run a Vagrant command to start a Vagrant machine, which is actually a VirtualBox VM running MariaDB on Ubuntu.

The following diagram should make the example clear:

vagrant-virtalbox-ansible

Vagrantfiles

A Vagrantfile is a file that describes how to create one or more Vagrant machines. Vagrantfiles use the Ruby language, as well as objects provided by Vagrant itself.

A Vagrantfile is often based on a box, which is usually an operating system in which we are going to install our software. For example, one can create a MariaDB Vagrantfile based on the ubuntu/trusty64 box. A Vagrantfile can describe a box with a single server, like MariaDB, but it can also contain a whole environment, like LAMP. For most practical use cases, having the whole environment in a single box is more convenient.

Boxes can be searched in Vagrant Cloud. Most of their Vagrantfiles are available on GitHub. Searches can be made, among other things, by keyword to find a specific technology, and by provider.

Providers

A provider adds support for creating a specific type of machines. Vagrant comes with several providers, for example:

  • VirtualBox allows one to create virtual machines with VirtualBox.
  • Hyper-V allows one to create virtual machines with Microsoft Hyper-V.
  • Docker allows one to create Docker containers.

Alternative providers are maintained by third parties or sold by HashiCorp. They allow one to create different types of machines, for example using VMWare.

To find out how to develop your own provider, see Plugin Development: Providers in Vagrant documentation.

Some examples of useful providers, recognized by the community:

Provisioners

A provisioner is a technology used to deploy software to the newly created machines.

The simplest provisioner is shell, which runs a shell file inside the Vagrant machine. powershell is also available.

Other providers use automation software to provision the machine. There are provisioners that allow one to use Ansible, Puppet, Chef or Salt. Where relevant, there are different provisioners allowing the use of these technologies in a distributed way (for example, using Puppet apply) or in a centralized way (for example, using a Puppet server).

It is interesting to note that there is both a Docker provider and a Docker provisioner. This means that a Vagrant machine can be a Docker container, thanks to the docker provisioner. Or it could be any virtualisation technology with Docker running in it, thanks to the docker provisioner. In this case, Docker pulls images and starts containers to run the software that should be running in the Vagrant machine.

Vagrant commands

This is a list of the most common Vagrant commands. For a complete list, see Command-Line Interface in Vagrant documentation.

To list the available machines:

vagrant box list

To start a machine from a box:

cd /box/directory
vagrant up

To connect to a machine:

vagrant ssh

To see all machines status and their id:

vagrant global-status

To destroy a machine:

vagrant destroy <id>

Vagrant Resources and References

Here are some valuable websites and pages for Vagrant users.


Content initially contributed by Vettabase Ltd.

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.