How to Create Private Vagrant Cloud on Ubuntu 20.04

Zeki Ahmet Bayar - Dec 22 '21 - - Dev Community

You may want to keep your Vagrant boxes in your own repository instead of the global cloud structure.

This can often be quite important for internal policies. Moreover, it makes sense to keep the vagrant boxes you think are in a place where only you can access them.

For this and similar reasons, I tried to create my secret vagrant repository and I saw that they explained the way to do it on the internet only for RHEL.

And you know... Some people (like me) are just not used to RHEL.

For these reasons, I wanted to explain how we can do this on Ubuntu.

1. Apache Installation

As can be expected, we first start with installing the Apache.



sudo apt update
sudo apt install apache2


Enter fullscreen mode Exit fullscreen mode

1.1. Creation of Necessary Directories

Before configuring Apache, we can create the necessary log directories.



sudo mkdir /var/log/apache2/vcloud


Enter fullscreen mode Exit fullscreen mode

1.2. Apache Configuration

To configure Apache simply, create a configuration file named vcloud.conf under /etc/apache2/sites-available/. Then add the following configurations into this file.



NameVirtualHost *:80

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


Enter fullscreen mode Exit fullscreen mode

ServerName is very important in this configuration. In the future we will need to create a host record to access it.

1.3. Activate Configuration

To activate the configuration follow the steps.



cd /etc/apache2/sites-available
sudo a2ensite vcloud.conf


Enter fullscreen mode Exit fullscreen mode

1.4. Create Local Host Record

Create a record to reach the ServerName you gave in the configuration.

To do this, add a line /etc/hosts file like this.



10.20.30.78    vcloud.acik.lab


Enter fullscreen mode Exit fullscreen mode

If you try to access the repository from Windows, the address of this file should be something like C:\Windows\System32\Drivers\etc\hosts

1.5. Create Directories for Vagrant Box

Create directories where we will put the Vagrant box. I choose the Pardus 21.0 distribution that I created myself.



sudo mkdir -p /var/www/html/vcloud/vagrant/pardus/21


Enter fullscreen mode Exit fullscreen mode

2. Get Vagrant Box

That moment has come! Let's download the vagrant box. (If you feel lost, you should experience Pardus 21 with me.)



sudo wget -O /var/www/html/vcloud/vagrant/pardus/21/pardus-21-0.1.0.box https://app.vagrantup.com/zeki/boxes/pardus21/versions/0.1.0/providers/virtualbox.box


Enter fullscreen mode Exit fullscreen mode

2.1. Create Metadata File

After the download is complete, create a metadata file named pardus-21.json under /var/www/html/vcloud/vagrant/. Don't mind the word metadata being so cool, it's just a json file and fill its content as below.



{
  "name": "pardus/21",
  "description": "Pardus 21.0 XFCE",
  "versions": [
    {
      "version": "0.1.0",
      "providers": [
        {
          "name": "virtualbox",
          "url": "http://vcloud.acik.lab/vcloud/vagrant/pardus/21/pardus-21-0.1.0.box"
        }
      ]
    }
  ]
}


Enter fullscreen mode Exit fullscreen mode

3. Restart Apache Services

After completing all these steps, we can activate Apache service.



sudo systemctl start apache2
sudo systemctl enable apache2


Enter fullscreen mode Exit fullscreen mode

3.1. Accessibility Test

If all goes well you should see vagrant boxes at http://vcloud.acik.lab/vcloud/vagrant/.

Accessibility test

4. Testing

Create new Vagrant directory and Vagrantfile to test. (On the another server.)



mkdir pardus-21 && cd pardus-21
touch Vagrantfile


Enter fullscreen mode Exit fullscreen mode

Insert the following lines into the Vagrantfile.



Vagrant.configure("2") do |config|
  config.vm.box = "pardus/21"
  config.vm.box_url = "http://vcloud.acik.lab/vcloud/vagrant/pardus-21.json"
  config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
end


Enter fullscreen mode Exit fullscreen mode

LET'S VAGRANT UP!



cd ~/pardus-21 
vagrant up


Enter fullscreen mode Exit fullscreen mode

The output should look like this.

Output of vagrant up

Congratulations!! You now have a secret vagrant repository!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .