Skip to main content

2 posts tagged with "vagrant"

View All Tags

Vagrant - DevOps Environment

· 3 min read

Inspiration​

I recently wrote about building a Vagrant box, and I've finally finished it 🎉. It comes in two versions:

  • A server version you access over SSH.
  • A GUI version with desktop apps preinstalled 💻.

asciicast

Here's the same process as a diagram:

Installing on Windows​

Check the resources available on your host OS:

CPU

WMIC CPU Get DeviceID,NumberOfCores,NumberOfLogicalProcessors

Look for the OS version and total RAM:

systeminfo |findstr /c:"OS Name" /c:"Total Physical Memory"

img

"Recommended resources"
  • 2 vpcu
  • 4Gi RAM

You'll need:

VirtualBox Guest Additions​

6.4. Installing the VirtualBox Guest Additions

vbguest vagrant plugin​

danger

This only worked once for me 💀.

vagrant plugin uninstall vagrant-vbguest
vagrant destroy -f
vagrant up
vagrant plugin install vagrant-vbguest
vagrant vbguest --do install

ansible galaxy​

Use my example. The Ansible role installs Guest Additions.

caution

I can't promise it will work on every machine, but it should take very little tweaking.

The secret option​

You can always search the web or YouTube for how to make VirtualBox go full screen 😉.

Good luck, and may the Force be with you!

tip

If you haven't seen this yet, now's your chance:

Toggle me!

🦖 🦕

Links

Links and articles that helped me build this:

Links

Selfmade Vagrant box

· 2 min read

I couldn't find a good box with a GUI on Vagrant Cloud.

Build process​

info

I'll use Docker as an analogy throughout.

config file​

We describe the Vagrant box (think Docker image) in an HCL configuration, much like Terraform.

source "vagrant" "ubuntu" {
add_force = true
communicator = "ssh"
provider = "virtualbox"
source_path = "ubuntu/focal64"
}

build {
name = "learn-packer"
sources = [
"source.vagrant.ubuntu"
]
}
tip

Useful commands:

packer validate packer.hcl # Validate the file
packer fmt . # Format the files and, I believe, validate them too

build​

Build the image with Packer, which plays a role similar to the Docker engine here.

packer build packer.hcl

After a while, a .box file will appear in the learn-packer directory. Think of it as the Docker image.

push​

Upload the file to Vagrant Cloud. You'll need its checksum, which you can calculate with md5, for example.

provisioner​

note

Ansible is my preferred provisioner, though shell works too.

source "vagrant" "ubuntu" {
add_force = true
communicator = "ssh"
provider = "virtualbox"
source_path = "ubuntu/focal64"
}

build {
name = "learn-packer"
sources = [
"source.vagrant.ubuntu"
]
provisioner "ansible" {
playbook_file = "./ansible/packer-playbook.yml"
}
}

post-processors​

caution

I haven't tested this.

These steps run after the build, for example publishing to Vagrant Cloud, much like docker push.

GitHub repo