Skip to content

Commit

Permalink
add debian12 to test
Browse files Browse the repository at this point in the history
  • Loading branch information
goffinet committed Oct 20, 2024
1 parent d47d603 commit 6fd3ddb
Show file tree
Hide file tree
Showing 8 changed files with 302 additions and 5 deletions.
6 changes: 6 additions & 0 deletions build-packer-templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
iso_url: "https://fedora.cu.be/linux/releases/40/Server/x86_64/iso"
iso_name: "Fedora-Server-netinst-x86_64-40-1.14.iso"
checksum_filename: "Fedora-Server-40-1.14-x86_64-CHECKSUM"
- type: "debian"
flavor: "debian"
version: "12"
iso_url: "https://cdimage.debian.org/debian-cd/current/amd64/iso-cd"
iso_name: "debian-11.3.0-amd64-netinst.iso"
checksum_filename: "SHA256SUMS"
- type: "debian"
flavor: "ubuntu"
version: "20.04"
Expand Down
118 changes: 118 additions & 0 deletions debian12.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#Generated by packer-kvm/build-packer-templates.yaml

packer {
required_plugins {
qemu = {
version = "~> 1"
source = "github.com/hashicorp/qemu"
}
ansible = {
version = ">= 1.1.2"
source = "github.com/hashicorp/ansible"
}
}
}

variable "cpu" {
type = string
default = "2"
}

variable "destination_server" {
type = string
default = "download.goffinet.org"
}

variable "disk_size" {
type = string
default = "40000"
}

variable "headless" {
type = string
default = "true"
}

variable "iso_checksum" {
type = string
default = "file:https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/SHA256SUMS"
}

variable "iso_url" {
type = string
default = "https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-11.3.0-amd64-netinst.iso"
}

variable "name" {
type = string
default = "debian"
}

variable "ram" {
type = string
default = "2048"
}

variable "ssh_password" {
type = string
default = "testtest"
}

variable "ssh_username" {
type = string
default = "root"
}

variable "version" {
type = string
default = "12"
}

source "qemu" "debian12" {
accelerator = "kvm"
boot_command = ["<esc><wait>", "auto <wait>", "console-keymaps-at/keymap=us <wait>", "console-setup/ask_detect=false <wait>", "debconf/frontend=noninteractive <wait>", "debian-installer=en_US <wait>", "fb=false <wait>", "install <wait>", "kbd-chooser/method=us <wait>", "keyboard-configuration/xkb-keymap=us <wait>", "locale=en_US <wait>", "netcfg/get_hostname=${var.name}${var.version} <wait>", "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/http/${var.config_file} <wait>", "<enter><wait>"]
disk_cache = "none"
disk_compression = true
disk_discard = "unmap"
disk_interface = "virtio"
disk_size = var.disk_size
format = "qcow2"
headless = var.headless
http_directory = "."
iso_checksum = var.iso_checksum
iso_url = var.iso_url
net_device = "virtio-net"
output_directory = "artifacts/qemu/${var.name}${var.version}"
qemu_binary = "/usr/bin/qemu-system-x86_64"
qemuargs = [["-m", "${var.ram}M"], ["-smp", "${var.cpu}"], ["-cpu", "host"]]
shutdown_command = "sudo /usr/sbin/shutdown -h now"
ssh_password = var.ssh_password
ssh_username = var.ssh_username
boot_wait = "3s"
ssh_handshake_attempts = 500
ssh_timeout = "45m"
ssh_wait_timeout = "45m"
host_port_max = 2229
host_port_min = 2222
http_port_max = 10089
http_port_min = 10082
}

build {
sources = ["source.qemu.debian12"]

provisioner "shell" {
execute_command = "{{ .Vars }} sudo -E bash '{{ .Path }}'"
inline = ["apt-get update", "apt -y install python3 python3-pip", "pip3 install ansible"]
}

provisioner "ansible-local" {
playbook_dir = "ansible"
playbook_file = "ansible/playbook.yml"
}

post-processor "shell-local" {
environment_vars = ["IMAGE_NAME=${var.name}", "IMAGE_VERSION=${var.version}", "DESTINATION_SERVER=${var.destination_server}"]
script = "scripts/push-image.sh"
}
}
Empty file added http/debian12/meta-data
Empty file.
36 changes: 36 additions & 0 deletions http/debian12/user-data
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#cloud-config
autoinstall:
version: 1
identity:
hostname: debian12
username: ubuntu
password: $6$rounds=4096$mB3ZauOM8/HIycgS$iaaXsE86il1SLeotstYVkkQXG9md.tG0QMyWvszGlc4zye9SxK3W3lnyYT5K9vkgZWZa7QFwIOIqPE8umY7zg1
user-data:
disable_root: false
keyboard:
layout: us
locale: en_US
network:
ethernets:
eth0:
dhcp4: true
dhcp-identifier: mac
version: 2
ssh:
allow-pw: true
install-server: true
storage:
layout:
name: lvm
late-commands:
- sed -i -e 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /target/etc/ssh/sshd_config
- sed -i -e 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /target/etc/ssh/sshd_config
- echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' > /target/etc/sudoers.d/ubuntu
- sed -ie 's/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX="net.ifnames=0 ipv6.disable=1 biosdevname=0"/' /target/etc/default/grub
- curtin in-target --target /target update-grub2
packages:
- bc
- curl
- wget
- openssh-server
# - qemu-guest-agent
50 changes: 50 additions & 0 deletions http/user-data
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
d-i pkgsel/install-language-support boolean false

# locale
d-i debian-installer/locale string en_US.UTF-8

# keyboard
d-i keyboard-configuration/xkb-keymap select us

# timezone
d-i time/zone string Europe/Paris

# Controls whether to use NTP to set the clock during the install
d-i clock-setup/ntp boolean true

# apt
d-i mirror/country string manual
d-i mirror/http/hostname string ftp.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string
d-i apt-setup/use_mirror boolean true

# users
d-i passwd/root-password password testtest
d-i passwd/root-password-again password testtest
d-i passwd/make-user boolean false

# partitioning
d-i partman-auto/method string regular
d-i partman-auto/choose_recipe select atomic
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true

apt-cdrom-setup apt-setup/cdrom/set-first boolean false

# software
tasksel tasksel/first multiselect standard
d-i pkgsel/include string qemu-guest-agent wget openssh-server vim sudo cloud-init
popularity-contest popularity-contest/participate boolean false

# grub
d-i grub-installer/only_debian boolean true
d-i grub-installer/bootdev string /dev/vda

# script
d-i preseed/late_command string in-target sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

# finish
d-i finish-install/reboot_in_progress note
29 changes: 24 additions & 5 deletions roles/build_packer_templates/defaults/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,37 @@ boot_command: >-
"initrd /casper/initrd<enter><wait>",
"boot<enter><wait>"]
{%- endif -%}
{%- if flavor == 'debian' -%}
["<esc><wait>", "auto <wait>",
"console-keymaps-at/keymap=us <wait>",
"console-setup/ask_detect=false <wait>",
"debconf/frontend=noninteractive <wait>",
"debian-installer=en_US <wait>",
"fb=false <wait>",
"install <wait>",
"kbd-chooser/method=us <wait>",
"keyboard-configuration/xkb-keymap=us <wait>",
"locale=en_US <wait>",
"netcfg/get_hostname=${var.name}${var.version} <wait>",
"preseed/url=http://{% raw %}{{ .HTTPIP }}:{{ .HTTPPort }}{% endraw %}/http/${var.config_file} <wait>",
"<enter><wait>"]
{%- endif -%}
{%- endif -%}
ssh_password_salt: >-
mB3ZauOM8/HIycgS
ssh_password: >-
{%- if type == 'redhat' -%}
{%- if type == 'redhat' or flavor == 'debian' -%}
testtest
{%- elif type == 'debian' -%}
{%- elif flavor == 'ubuntu' -%}
ubuntu
{%- endif -%}
ssh_username: >-
{%- if type == 'redhat' -%}
{%- if type == 'redhat' or flavor == 'debian' -%}
root
{%- elif type == 'debian' -%}
{%- elif flavor == 'ubuntu' -%}
ubuntu
{%- endif -%}
Expand All @@ -63,10 +78,14 @@ shell_provisioner: >-
{%- if type == 'redhat' -%}
["dnf -y install python3 python3-pip",
"pip3 install ansible"]
{%- elif type == 'debian' -%}
{%- elif flavor == 'ubuntu' -%}
["sudo apt-get update",
"sudo apt-get -y install software-properties-common",
"sudo apt-add-repository --yes --update ppa:ansible/ansible",
"sudo apt update",
"sudo apt -y install ansible"]
{% elif flavor == 'debian' %}
["apt-get update",
"apt -y install python3 python3-pip",
"pip3 install ansible"]
{%- endif -%}
18 changes: 18 additions & 0 deletions roles/build_packer_templates/tasks/debian.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
type: "{{ item.type }}"
flavor: "{{ item.flavor }}"

- name: Set debian flavor computed variables
ansible.legacy.set_fact:
label: "{{ item.flavor }}{{ item.version.split('.')[0] }}"
version: "{{ item.version.split('.')[0] }}"
preseed_suffix: "-preseed.cfg"
when: item.flavor == "debian"

- name: Set ubuntu computed variables
ansible.legacy.set_fact:
label: "{{ item.flavor }}{{ item.version.split('.')[0] }}{{ item.version.split('.')[1] }}"
Expand Down Expand Up @@ -33,3 +40,14 @@
ansible.legacy.template:
src: "{{ metadata_file }}.j2"
dest: "{{ playbook_dir }}/http/{{ label }}/{{ metadata_file }}"

- name: Create debian flavor http directory
ansible.legacy.file:
dest: "{{ playbook_dir }}/http"
state: directory

- name: Create debian flavor preseed file
ansible.legacy.template:
src: "preseed.cfg.j2"
dest: "{{ playbook_dir }}/http/{{ config_file }}"

50 changes: 50 additions & 0 deletions roles/build_packer_templates/templates/preseed.cfg.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
d-i pkgsel/install-language-support boolean false

# locale
d-i debian-installer/locale string en_US.UTF-8

# keyboard
d-i keyboard-configuration/xkb-keymap select us

# timezone
d-i time/zone string Europe/Paris

# Controls whether to use NTP to set the clock during the install
d-i clock-setup/ntp boolean true

# apt
d-i mirror/country string manual
d-i mirror/http/hostname string ftp.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string
d-i apt-setup/use_mirror boolean true

# users
d-i passwd/root-password password testtest
d-i passwd/root-password-again password testtest
d-i passwd/make-user boolean false

# partitioning
d-i partman-auto/method string regular
d-i partman-auto/choose_recipe select atomic
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true

apt-cdrom-setup apt-setup/cdrom/set-first boolean false

# software
tasksel tasksel/first multiselect standard
d-i pkgsel/include string qemu-guest-agent wget openssh-server vim sudo cloud-init
popularity-contest popularity-contest/participate boolean false

# grub
d-i grub-installer/only_debian boolean true
d-i grub-installer/bootdev string /dev/vda

# script
d-i preseed/late_command string in-target sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

# finish
d-i finish-install/reboot_in_progress note

0 comments on commit 6fd3ddb

Please sign in to comment.