Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ubuntu 22.04 box #94

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.box
iso/*
.vagrant/*
ubuntu2204/.vagrant/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

This project contains the Packer build configurations for all of Jeff Geerling's (geerlingguy's) Vagrant Boxes. Each box builds a minimal base box for use with VirtualBox. Available boxes include:

- [geerlingguy/ubuntu2204](https://app.vagrantup.com/geerlingguy/boxes/ubuntu2204) - [`ubuntu2204` directory](ubuntu2204/)
- [geerlingguy/ubuntu2004](https://app.vagrantup.com/geerlingguy/boxes/ubuntu2004) - [`ubuntu2004` directory](ubuntu2004/)
- [geerlingguy/ubuntu1804](https://app.vagrantup.com/geerlingguy/boxes/ubuntu1804) - [`ubuntu1804` directory](ubuntu1804/)
- [geerlingguy/rockylinux8](https://app.vagrantup.com/geerlingguy/boxes/rockylinux8) - [`rockylinux8` directory](rockylinux8/)
Expand Down
1 change: 1 addition & 0 deletions build-boxes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- debian9
- ubuntu1804
- ubuntu2004
- ubuntu2204
versions: {}

tasks:
Expand Down
8 changes: 8 additions & 0 deletions ubuntu2204/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Packer Build - Ubuntu 22.04 minimal Vagrant Box

**Current Ubuntu Version Used**: 22.04 live server install image

This build is based on/inspired by [rlaun/packer-ubuntu-22.04](https://github.com/rlaun/packer-ubuntu-22.04).
See that repo's readme for useful information on the new Ubuntu installer.

See the [project README.md](../README.md) for usage instructions.
25 changes: 25 additions & 0 deletions ubuntu2204/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.ssh.insert_key = false
config.vm.synced_folder '.', '/vagrant', type: 'nfs'

# VirtualBox.
config.vm.define "virtualbox" do |virtualbox|
virtualbox.vm.hostname = "virtualbox-ubuntu2204"
virtualbox.vm.box = "file://builds/virtualbox-ubuntu2204.box"
virtualbox.vm.network :private_network, ip: "172.16.3.21"

config.vm.provider :virtualbox do |v|
v.gui = false
v.memory = 1024
v.cpus = 1
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--ioapic", "on"]
end

config.vm.provision "shell", inline: "echo Hello, World"
end

end
87 changes: 87 additions & 0 deletions ubuntu2204/box-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"variables": {
"version": ""
},
"provisioners": [
{
"type": "shell",
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
"script": "scripts/ansible.sh"
},
{
"type": "shell",
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
"script": "scripts/setup.sh"
},
{
"type": "ansible-local",
"playbook_file": "../shared/main.yml",
"galaxy_file": "../shared/requirements.yml"
},
{
"type": "shell",
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
"script": "scripts/cleanup.sh"
}
],
"builders": [
{
"type": "virtualbox-iso",
"boot_command": [
"e<wait>",
"<down><down><down>",
"<end><bs><bs><bs><bs><wait>",
"autoinstall ds=nocloud-net\\;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ ---<wait>",
"<f10><wait>"
],
"boot_wait": "10s",
"disk_size": 81920,
"guest_os_type": "Ubuntu_64",
"headless": true,
"http_directory": "http",
"iso_urls": [
"ubuntu-22.04-live-server-amd64.iso",
"https://releases.ubuntu.com/22.04/ubuntu-22.04-live-server-amd64.iso"
],
"iso_checksum": "sha256:84aeaf7823c8c61baa0ae862d0a06b03409394800000b3235854a6b38eb4856f",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_wait_timeout": "1800s",
"ssh_timeout": "60m",
"ssh_handshake_attempts": 500,
"shutdown_command": "echo 'vagrant'|sudo -S shutdown -P now",
"guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso",
"virtualbox_version_file": ".vbox_version",
"vm_name": "packer-ubuntu-22.04-amd64",
"vboxmanage": [
[
"modifyvm",
"{{.Name}}",
"--memory",
"1024"
],
[
"modifyvm",
"{{.Name}}",
"--cpus",
"1"
]
]
}
],
"post-processors": [
[
{
"output": "builds/{{.Provider}}-ubuntu2204.box",
"type": "vagrant"
},
{
"type": "vagrant-cloud",
"box_tag": "geerlingguy/ubuntu2204",
"version": "{{user `version`}}"
}
]
]
}

1 change: 1 addition & 0 deletions ubuntu2204/builds/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory will contain built Vagrant box files.
Empty file added ubuntu2204/http/meta-data
Empty file.
10 changes: 10 additions & 0 deletions ubuntu2204/http/user-data
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#cloud-config
autoinstall:
version: 1
identity:
hostname: vagrant
password: "$6$B566qc2ieo8i/Bnt$fowURQIzy1Z0DogCVHKQ/HKFKbJtSiFm1E0wAGWOBMb1hvhmZ1RQ7GzOpK0.eDY6tn32bkqAPSPu6LHnXVdzr."
username: vagrant
locale: en_US
keyboard:
layout: us
10 changes: 10 additions & 0 deletions ubuntu2204/scripts/ansible.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash -eux

# Install Ansible repository.
apt -y update && apt-get -y upgrade
apt -y install software-properties-common
apt-add-repository ppa:ansible/ansible

# Install Ansible.
apt -y update
apt -y install ansible
24 changes: 24 additions & 0 deletions ubuntu2204/scripts/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash -eux

# Uninstall Ansible and remove PPA.
apt -y remove --purge ansible
apt-add-repository --remove ppa:ansible/ansible

# Apt cleanup.
apt autoremove -y
apt update

# Blank netplan machine-id (DUID) so machines get unique ID generated on boot.
truncate -s 0 /etc/machine-id
rm /var/lib/dbus/machine-id
ln -s /etc/machine-id /var/lib/dbus/machine-id

# Delete unneeded files.
rm -f /home/vagrant/*.sh

# Zero out the rest of the free space using dd, then delete the written file.
dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY

# Add `sync` so Packer doesn't quit too early, before the large file is deleted.
sync
8 changes: 8 additions & 0 deletions ubuntu2204/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -eux

# Add vagrant user to sudoers.
echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers

# Disable daily apt unattended updates.
echo 'APT::Periodic::Enable "0";' >> /etc/apt/apt.conf.d/10periodic