Intro

It is possible to host your own Vagrant "cloud" on premises. You might want to do this to align with your companies security policy and or to host your custom Vagrant boxes.

There are a number of methods to serve your Vagrant boxes, in this post I will show you how to build a web server to host Vagrant boxes rather than consume them from the real Vagrant cloud.

I will borrow a pre-built Cumulus-VX box from the real Vagrant cloud and serve it from my web server host so my internal lab users can consume it.

The following software will be used as part of this post.

  • CentOS - 7
  • Apache - 2.4.6-88
  • Vagrant - 2.2.4
  • Cumulus-VX - 3.7.6

Installation

I am using the Apache web server for this lab, in RHEL land, The Apache package is called httpd.

cmd
sudo yum install httpd

Start and enable Apache.

cmd
sudo systemctl start httpd
sudo systemctl enable httpd

Configuration

Create a virtual host file named vhost.conf in the /etc/httpd/conf.d/ directory.

file
NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin bradmin@lab.local
    ServerName util01.lab.local
    ServerAlias www.util01.lab.local
    DocumentRoot /var/www/html
    <Directory "/var/www/html">
        Options All Indexes FollowSymLinks
        Order allow,deny
        Allow from all
  </Directory>
  ErrorLog /var/log/httpd/repo/error.log
  CustomLog /var/log/httpd/repo/access.log combined
</VirtualHost>

Create the necessary directories.

cmd
sudo mkdir -p /var/www/html/repo/vagrant/cumulus/vx
sudo mkdir /var/log/httpd/repo

Add the Cumulus-VX Vagrant box.

cmd
sudo wget -O /var/www/html/repo/vagrant/cumulus/vx/cumulus-vx-3.7.6.box https://vagrantcloud.com/CumulusCommunity/boxes/cumulus-vx/versions/3.7.6/providers/libvirt.box

Create a metadata file named cumulus-vx.json in the /var/www/html/repo/vagrant/ directory.

The metadata file defines the parameters about a box such as the version number and box location.

file
{
  "name": "cumulus/vx",
  "description": "Cumulus VX",
  "versions": [
    {
      "version": "3.7.6",
      "providers": [
        {
          "name": "libvirt",
          "url": "http://util01.lab.local/repo/vagrant/cumulus/vx/cumulus-vx-3.7.6.box"
        }
      ]
    }
  ]
}

Change directory ownership to the apache user.

cmd
sudo chown -R apache:apache /var/www

Restart the Apache service.

cmd
sudo systemctl restart httpd.service

Reconfigure directories to permit SELinux access to the file system from the web server.

cmd
sudo restorecon -r /var/www/html/repo/*

Permit HTTP traffic through the firewall

cmd
sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload

Testing

On your laptop or shared host that you are running vagrant create and change into a directory for the test environment.

file
mkdir -p ~/vagrant/cumulus-test/ && cd ~/vagrant/cumulus-test/

Create a Vagrantfile with the following contents.

file
Vagrant.configure("2") do |config|
  config.vm.box = "cumulus/vx"
  config.vm.box_url = "http://util01.lab.local/repo/vagrant/cumulus-vx.json"
  config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
end
Note
I am disabling synced folders as the base repos on the Cumulus image dont have access to the nfs packages that Vagrant tries to install.

Now vagrant up and confirm the Vagrant box is downloaded and installed from the local web server.

cmd
vagrant up

# output

Bringing machine 'default' up with 'libvirt' provider...
==> default: Box 'cumulus/vx' could not be found. Attempting to find and install...
default: Box Provider: libvirt
default: Box Version: >= 0
==> default: Loading metadata for box 'http://util01.lab.local/repo/vagrant/cumulus-vx.json'
default: URL: http://util01.lab.local/repo/vagrant/cumulus-vx.json
==> default: Adding box 'cumulus/vx' (v3.7.6) for provider: libvirt
default: Downloading: http://util01.lab.local/repo/vagrant/cumulus/vx/cumulus-vx-3.7.6.box
==> default: Successfully added box 'cumulus/vx' (v3.7.6) for 'libvirt'!

==> default: Uploading base box image as volume into libvirt storage...
==> default: Creating image (snapshot of base box volume).
==> default: Creating domain with the following settings...
==> default:  -- Name:              cumulus-test_default
==> default:  -- Domain type:       kvm
==> default:  -- Cpus:              1
==> default:  -- Feature:           acpi
==> default:  -- Feature:           apic
==> default:  -- Feature:           pae
==> default:  -- Memory:            512M
==> default:  -- Management MAC:
==> default:  -- Loader:
==> default:  -- Nvram:
==> default:  -- Base box:          cumulus/vx
==> default:  -- Storage pool:      default
==> default:  -- Image:             /var/lib/libvirt/images/cumulus-test_default.img (6G)
==> default:  -- Volume Cache:      default
==> default:  -- Kernel:
==> default:  -- Initrd:
==> default:  -- Graphics Type:     vnc
==> default:  -- Graphics Port:     -1
==> default:  -- Graphics IP:       127.0.0.1
==> default:  -- Graphics Password: Not defined
==> default:  -- Video Type:        cirrus
==> default:  -- Video VRAM:        9216
==> default:  -- Sound Type:
==> default:  -- Keymap:            en-us
==> default:  -- TPM Path:
==> default:  -- INPUT:             type=mouse, bus=ps2
==> default: Creating shared folders metadata...
==> default: Starting domain.
==> default: Waiting for domain to get an IP address...
==> default: Waiting for SSH to become available...
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Configuring and enabling network interfaces...

As you can see from the output above the Cumulus-VX box was downloaded and installed from the local web server.

Finally, confirm the box is installed locally on your laptop or shared host.

cmd
vagrant box list

# output

cumulus/vx (libvirt, 3.7.6)

Outro

Hosting your own Vagrant box store is a nice way to serve up custom Vagrant boxes as well as boxes from the real Vagrant cloud that your users may not be able to access due to corporate policies.