Xenial Base Vagrant Box Setup
V2Master | V2Deployment | V2VagrantBoxSetup
Contents
Introduction
We create a Vagrant box for Ubuntu 16.04 LTS, based on the official Ubuntu cloud image. Currently our base box is the same as the cloud image, but
- Disk size is increased to 40GB from 10GB.
GuestAdditions updated to version 5.1.18
- Basic users and passwords set
- Minimal puppet client installed
Get base box and add as vagrant box to the system
vagrant@zg-2: vagrant box add https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-vagrant.box --name=xenial-server-cloudimg-amd64-vagrant
Create a new virtual machine based on the base box and start it
vagrant@zg-2:~/vms$ mkdir xenial-base vagrant@zg-2:~/vms$ cd xenial-base vagrant@zg-2:~/vms/xenial-base$ vi Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "xenial-server-cloudimg-amd64-vagrant" config.vm.hostname = "xenial-base.softxs.ch" config.vm.provider :virtualbox do |v| v.customize ["modifyvm", :id, "--name", "xenial-base"] v.customize ["modifyvm", :id, "--memory", "8192"] end config.vm.network :private_network, ip: "172.16.1.100", netmask: "255.240.0.0" end vagrant@zg-2:~/vms/xenial-base$ vagrant up
Updating VirtualBox Guest Additions
vagrant@zg-2:~/vms/xenial-base$ vagrant ssh ubuntu@xenial-base:~$ sudo su - root@xenial-base:~# cd /tmp root@xenial-base:~# wget http://download.virtualbox.org/virtualbox/5.1.18/VBoxGuestAdditions_5.1.18.iso root@xenial-base:~# mount -o loop /tmp/VBoxGuestAdditions_5.1.18.iso /mnt root@xenial-base:~# apt-get remove virtualbox-guest-utils root@xenial-base:~# apt-get install make gcc perl linux-headers-$(uname -r) root@xenial-base:~# /mnt/VBoxLinuxAdditions.run root@xenial-base:~# umount /mnt root@xenial-base:~# rm /tmp/VBoxGuestAdditions_5.1.18.iso
Set Users and Passords
- Set root password and vagrant user
root@xenial-base:~# passwd root@xenial-base:~# adduser vagrant # add vagrant to all groups, where ubuntu is a member (with the exeption of the ubuntu group) root@xenial-base:~# vi /etc/group :%s/ubuntu$/ubuntu,vagrant/ :x # add vagrant as sudoer without password root@xenial-base:~# cat >> /etc/sudoers.d/90-cloud-init-users vagrant ALL=(ALL) NOPASSWD:ALL CTRL-D # Set auth key for vagrant user (copied from user ubuntu) root@xenial-base:~# mkdir ~vagrant/.ssh root@xenial-base:~# cp ~ubuntu/.ssh/authorized_keys ~vagrant/.ssh root@xenial-base:~# chown -R vagrant:vagrant ~vagrant/.ssh root@xenial-base:~# chmod 755 ~vagrant/.ssh root@xenial-base:~# chmod 600 ~vagrant/.ssh/authorized_keys root@xenial-base:~# exit ubuntu@xenial-base:~$ exit
Resize HDD
vagrant@zg-2:~/vms/xenial-base$ vagrant halt vagrant@zg-2:~/VirtualBox VMs/xenial-base$ cd ~/VirtualBox\ VMs/xenial-base vagrant@zg-2:~/VirtualBox VMs/xenial-base$ VBoxManage clonehd ubuntu-xenial-16.04-cloudimg.vmdk clone-disk1.vdi --format vdi vagrant@zg-2:~/VirtualBox VMs/xenial-base$ VBoxManage showhdinfo clone-disk1.vdi vagrant@zg-2:~/VirtualBox VMs/xenial-base$ VBoxManage modifyhd clone-disk1.vdi --resize 40960 vagrant@zg-2:~/VirtualBox VMs/xenial-base$ vboxmanage list hdds vagrant@zg-2:~/VirtualBox VMs/xenial-base$ VBoxManage storageattach xenial-base --storagectl SCSI --medium none --type hdd --port 0 vagrant@zg-2:~/VirtualBox VMs/xenial-base$ vboxmanage closemedium disk ce7c94a3-7b50-4ab8-b7b1-74eb852dd094 --delete vagrant@zg-2:~/VirtualBox VMs/xenial-base$ VBoxManage storageattach xenial-base --storagectl SCSI --medium clone-disk1.vdi --type hdd --port 0
Minimal puppet client setup
vagrant@xenial-rails:~$ sudo su - root@xenial-rails:~# apt install puppet-common root@xenial-rails:~# cd /etc/puppet root@xenial-rails:~# rm -rf [efmt]* root@xenial-rails:~# vi puppet.conf [agent] server = puppet report = true
Repackaging the VM into a new Vagrant box
vagrant@zg-2:~/vms/xenial-base$ vagrant package --output ~/boxes/xenial-base.box vagrant@zg-2:~/vms/xenial-base$ vagrant box add xenial-base ~/boxes/xenial-base.box