From 184f992584e3ccb4363379f6f921ccea11ce1302 Mon Sep 17 00:00:00 2001 From: Maros Kukan Date: Wed, 27 Jul 2022 14:05:55 +0200 Subject: [PATCH 1/8] Add support for Ubuntu 22.04 --- README.md | 1 + build-boxes.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 12ad0bc..63b859f 100644 --- a/README.md +++ b/README.md @@ -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/ubuntu2004) - [`ubuntu22code 04` directory](ubuntu2004/) - [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/) diff --git a/build-boxes.yml b/build-boxes.yml index e451293..618776f 100644 --- a/build-boxes.yml +++ b/build-boxes.yml @@ -12,6 +12,7 @@ - debian9 - ubuntu1804 - ubuntu2004 + - ubuntu2204 versions: {} tasks: From fdcef674a711ab4d9dc72d25041717c624bfbdf8 Mon Sep 17 00:00:00 2001 From: Maros Kukan Date: Wed, 27 Jul 2022 14:06:58 +0200 Subject: [PATCH 2/8] Initial commit --- ubuntu2204/README.md | 5 +++ ubuntu2204/Vagrantfile | 25 +++++++++++ ubuntu2204/box-config.json | 79 +++++++++++++++++++++++++++++++++++ ubuntu2204/builds/README.md | 1 + ubuntu2204/http/meta-data | 0 ubuntu2204/http/user-data | 33 +++++++++++++++ ubuntu2204/http/vendor-data | 0 ubuntu2204/scripts/ansible.sh | 10 +++++ ubuntu2204/scripts/cleanup.sh | 24 +++++++++++ ubuntu2204/scripts/setup.sh | 8 ++++ 10 files changed, 185 insertions(+) create mode 100644 ubuntu2204/README.md create mode 100644 ubuntu2204/Vagrantfile create mode 100644 ubuntu2204/box-config.json create mode 100644 ubuntu2204/builds/README.md create mode 100644 ubuntu2204/http/meta-data create mode 100644 ubuntu2204/http/user-data create mode 100644 ubuntu2204/http/vendor-data create mode 100644 ubuntu2204/scripts/ansible.sh create mode 100644 ubuntu2204/scripts/cleanup.sh create mode 100644 ubuntu2204/scripts/setup.sh diff --git a/ubuntu2204/README.md b/ubuntu2204/README.md new file mode 100644 index 0000000..967a2c9 --- /dev/null +++ b/ubuntu2204/README.md @@ -0,0 +1,5 @@ +# Packer Build - Ubuntu 20.04 minimal Vagrant Box + +**Current Ubuntu Version Used**: 22.04 Live server install image + +See the [project README.md](../README.md) for usage instructions. diff --git a/ubuntu2204/Vagrantfile b/ubuntu2204/Vagrantfile new file mode 100644 index 0000000..d2719d6 --- /dev/null +++ b/ubuntu2204/Vagrantfile @@ -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 diff --git a/ubuntu2204/box-config.json b/ubuntu2204/box-config.json new file mode 100644 index 0000000..846f7ff --- /dev/null +++ b/ubuntu2204/box-config.json @@ -0,0 +1,79 @@ +{ + "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": [ + "c", + "linux /casper/vmlinuz autoinstall quiet net.ifnames=0 biosdevname=0 ", + "ds='nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/' --- ", + "initrd /casper/initrd", + "boot" + ], + "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", + "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" + } + ] + ] +} \ No newline at end of file diff --git a/ubuntu2204/builds/README.md b/ubuntu2204/builds/README.md new file mode 100644 index 0000000..fbaa9ab --- /dev/null +++ b/ubuntu2204/builds/README.md @@ -0,0 +1 @@ +This directory will contain built Vagrant box files. \ No newline at end of file diff --git a/ubuntu2204/http/meta-data b/ubuntu2204/http/meta-data new file mode 100644 index 0000000..e69de29 diff --git a/ubuntu2204/http/user-data b/ubuntu2204/http/user-data new file mode 100644 index 0000000..2f8e644 --- /dev/null +++ b/ubuntu2204/http/user-data @@ -0,0 +1,33 @@ +#cloud-config +autoinstall: + version: 1 + locale: en_US.UTF-8 + keyboard: + layout: us + variant: us + + early-commands: + - systemctl stop ssh + + ssh: + install-server: true + allow-pw: true + + identity: + hostname: ubuntu2004 + password: "$6$8P/WYeedh2vMmmn4$5LZtQr7MvzvtE2AGkQIlXJjZKyOUOyHwOcu5WSYBO7ls3.rgnGfl.236U0uAGbFY2ZCJt55tFBeJ1P1j.WQp/1" #vagrant + username: vagrant + + storage: + layout: + name: lvm + + packages: + - cryptsetup + - build-essential + - libssl-dev + - libreadline-dev + - zlib1g-dev + - linux-source + - dkms + - nfs-common diff --git a/ubuntu2204/http/vendor-data b/ubuntu2204/http/vendor-data new file mode 100644 index 0000000..e69de29 diff --git a/ubuntu2204/scripts/ansible.sh b/ubuntu2204/scripts/ansible.sh new file mode 100644 index 0000000..c173dd9 --- /dev/null +++ b/ubuntu2204/scripts/ansible.sh @@ -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 diff --git a/ubuntu2204/scripts/cleanup.sh b/ubuntu2204/scripts/cleanup.sh new file mode 100644 index 0000000..a2cabb0 --- /dev/null +++ b/ubuntu2204/scripts/cleanup.sh @@ -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 diff --git a/ubuntu2204/scripts/setup.sh b/ubuntu2204/scripts/setup.sh new file mode 100644 index 0000000..2175868 --- /dev/null +++ b/ubuntu2204/scripts/setup.sh @@ -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 From 105454a9959da536256ae032af12c2f4fc875004 Mon Sep 17 00:00:00 2001 From: Maros Kukan Date: Wed, 27 Jul 2022 20:11:56 +0200 Subject: [PATCH 3/8] Remove extra device options --- ubuntu2204/box-config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ubuntu2204/box-config.json b/ubuntu2204/box-config.json index 846f7ff..1228ff0 100644 --- a/ubuntu2204/box-config.json +++ b/ubuntu2204/box-config.json @@ -29,7 +29,7 @@ "type": "virtualbox-iso", "boot_command": [ "c", - "linux /casper/vmlinuz autoinstall quiet net.ifnames=0 biosdevname=0 ", + "linux /casper/vmlinuz autoinstall ", "ds='nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/' --- ", "initrd /casper/initrd", "boot" From a768061b70b823dc0f565bcf870fe2edd979bf0b Mon Sep 17 00:00:00 2001 From: Maros Kukan Date: Wed, 27 Jul 2022 20:12:28 +0200 Subject: [PATCH 4/8] Update release to 22.04 --- ubuntu2204/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ubuntu2204/README.md b/ubuntu2204/README.md index 967a2c9..3a7b51d 100644 --- a/ubuntu2204/README.md +++ b/ubuntu2204/README.md @@ -1,4 +1,4 @@ -# Packer Build - Ubuntu 20.04 minimal Vagrant Box +# Packer Build - Ubuntu 22.04 minimal Vagrant Box **Current Ubuntu Version Used**: 22.04 Live server install image From b8f09f9b3e33c0ce1537d2073b8bec3d2da10f71 Mon Sep 17 00:00:00 2001 From: Maros Kukan Date: Wed, 27 Jul 2022 20:26:08 +0200 Subject: [PATCH 5/8] Disable nfs over UDP --- ubuntu2204/Vagrantfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ubuntu2204/Vagrantfile b/ubuntu2204/Vagrantfile index d2719d6..f307f8f 100644 --- a/ubuntu2204/Vagrantfile +++ b/ubuntu2204/Vagrantfile @@ -3,12 +3,12 @@ Vagrant.configure("2") do |config| config.ssh.insert_key = false - config.vm.synced_folder '.', '/vagrant', type: 'nfs' + config.vm.synced_folder '.', '/vagrant', type: 'nfs', nfs_udp: false # VirtualBox. config.vm.define "virtualbox" do |virtualbox| virtualbox.vm.hostname = "virtualbox-ubuntu2204" - virtualbox.vm.box = "file://builds/virtualbox-ubuntu2204.box" + virtualbox.vm.box = "file://builds/virtualbox-ubuntu2205.box" virtualbox.vm.network :private_network, ip: "172.16.3.21" config.vm.provider :virtualbox do |v| From e4812a2ceea0e5a86e79fee440b8e8722f71e27f Mon Sep 17 00:00:00 2001 From: Maros Kukan Date: Wed, 27 Jul 2022 20:35:36 +0200 Subject: [PATCH 6/8] Update box path with correct version --- ubuntu2204/Vagrantfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ubuntu2204/Vagrantfile b/ubuntu2204/Vagrantfile index f307f8f..1d47e61 100644 --- a/ubuntu2204/Vagrantfile +++ b/ubuntu2204/Vagrantfile @@ -8,7 +8,7 @@ Vagrant.configure("2") do |config| # VirtualBox. config.vm.define "virtualbox" do |virtualbox| virtualbox.vm.hostname = "virtualbox-ubuntu2204" - virtualbox.vm.box = "file://builds/virtualbox-ubuntu2205.box" + virtualbox.vm.box = "file://builds/virtualbox-ubuntu2204.box" virtualbox.vm.network :private_network, ip: "172.16.3.21" config.vm.provider :virtualbox do |v| From 912badd8cfb33bf5bfdbc1589672688b185bb653 Mon Sep 17 00:00:00 2001 From: Maros Kukan Date: Wed, 27 Jul 2022 20:37:50 +0200 Subject: [PATCH 7/8] Add vagrant-cloud post-processor --- ubuntu2204/box-config.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ubuntu2204/box-config.json b/ubuntu2204/box-config.json index 1228ff0..76e8e42 100644 --- a/ubuntu2204/box-config.json +++ b/ubuntu2204/box-config.json @@ -73,6 +73,11 @@ { "output": "builds/{{.Provider}}-ubuntu2204.box", "type": "vagrant" + }, + { + "type": "vagrant-cloud", + "box_tag": "geerlingguy/debian11", + "version": "{{user `version`}}" } ] ] From 99a8cd68cf0913d149230f3295c72d765b196d1d Mon Sep 17 00:00:00 2001 From: Maros Kukan Date: Wed, 27 Jul 2022 20:40:43 +0200 Subject: [PATCH 8/8] Update links for Ubuntu2204 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 63b859f..7cd0d2e 100644 --- a/README.md +++ b/README.md @@ -4,7 +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/ubuntu2004) - [`ubuntu22code 04` directory](ubuntu2004/) + - [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/)