Last active
July 16, 2018 14:40
-
-
Save versionsix/0b57664b96c630c1c3a947e8ac9d0f2a to your computer and use it in GitHub Desktop.
Vagrant add local updated ubuntu version for libvirt provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Make sure libguestfs-tools package is installed (libguestfs-tools-c on EL) | |
# Make sure current user is in kvm group: sudo usermod $USER -g kvm OR sudo chmod 0666 /dev/kvm | |
# Based on https://scotch.io/tutorials/how-to-create-a-vagrant-base-box-from-an-existing-one | |
box=ubuntu1804 | |
provider=libvirt | |
if [[ $EUID > 0 ]]; then | |
echo "Please run as root/sudo" | |
exit 1 | |
else | |
mkdir -p $box"_box" | |
cd $box"_box" | |
touch Vagrantfile | |
cat << EOF > Vagrantfile | |
Vagrant.configure("2") do |config| | |
config.ssh.insert_key = false | |
config.vm.box = "generic/ubuntu1804" | |
config.vm.box_check_update = true | |
config.vm.provider "libvirt" do |libvirt| | |
libvirt.memory = "2048" | |
libvirt.cpus = 2 | |
end | |
config.vm.provision "shell", inline: <<-SHELL | |
sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade | |
DEBIAN_FRONTEND=noninteractive sudo apt install ansible -y | |
DEBIAN_FRONTEND=noninteractive sudo apt autoremove | |
sudo dd if=/dev/zero of=/EMPTY bs=1M | |
sudo rm -f /EMPTY | |
cat /dev/null > ~/.bash_history && history -c | |
SHELL | |
end | |
EOF | |
vagrant up --provider=$provider | |
vagrant halt | |
sudo chmod a+r "/var/lib/libvirt/images/"$box"_box_default.img" | |
vagrant package --output $box".box" | |
vagrant box add $box $box".box" --force | |
vagrant destroy --force | |
ls -lh $box".box" | |
cd .. | |
rm -rf $box"_box" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment