Title: Install vagrant, then use vagrant-libvirt plug-in on ubuntu14.04/trusty
ref. https://github.com/pradels/vagrant-libvirt
ref. https://bugs.launchpad.net/ubuntu/+source/vagrant/+bug/1553666
Objectives:
- Install vagrant on ubuntu14.04/trusty
- Install vagrant-libvirt plug-in
- Deploy VM with vagrant
Pre-requisite:
- ubuntu14.04.3 server
~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.3 LTS"
- libvirt-dev 1.2.2
~$ dpkg -p libvirt-dev
Package: libvirt-dev
Priority: optional
Section: libdevel
Installed-Size: 2676
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Source: libvirt
Version: 1.2.2-0ubuntu13.1.17
- libvirt 1.2.2
~$ dpkg -p libvirt-bin
Package: libvirt-bin
Priority: optional
Section: admin
Installed-Size: 11569
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Source: libvirt
Version: 1.2.2-0ubuntu13.1.14
- qemu-kvm 2.0.0
~$ dpkg -p qemu-kvm
Package: qemu-kvm
Priority: optional
Section: otherosfs
Installed-Size: 99
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Multi-Arch: foreign
Source: qemu
Version: 2.0.0+dfsg-2ubuntu1.21
- ruby, gem
~$ ruby --version
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
~$ gem --version
1.8.23
1. Install vagrant
~$ wget https://releases.hashicorp.com/vagrant/1.8.1/vagrant_1.8.1_x86_64.deb
~$ sudo dpkg --install vagrant_1.8.1_x86_64.deb
check
~$ vagrant --version
Vagrant 1.8.1
2. Install plug-ins
~$ vagrant plugin install vagrant-libvirt
output
~$ vagrant plugin install vagrant-libvirt
Installing the 'vagrant-libvirt' plugin. This can take a few minutes...
Installed the plugin 'vagrant-libvirt (0.0.32)'!
~$ vagrant plugin install --plugin-version 0.0.3 fog-libvirt
output
Installing the 'fog-libvirt --version '0.0.3'' plugin. This can take a few minutes...
Installed the plugin 'fog-libvirt (0.0.3)'!
3. Add Box, init Box
~$ vagrant box add centos/7
~$ mkdir -p vagrant/centos7/
~$ cd ./vagrant/centos7/
~/vagrant/centos7$ vagrant init centos/7
output
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
4. Edit Vagrantfile
~/vagrant/centos7$ vi Vagrantfile
~/vagrant/centos7$ cat Vagrantfile | grep -v \# | grep -v ^$
Vagrant.configure(2) do |config|
config.vm.define :test_vm do |test_vm|
test_vm.vm.box = "centos/7"
end
end
5. Start VM
~/vagrant/centos7$ vagrant up --provider=libvirt
- may take several minutes while first adding the box.
~/vagrant/centos7$ virsh list | grep test_vm
example
13 centos7_test_vm running
6. Connect VM
~/vagrant/centos7$ vagrant ssh
[vagrant@localhost ~]$ cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[vagrant@localhost ~]$ ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:b3:f7:35 brd ff:ff:ff:ff:ff:ff
inet 192.168.121.82/24 brd 192.168.121.255 scope global dynamic eth0
valid_lft 2442sec preferred_lft 2442sec
inet6 fe80::5054:ff:feb3:f735/64 scope link
valid_lft forever preferred_lft forever