Vagrant Libvirt Install CentOS 7
Published: 2019-05-24
Intro
This post will cover the process of installing Vagrant with the libvirt provider on CentOS 7.
For reference the following software will be used in this post.
- CentOS - 7
- Vagrant - 2.2.4
- Vagrant-libvirt - 0.0.45
System Prep
Before we begin, lets ensure the host is updated.
sudo yum update -y && sudo yum upgrade -yOn this host I will set the SELinux policy to permissive.
sudo setenforce permissive
sudo sed -i 's/^SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/configInstallation
Install Vagrant
sudo yum install -y https://releases.hashicorp.com/vagrant/2.2.4/vagrant_2.2.4_x86_64.rpmInstall the vagrant-libvirt dependencies
sudo yum install -y qemu libvirt libvirt-devel ruby-devel gcc qemu-kvm rsyncInstall the vagrant-libvirt plugin.
vagrant plugin install vagrant-libvirtConfiguration
Start and enable the libvirtd service.
sudo systemctl start libvirtd.service
sudo systemctl enable libvirtd.serviceAdd your user to the libvirt group.
sudo usermod -aG libvirt $USERSet an environment variable for the default libvirt uri as qemu:///system. Without this virsh commands point to the users qemu:///session uri which does not have privileges to add/view system wide networks.
sudo tee --append /etc/environment > /dev/null << "EOF"
LIBVIRT_DEFAULT_URI=qemu:///system
EOFSource the /etc/environment file to load the config into your environment.
source /etc/environmentCreate a vagrant-libvirt network using an xml file named vagrant-libvirt.xml with the below contents.
<network connections='1'>
<name>vagrant-libvirt</name>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='virbr1' stp='on' delay='0'/>
<ip address='192.168.121.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.121.2' end='192.168.121.254'/>
</dhcp>
</ip>
</network>Define and start the network.
virsh net-define vagrant-libvirt.xml
virsh net-start vagrant-libvirt
virsh net-autostart vagrant-libvirtTesting
Confirm you can build a Vagrant box.
mkdir -p ~/vagrant/centos-test && cd ~/vagrant/centos-test
vagrant init centos/7 && vagrant up
# output
Bringing machine 'default' up with 'libvirt' provider...
==> default: Checking if box 'centos/7' version '1902.01' is up to date...
==> default: Creating image (snapshot of base box volume).
==> default: Creating domain with the following settings...
==> default: -- Name: centos-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: centos/7
==> default: -- Storage pool: default
==> default: -- Image: /var/lib/libvirt/images/centos-test_default.img (41G)
==> 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...
default: SSH address: 192.168.121.38:22
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Rsyncing folder: /home/bradmin/vagrant/centos-test/ => /vagrant
# SUCCESS !!!!Outro
If you followed along, Vagrant and the vagrant-libvirt plugin are now installed in your CentOS 7 host and you can successfully build Vagrant boxes.
Links
https://github.com/vagrant-libvirt/vagrant-libvirt#installation