sh Vagrant为libvirt提供商添加本地更新的ubuntu版本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh Vagrant为libvirt提供商添加本地更新的ubuntu版本相关的知识,希望对你有一定的参考价值。

#!/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

以上是关于sh Vagrant为libvirt提供商添加本地更新的ubuntu版本的主要内容,如果未能解决你的问题,请参考以下文章

sh 验证本地计算机上的所有Vagrant框。好脚本!

sh 验证本地计算机上的所有Vagrant框。好脚本!

如何在 vagrant 中使用 ssh-key 和密码?

Fedora 22 上的 NFS Vagrant

添加本地现有 VDI 的 Vagrant 语法是啥?

sh vagrant sh配置文件为ubuntu 32精确