Skip to content

Instantly share code, notes, and snippets.

@acidprime
Last active February 20, 2021 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acidprime/a24a415a21c0cdb83622b282827fb10e to your computer and use it in GitHub Desktop.
Save acidprime/a24a415a21c0cdb83622b282827fb10e to your computer and use it in GitHub Desktop.
Razor Server Task for Debian Buster

Task notes for Debian Buster

Node Metadata

  • 'timezone' (optional) - This is the string corresponding to the timezone for the node.
    • Default: US/Pacific
  • 'root_password' (optional) - This is an override for the root_password that exists on the node when it binds to a policy. If this is provided, it will be used for the node's root password.
  • 'hostname' (optional) - This is an override for the hostname that exists on the node when it binds to a policy. If this is provided, it will be used for the node's hostname.
#!ipxe
echo Razor <%= task.label %> task boot_call
echo Installation node: <%= node_url %>
echo Installation repo: <%= repo_url %>
sleep 3
set cmdline <%= render_template("kernel_args").strip %>
<%
# Is this a new-style combined installer build, or one with only
# one architecture present in the files we discover? If so, we
# want to use that. This also allows us to handle architecture
# nicely for installation.
if repo_file?('install.amd') or repo_file?('install.386')
%>
# check for 64-bit CPU support and boot the AMD64 installer.
cpuid --ext 29 || goto i386
# AMD64 support in CPU, boot the AMD64 installer.
<% if repo_file?('install.amd') %>
echo detected AMD64 CPU support, booting AMD64 installer
kernel <%= repo_url('install.amd/vmlinuz') %> ${cmdline} || goto error
initrd <%= repo_url('install.amd/initrd.gz') %> || goto error
boot
<% else %>
echo No AMD64 installer present, expected install.amd directory
<% end %>
:i386
<% if repo_file?('install.386') %>
kernel <%= repo_url('install.386/vmlinuz') %> ${cmdline} || goto error
initrd <%= repo_url('install.386/initrd.gz') %> || goto error
boot
<% else %>
echo No i386 installer present, expected install.386 directory
<% end %>
:fail
echo Unable to find a suitable installer to boot, sorry
goto error
<% else %>
# fallback to classic boot mode, hope your arch matches...
kernel <%= repo_url("/linux") %> ${cmdline} || goto error
initrd <%= repo_url("/initrd.gz") %> || goto error
boot
<% end %>
DEBCONF_DEBUG=5 install auto=true url=<%= file_url("preseed") %> debian-installer=en_US locale=en_US kbd-chooser/method=us netcfg/get_hostname=<%= (node.metadata['hostname'] || node.hostname).split('.').first %> netcfg/get_domain=<%= (node.metadata['hostname'] || node.hostname).split('.').drop(1).join('.') %> fb=false debconf/frontend=noninteractive console-setup/ask_detect=false cloud-init=enabled ds=nocloud;local-hostname=<%= node.metadata['hostname'] %> netcfg/choose_interface=auto
---
os_version: buster
description: Debian Buster Installer
boot_sequence:
1: boot_install
default: boot_local
#!/bin/bash
exec >> /var/log/razor.log 2>&1
<%= render_template("set_hostname") %>
sed -i 's_<%= repo_url("archive.ubuntu.com/ubuntu_g")%>' /etc/apt/sources.list
apt-get -y update
[ "$?" -eq 0 ] || curl -s <%= log_url("apt_update_fail", :error) %>
apt-get -y upgrade
[ "$?" -eq 0 ] || curl -s <%= log_url("apt_upgrade_fail", :error) %>
<%= render_template("store_ip") %>
<%= render_template("os_complete") %>
# Send final state
curl -s <%= stage_done_url("finished") %>
#!/bin/bash
echo Razor policy successfully applied > /tmp/razor_complete.log
echo Installed using <%= task.label %> - <%= task.description %> >> /tmp/razor_complete.log
echo Repo: <%= repo_url %> >> /tmp/razor_complete.log
echo Node: <%= node_url %> >> /tmp/razor_complete.log
systemctl disable razor_postinstall.service
curl <%= broker_install_url %> | bash
if [ $? -ne 0 ]; then
echo "Broker run failed; see /var/log/razor.log for more details" >> /tmp/razor_complete.log
fi
#_preseed_V1
#### Contents of the preconfiguration file (for buster)
### Localization
# Preseeding only locale sets language, country and locale.
d-i debian-installer/locale string en_US
d-i console-keymaps-at/keymap select us
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/xkb-keymap select us
d-i keyboard-configuration/layoutcode string us
# If non-free firmware is needed for the network or other hardware, you can
# configure the installer to always try to load it, without prompting. Or
# change to false to disable asking.
d-i hw-detect/load_firmware boolean false
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string <%= node.metadata['hostname'] || node.hostname %>
d-i netcfg/get_domain string homeops.tech
d-i netcfg/no_default_route boolean true
### Mirror settings
d-i mirror/country string manual
d-i mirror/http/hostname string http.us.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string
# Suite to install.
d-i mirror/suite string buster
### Clock and time zone setup
d-i time/zone string <%= node.metadata['timezone'] || 'US/Pacific' %>
d-i clock-setup/utc boolean false
d-i clock-setup/ntp boolean true
d-i clock-setup/ntp-server string synology.homeops.tech
### Partitioning
<% if node.facts['is_virtual'] == true %>
d-i partman-auto/disk string /dev/sda
<% else %>
d-i partman-auto/disk string /dev/nvme0n1
<% end %>
d-i partman-auto/method string lvm
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-auto/purge_lvm_from_device boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-auto-lvm/guided_size string max
d-i partman-auto/choose_recipe select atomic
d-i partman/default_filesystem string ext4
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
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
d-i partman-md/confirm boolean true
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
### Account setup
d-i passwd/root-login boolean true
d-i passwd/make-user boolean false
d-i passwd/root-password password <%= node.metadata['root_password'] || node.root_password %>
d-i passwd/root-password-again password <%= node.metadata['root_password'] || node.root_password %>
d-i user-setup/allow-password-weak boolean true
### Apt setup
d-i apt-setup/backports boolean true
d-i debian-installer/allow_unauthenticated boolean true
tasksel tasksel/first multiselect standard
d-i pkgsel/include string ruby openssh-server build-essential curl
### Boot loader installation
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev string default
# GRUB timeout; for internal use
grub-pc grub-pc/timeout string 1
popularity-contest popularity-contest/participate boolean false
d-i finish-install/reboot_in_progress note
# Uncomment this for `nomodeset`.
# d-i debian-installer/add-kernel-opts string nomodeset
# Individual additional packages to install, customise this for your needs
d-i pkgsel/include string build-essential git openssh-server vim curl cloud-init
#Our callbacks
d-i preseed/early_command string wget <%= log_url("preseed start") %>; \
sh -c 'set -- $(vgs --rows --noheadings | head -n 1); for vg in "$@"; do swapoff "/dev/$vg/swap"; vgremove -f "$vg"; done; set -- $(pvs --rows --noheadings | head -n 1); for pv in "$@"; do pvremove -f "$pv"; done'
d-i preseed/late_command string wget <%= log_url("preseed end") %>; \
wget <%= file_url("os_boot") %> -O /target/usr/local/bin/razor_postinstall.sh; \
chmod +x /target/usr/local/bin/razor_postinstall.sh; \
wget <%= file_url("razor_systemd") %> -O /target/etc/systemd/system/razor_postinstall.service; \
in-target sh -c 'systemctl enable razor_postinstall.service'; \
in-target sh -c 'systemctl enable cloud-init-local.service'; \
in-target sh -c 'systemctl enable cloud-init.service'; \
in-target sh -c 'systemctl enable cloud-config.service'; \
in-target sh -c 'systemctl enable cloud-final.service'; \
wget <%= stage_done_url("preseed") %>
[Unit]
Description=Razor Post Install
ConditionFileIsExecutable=/usr/local/bin/razor_postinstall.sh
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/usr/local/bin/razor_postinstall.sh
TimeoutSec=0
StandardOutput=journal+console
StandardError=journal+console
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment