Vagrant for Libvirt on Centos7

Install vagrant with libvirt

yum install https://releases.hashicorp.com/vagrant/1.8.5/vagrant_1.8.5_x86_64.rpm

(I had an issue with 1.8.5 incorrectly setting the permissions on the authorized_hosts file so i backed off to 1.8.4)

Install the prereqs for the vagrant plugin installer(Not 100% sure all this is required)

yum install libxslt-devel libxml2-devel libvirt-devel libguestfs-tools-c ruby-devel gcc automake makeconf

Install the plugin

vagrant plugin install vagrant-libvirt

 

More info see here https://github.com/vagrant-libvirt/vagrant-libvirt#networks

DNS

To have DNS update automagically install the landrush plugin – https://github.com/vagrant-landrush/landrush

yum install gcc-c++

vagrant plugin install landrush

My virtual host required a change to the firewall to allow DNS to work

[root@hp ~]# firewall-cmd --zone=internal --add-port=10053/tcp --permanent
success
[root@hp ~]# firewall-cmd --zone=internal --add-port=10053/udp --permanent
success
[root@hp ~]# firewall-cmd --zone=internal --add-port=10053/udp
success
[root@hp ~]# firewall-cmd --zone=internal --add-port=10053/tcp

Example Vagrantfile

Note the setting to enable landmark and to keep the insecure key to make management easier

Vagrant.configure("2") do |config|

        config.ssh.insert_key = false
        config.landrush.enabled = true

        config.vm.define :cephosd1 do |cephosd1|
                cephosd1.vm.box = "centos/7"
                cephosd1.vm.provider :libvirt do |domain|
                        domain.memory=2048
                end
                cephosd1.vm.hostname="cephosd1"
                cephosd1.vm.network :private_network, :ip => "172.18.0.201"
                cephosd1.vm.provider :libvirt do |libvirt|
                        libvirt.storage :file, :size => '20G'
                        libvirt.storage :file, :size => '20G'
                        libvirt.storage :file, :size => '20G'
                        libvirt.storage :file, :size => '20G'
                        libvirt.storage :file, :size => '20G'
                end
        end

end

 

 

To SSH into a VM

Disabling host verification and using the insecure keyfile

ssh -i /root/.vagrant.d/insecure_private_key vagrant@cephosd1 -o StrictHostKeyChecking=no

Alternatively of course

vagrant ssh cephosd1

 

Using Ansible

http://blog.scottlowe.org/2015/06/08/using-vagrant-to-learn-ansible/

[defaults]
inventory = ./hosts
private_key_file = /Users/slowe/.vagrant.d/insecure_private_key
remote_user = vagrant
host_key_checking = False

Centos 7 UEFI things

How to tell if you booted from a UEFI enabled machine

dmesg | grep "EFI v"

 

When enabling net.ifnames=o

Edit /etc/default/grub

Ammend line GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/swap vconsole.font=latarcyrheb-sun16 rd.lvm.lv=centos/root crashkernel=auto  vconsole.keymap=us rhgb quiet net.ifnames=0"

Then run

grub2-mkconfig  -o /boot/efi/EFI/centos/grub.cfg

or

grub2-mkconfig -o /boot/grub2/grub.cfg