diff --git a/README.md b/README.md index 12ad0bc..7cd0d2e 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/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/) 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: diff --git a/ubuntu2204/README.md b/ubuntu2204/README.md new file mode 100644 index 0000000..3a7b51d --- /dev/null +++ b/ubuntu2204/README.md @@ -0,0 +1,5 @@ +# Packer Build - Ubuntu 22.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..1d47e61 --- /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', 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.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..76e8e42 --- /dev/null +++ b/ubuntu2204/box-config.json @@ -0,0 +1,84 @@ +{ + "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 ", + "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" + }, + { + "type": "vagrant-cloud", + "box_tag": "geerlingguy/debian11", + "version": "{{user `version`}}" + } + ] + ] +} \ 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