The first hurdle when using the book was that the examples provided in the book rely on using Vagrant with Virtual box to create test machines which themselves were running Ubuntu. I use a Fedora 29 machine and would like to use CentOS on KVM instead for my setup.
To get the test machines setup for my environment, I've had to deviate from the instructions given in the book. This post is based on my notes. These notes should also benefit those who are just looking to use Vagrant with KVM.
First install Vagrant and the libvirt plugin for vagrant.
sudo dnf install -y vagrant vagrant-libvirtI use the directory ~/vagrant/ceph as the location for the Vagrantfile for my test machines.
My Vagrant file is as follows
Going through this step-by-step
I use a variable storage_pool_name to store the name of the storage pool name in libvirt. This pool is created as a 'Filesystem Directory' on my laptop which has been named "vagrant-pool".
This is an array or dictionaries containing details of the machines to be setup.
The main configuration block used by Vagrant.
I then initialise common settings for all the test machines. I've commented inline.
We then iterate through the list of nodes in the nodes array setting up a test box for each node with the described features in the block.
To create the test machines, we simply call
$ vagrant up
We can also call up individual machines by providing a list of names.
$ vagrant up mon1 osd1
On first run, vagrant will download an image of CentOS 7. Subsequent runs will be faster.
We can suspend and resume using the commands
$ vagrant suspend
$ vagrant resume
This ensures that the virtual machines are available later when you get back to it.
When we are done and no longer need the machines, we can use the following command to stop and delete them.
$ vagrant destroy
As with "vagrant up", we can provide machine names.
To complete the setup, I add the following to my /etc/hosts file.
Since I will be recreating these test machines several times, I do not want to keep modifying the ~/.ssh/known_hosts because of the default StrictHostKeyChecking I have on my main setup.
I add the following lines to ~/.ssh/config.
You can now test by sshing into the test machines
$ ssh root@mon1