Skip to main content

3 posts tagged with "packer"

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

AWS Free Tier and a Packer Tutorial

· 2 min read

Background​

When I was learning AWS from a YouTube playlist, I built a VPC across two Availability Zones with several subnets. The private subnets used NAT gateways. The course never mentioned that NAT gateways were outside the Free Tier. The two gateways cost me about $6 in a couple of days. That stung, so I set up a billing alarm.

#!NOTE

Here's the ADV-IT course.

What happened​

I had recently been learning to build artifacts with Packer. After experimenting on AWS, I deleted all the AMIs in the relevant region through the console and moved on.

A week later I saw another email from AWS. My personal Gmail sometimes gets billing reports from them, usually empty, and invitations to re:Invent.

alert

I'd used 85% of my Free Tier allowance for EBS snapshots.

info

The AWS Free Tier page lists the monthly allowances for each resource.

It turns out Packer had created these snapshots alongside the AMIs.

snapshots

Lessons learned
  • Start by setting up a non-root identity. Then set up billing alerts. I'd pick a 50% threshold because I burned through my allowance fast.
  • If you're writing a tutorial, call out which resources fall outside the Free Tier and which have tight limits.

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