![]()
Repositories
General
- vagrant: a tool for building and distributing development environments.
- awesome-vagrant: A curated list of awesome Vagrant resources, plugins, tutorials and other nice things
Plugins
- GitHub - Available Vagrant Plugins
- vagrant-libvirt: aΒ VagrantΒ plugin that adds aΒ LibvirtΒ provider to Vagrant, allowing Vagrant to control and provision machines via Libvirt toolkit.
- vagrant-vmware-desktop: Β the common codebase for the official providers for VMware desktop products: Fusion, Player, and Workstation. This therefore works on Windows, Mac, and Linux
Box Templates
- bento: Packer templates for building minimal Vagrant baseboxes for multiple platforms π (Recommended)
- vagrant-cloud-images: Vagrant Cloud Images by Ansible π (Recommended)
OS Resources
- Ubuntu - Ubuntu Cloud Images: Ubuntu Cloud Images are the official Ubuntu images that have been customised by Canonical π (Recommended)
- OpenStack - Obtain Image: The simplest way to obtain a virtual machine image that works with OpenStack is to download one that someone else has already created. π (Recommended)
- Debian - Debian Official Cloud Images: Find the cloud images provided by the Debian Cloud Team
- Ubuntu - Run an OVA using VirtualBox
Documentation & Resources
General
- Vagrant - General Documentation
- Vagrant - Vagrantfile
- Vagrant - Networking
- Vagrant - Creating a Base Box
External
- Vagrant Cloud: The repository for downloading the image needed for turn on the machine
Tips & Configuration
Standard Vagrantfile
Vagrant.configure("2") do |config|
# # Handle multiple machine in one block of Vagrantfile
# # https://developer.hashicorp.com/vagrant/docs/multi-machine
config.vm.define "harchidb-primary", primary: true do |config|
config.vm.box = "ubuntu/focal64"
config.vm.hostname = "harchidb-primary"
config.vm.communicator = "ssh"
# Default enable 2222 for ssh communication (Add id: "ssh" to disable default)
# https://realguess.net/2015/10/06/overriding-the-default-forwarded-ssh-port-in-vagrant/
config.vm.network "forwarded_port", guest: 22, host: 6996, protocol: "tcp", id: "ssh", host_ip: "127.0.0.1"
# Add the bridge network for let two machine can communicate each others
# With Linux, Private Network will set by default in range: 192.168.56.0/21 (192.168.56.1 - 192.168.63.255)
# Read more the documentation at: https://www.virtualbox.org/manual/ch06.html#network_hostonly
config.vm.network "private_network", ip: "192.168.56.10"
config.vm.box_check_update = false
config.ssh.username = ENV["SSH_USER"]
config.ssh.private_key_path = ENV["SSH_PRIV_KEY_PATH"]
config.ssh.port = 6996
config.ssh.guest_port = 22
# # Disable to generate a key pair inside .vargrant directory, use insecure_private_keys
# # instead of using private_key
# config.ssh.insert_key = false
config.ssh.forward_agent = true
config.vm.provider "virtualbox" do |config|
config.name = "harchidb-primary"
config.memory = 2048
config.cpus = 2
end
# Add one more disk 10GB for master node, if prerequisites
config.vm.disk :disk, size: "10GB", name: "extra_storage"
end
# Initialize the shell command to configuration
$configScript = <<-'SHELL'
sudo -i
sudo apt update && sudo apt install curl git -y
sudo apt install docker.io docker-compose -y
sudo usermod -aG docker vagrant
SHELL
# Reload profile of current user on machine
$reloadProfile = <<-'SHELL'
sudo -i
shutdown -r now
SHELL
# Execution the shell script provide
config.vm.provision "shell", inline: $configScript
# Configuration auto trigger reload profile in machine after shell
config.trigger.after :up, :provision do |trigger|
trigger.info = "Running a after trigger!"
trigger.run_remote = { inline: $reloadProfile }
trigger.ignore = [:destroy, :halt]
end
endVagrant canβt authentication ssh
If you have problems when vagrant canβt authentication for ssh. You will need concern to add this setting. Read more at: Vagrant ssh authentication failure
config.ssh.forward_agent = trueConvert OVA to Vagrant Host
Announcement
HashiCorp is deprecating and shutting down HCP Vagrant (formerly Vagrant Cloud), with servers shutting down permanently on December 31, 2026. Read detail at Vagrant - Deprecation of HCP Vagrant
Therefore before the due day, you need to figure out the way to back up the image, or at least you can build vagrant box from base image, especially Ubuntu.
BTW, I think you can easier reach out to archived *.box for both Ubuntu 22.04 (jammy) and Ubuntu 20.04 (focal), or lower from Ubuntu - Ubuntu Cloud Images, with command vagrant
# jammy
vagrant box add --name ubuntu/jammy64-cloud-image https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64-vagrant.box
# focal (EOL)
vagrant box add --name ubuntu/focal64-cloud-image https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64-vagrant.boxBut anyway, you can try to create for your own vagrant box from several ways, but to ensure vagrant can work stable, you need following this instruction Vagrant - Creating a Base Box. Here is couple of ways, I think that can work for build your image
- Use packer to build the vagrant box, with plugin virtualbox, β¦
- Use bento which recommended by Vagrant to build minimal Vagrant base boxes, it also use
packerinside. Another solution can explore at Packer - Download Packer Community Projects - Use vagrant-cloud-images with Ansible to build several OS source, e.g Ubuntu, Debian, β¦
- Use exactly provider to convert image to vagrant box which supported by vagrant, e.g: Β VirtualBox, Hyper-V, Docker, or VMware
In my perspective, I will try go from the root, it means from image, follow and applied configuation of base image with vagrant requirement, and use vagrant package following the provider, e.g: VirtualBox to build box file format. Here resource you can consult
- Ubuntu - Run an OVA using VirtualBox
- ova-to-box.md
- Ubuntu - Create and use a local cloud-init datasource
- cloud-init documentation
- Dev.to - Linuxβs Cloud InitβββBenefits, Quirks, and Drawbacks
- cloud-init-collection
- A guide to some issues working with cloud-init
- Youtube - Creating a Vagrant Box with VMware Provider: Step-by-Step Guide
- Blog - How to build a Vagrant base box from a VirtualBox VM
- Blog - Converting an existing VM to Vagrant
- OneUptime - How to Use Cloud Images with KVM on Ubuntu
I will choose OVA to Box for my strategy to base box image, first you need to grasp any ova and download it, for example
wget https://cloud-images.ubuntu.com/resolute/current/resolute-server-cloudimg-amd64.ovaYou need install and setup virtualbox to setup the VM and put the cloud-init configuration for Vagrant. Explore and troubleshot VirtualBox at VirtualBox Error in Ubuntu
If you already run virtualbox, it will provide you bunch of package, and we will use vboxmanage to import ova and run vm to testing
# import ova to virtualbox to create vm
vboxmanage import /path/to/ova/file
# check vm already create
vboxmanage list vms
#"name-of-vm" {vm-uuid}Info
The VM version you download is cloud-image, pre-installed operating system disk images built by Canonical for public clouds, private clouds, and local virtual machines. Unlike standard installer ISOs, they boot directly into a configured system and use
cloud-initto apply instance-specific settings on first boot.
Right now your VM is totally empty, and it doesnβt configure any user (it has ubuntu user but no canβt login), so therefore we need to use cloud-init to start boot, which kinda work for any distro linux.
# to use cloud-init, you can install them from package
# ref: https://github.com/canonical/cloud-utils
sudo apt install cloud-image-utils -yBack to the requirement of image vagrant, including
Now we create cloud-init file configuration and try to burn them into iso and evalute inside vm before we starting, package them with vagrant
Attention
Remember the first line of
cloud-initshould be start with#cloud-config, that will signature to define in iso, if you define another sentences, that can break thecloud-initand hard to control or validate your build successful, or failure.
cloud-initwill run onlybootimefirst, so carefully if you want to donβt make any mistake. If you login into the machine, you can rerun againcloud-initfor next boot, or you can make it several command when boot bybootcmd. If hit anything fail, or just want to test again, I recommend you erase your vm and try import and start again.
#cloud-config
users:
- name: vagrant
plain_text_passwd: vagrant
ssh_authorized_keys:
- "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key"
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN1YdxBpNlzxDqfJyw/QKow1F+wvG9hXGoqiysfJOn5Y vagrant insecure public key"
sudo: "ALL=(ALL) NOPASSWD: ALL"
lock_passwd: false
shell: /bin/bashNow use cloud-localds to create iso seed with these cloud-init above
cloud-localds vagrant.iso cloud-init.yamlWe will add this iso file to IDE Controller, explore more at VirtualBox - VirtualStorage
# Check the detail vm
# ref: https://stackoverflow.com/questions/44801397/vboxmanage-list-vm-details-storage
vboxmanage list vms -l
# Add the IDE controller to vm (if not exist, usually ide controller exist)
# ref: https://superuser.com/questions/741734/virtualbox-how-can-i-add-mount-a-iso-image-file-from-command-line
vboxmanage storagectl "<uuid|vmname>" --name IDE --add ide
# Attach the iso to ide
vboxmanage storageattach "<uuid|vmname>" --storagectl IDE --port 0 --device 0 --type dvddrive --medium /path/to/iso
# detech the iso to ide (if needed)
vboxmanage storageattach "<uuid|vmname>" --storagectl IDE --port 0 --device 0 --medium "none"Now run the VM to check one more time again before you package
# change nic1 of vm to NAT
vboxmanage modifyvm "<uuid|vmname>" --nic1 nat
# add port-forward (opt to ssh) or use GUI
# with NAT, guest usually attach to `10.0.2.15`, ref: https://www.virtualbox.org/manual/topics/networkingdetails.html
vboxmanage modifyvm "<uuid|vmname>" --natpf1 "guestssh,tcp,<HOST>,<HOST-PORT>,<GUEST>,<GUEST-PORT>"
vboxmanage modifyvm "<uuid|vmname>" --natpf1 "guestssh,tcp,127.0.0.1,9669,10.0.2.15,22"
# to delete nat port-forward
VBoxManage modifyvm "<uuid|vmname>" --natpf1 delete "guestssh"
# start the vm
vboxmanage startvm "<uuid|vmname>" --type headless
# login via ssh or GUI with `user:pass`Use vagrant to package the image after you check up anything following vagrant requirement
vagrant package --base "<uuid|vmname>" --output path/output/filename.boxAdd box with vagrant to start used
vagrant box add --name name-box-adding [--box-version <string>] /path/to/filename.box
# check again
vagrant box listTo remove vm if you donβt need to use or make mistake and want to remove it
# ref: https://askubuntu.com/questions/1483819/how-do-i-remove-a-virtualbox-machine-from-virtualbox-manager-so-i-can-reinstall
# ref: https://stackoverflow.com/questions/13769808/how-do-i-delete-a-virtualbox-machine-in-the-guru-meditation-error-state
vboxmanage unregistervm "<uuid|vmname>" --delete
# or remove natively with rm
rm -rf ~/VirtualBox\ VMs/<name-of-machine>