From e550f2f5a1f28ea31f1b197536cc281632622a77 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 19 Jan 2026 14:46:36 +0100 Subject: [PATCH] push --- .gitignore | 3 ++ LICENSE | 7 ++++ README.md | 47 ++++++++++++++++++++++++ Vagrantfile | 25 +++++++++++++ box-config.json | 90 ++++++++++++++++++++++++++++++++++++++++++++++ http/preseed.cfg | 48 +++++++++++++++++++++++++ scripts/ansible.sh | 9 +++++ scripts/cleanup.sh | 24 +++++++++++++ scripts/setup.sh | 8 +++++ 9 files changed, 261 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100755 README.md create mode 100644 Vagrantfile create mode 100755 box-config.json create mode 100644 http/preseed.cfg create mode 100644 scripts/ansible.sh create mode 100644 scripts/cleanup.sh create mode 100644 scripts/setup.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9035417 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +output-virtualbox-iso +builds/*.box +.vagrant \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..45636ca --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2026 Jeff Geerling, GregLebreton + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100755 index 0000000..216c8b6 --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# Build Vagrant box Debian 13 with virtualbox + +Debian 13 Vagrant box builder (Packer) from the project [Packer boxes](https://github.com/geerlingguy/packer-boxes) [Jeff Geerling](https://www.jeffgeerling.com), author of [Ansible for DevOps](https://www.ansiblefordevops.com) + +## Requirements + +The following software must be installed/present on your local machine before you can use Packer to build any of these Vagrant boxes: + + - [Packer](http://www.packer.io/) + - [Vagrant](http://vagrantup.com/) + - [VirtualBox](https://www.virtualbox.org/) + - [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) + +## Usage + +Make sure all the required software (listed above) is installed, then cd into one of the box directories and run: + + $ packer build -var 'version=1.2.0' box-config.json + +After a few minutes, Packer should tell you the box was generated successfully, and the box was uploaded to Vagrant Cloud. + +> **Note**: This configuration includes a post-processor that pushes the built box to Vagrant Cloud (which requires a `VAGRANT_CLOUD_TOKEN` environment variable to be set); remove the `vagrant-cloud` post-processor from the Packer template to build the box locally and not push it to Vagrant Cloud. You don't need to specify a `version` variable either, if not using the `vagrant-cloud` post-processor. + + +## Testing built boxes + +There's an included Vagrantfile that allows quick testing of the built Vagrant boxes. From the same box directory, run the following command after building the box: + + $ vagrant up + +Test that the box works correctly, then tear it down with: + + $ vagrant destroy -f + +## License + +MIT + +## Config + +- Modifier + +### Usage + +```bash +packer build -var 'version=1.0.0' box-config.json +``` diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..5b2d644 --- /dev/null +++ b/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-debian13" + virtualbox.vm.box = "file://builds/virtualbox-debian13.box" + virtualbox.vm.network :private_network, ip: "192.168.60.2" + + 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/box-config.json b/box-config.json new file mode 100755 index 0000000..b4aa10e --- /dev/null +++ b/box-config.json @@ -0,0 +1,90 @@ +{ + "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": [ + "", + "install ", + " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ", + "debian-installer=en_US.UTF-8 ", + "auto ", + "locale=en_US.UTF-8 ", + "kbd-chooser/method=us ", + "keyboard-configuration/xkb-keymap=us ", + "netcfg/get_hostname={{ .Name }} ", + "netcfg/get_domain=vagrantup.com ", + "fb=false ", + "debconf/frontend=noninteractive ", + "console-setup/ask_detect=false ", + "console-keymaps-at/keymap=us ", + "grub-installer/bootdev=/dev/sda ", + "" + ], + "boot_wait": "5s", + "disk_size": 81920, + "guest_os_type": "Debian_64", + "headless": true, + "http_directory": "http", + "iso_urls": [ + "debian-13.3.0-amd64-netinst.iso", + "https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-13.3.0-amd64-netinst.iso" + ], + "iso_checksum": "sha512:1ada40e4c938528dd8e6b9c88c19b978a0f8e2a6757b9cf634987012d37ec98503ebf3e05acbae9be4c0ec00b52e8852106de1bda93a2399d125facea45400f8", + "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-debian-13-amd64", + "vboxmanage": [ + [ + "modifyvm", + "{{.Name}}", + "--memory", + "1024" + ], + [ + "modifyvm", + "{{.Name}}", + "--cpus", + "1" + ] + ] + } + ], + "post-processors": [ + [ + { + "output": "builds/{{.Provider}}-debian13.box", + "type": "vagrant" + } + ] + ] +} diff --git a/http/preseed.cfg b/http/preseed.cfg new file mode 100644 index 0000000..5a11ade --- /dev/null +++ b/http/preseed.cfg @@ -0,0 +1,48 @@ +choose-mirror-bin mirror/http/proxy string +d-i apt-setup/use_mirror boolean true +d-i base-installer/kernel/override-image string linux-server +d-i clock-setup/utc boolean true +d-i clock-setup/utc-auto boolean true +d-i finish-install/reboot_in_progress note +d-i grub-installer/only_debian boolean true +d-i grub-installer/with_other_os boolean true +d-i keymap select us +d-i mirror/country string manual +d-i mirror/http/directory string /debian +d-i mirror/http/hostname string httpredir.debian.org +d-i mirror/http/proxy string +d-i partman-auto-lvm/guided_size string max +d-i partman-auto/choose_recipe select atomic +d-i partman-auto/method string lvm +d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm_nooverwrite boolean true +d-i partman-lvm/device_remove_lvm boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true +d-i partman/confirm_write_new_label boolean true +d-i passwd/root-login boolean false +d-i passwd/root-password-again password vagrant +d-i passwd/root-password password vagrant +d-i passwd/user-fullname string vagrant +d-i passwd/user-uid string 1000 +d-i passwd/user-password password vagrant +d-i passwd/user-password-again password vagrant +d-i passwd/username string vagrant +d-i pkgsel/include string sudo bzip2 acpid cryptsetup zlib1g-dev wget curl dkms make nfs-common net-tools openssh-server +d-i pkgsel/install-language-support boolean false +d-i pkgsel/update-policy select none +d-i pkgsel/upgrade select none +# Prevent packaged version of VirtualBox Guest Additions being installed: +# d-i preseed/early_command string sed -i \ +# '/in-target/idiscover(){/sbin/discover|grep -v VirtualBox;}' \ +# /usr/lib/pre-pkgsel.d/20install-hwpackages +d-i time/zone string UTC +d-i user-setup/allow-password-weak boolean true +d-i user-setup/encrypt-home boolean false +d-i preseed/late_command string sed -i '/^deb cdrom:/s/^/#/' /target/etc/apt/sources.list +apt-cdrom-setup apt-setup/cdrom/set-first boolean false +apt-mirror-setup apt-setup/use_mirror boolean true +popularity-contest popularity-contest/participate boolean false +tasksel tasksel/first multiselect standard, ssh-server diff --git a/scripts/ansible.sh b/scripts/ansible.sh new file mode 100644 index 0000000..62eafb6 --- /dev/null +++ b/scripts/ansible.sh @@ -0,0 +1,9 @@ +#!/bin/bash -eux + +# Install Ansible dependencies. +apt -y update && apt-get -y upgrade && apt -y install -y ansible +# apt -y update && apt-get -y upgrade +# apt -y install python3-pip python3-dev + +# # Install Ansible. +# pip3 install ansible diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh new file mode 100644 index 0000000..6a8f356 --- /dev/null +++ b/scripts/cleanup.sh @@ -0,0 +1,24 @@ +#!/bin/bash -eux + +# Uninstall Ansible and dependencies. +apt-get remove --purge ansible +rm -rf /home/vagrant/.ansible + +# Apt cleanup. +apt update -y +apt autoremove -y + +# 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/scripts/setup.sh b/scripts/setup.sh new file mode 100644 index 0000000..490498c --- /dev/null +++ b/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. Is this needed for Debian? +# echo 'APT::Periodic::Enable "0";' >> /etc/apt/apt.conf.d/10periodic