Files
ilker f3241671ff hpcod: let the head node configure itself from cloud-init
The tenant playbook ran from the control plane, one SSH round trip per
task, for work that touches nothing but the head node. The template now
carries the automation, and Terraform hands each clone only its own
inventory as cloud-init vendor data; a first-boot unit runs the same
roles locally. The control plane drives Terraform and then watches a
status file instead of driving the provision itself - which is also
what makes this work unchanged against a provider that is not Proxmox.

Vendor data, not user data. Proxmox generates the user data that creates
the login account and installs its keys, and supplying our own would
replace that wholesale and lock the tenant out of its own head node.

Two things this surfaced, both invisible while the playbook ran over
SSH. systemd starts services with no HOME, and wwctl refuses to run
without one - a login shell had been supplying it. And the collections
were installed unpinned, which made the template a moving target; the
install already warned that current ansible.utils does not support the
ansible-core Rocky 9 ships. They are pinned to versions that do.

Node names, MACs and addresses were computed in four places - the VM
resource, two outputs, and now the inventory. They are computed once
and read from there. A MAC derived twice is exactly how a node ends up
PXE booting and never being recognised.

Measured, cold, destroy to a cluster running jobs on both nodes:
terraform 30s, self-configuration 82s, node PXE and Slurm 82s, total
194s against 215s. Less than the earlier estimate of ~60s off the
configure phase, and worth being precise about why: that estimate came
from timing a local run against an already-provisioned host, where most
tasks were no-ops. Cold against cold it is 100s remote to 78s local.
The rest of what the first-boot unit spends is waiting for cloud-init
to finish, which the old flow did not pay because it only waited for
sshd.
2026-09-02 07:16:29 +02:00

74 lines
2.7 KiB
YAML

---
# Make the head node able to configure itself.
#
# The tenant playbook used to run from the control plane, one SSH round trip
# per task. Measured on a 65-task provision that transport cost about 60
# seconds - more than half the total - for work that touches nothing but the
# head node itself. Running the same roles locally on the head takes ~39s
# instead of ~100s.
#
# So the template carries the automation, and a tenant is handed only its own
# inventory. The control plane still owns Terraform and still reaches the head
# for day-2 work; what it no longer does is drive first-time configuration
# over a network it has to wait for.
- name: Install the Ansible runtime
ansible.builtin.dnf:
name:
- ansible-core
# ansible.utils.ipaddr is a thin wrapper over this; without it the
# network tasks fail with an import error rather than a missing package.
- python3-netaddr
state: present
tags: [install]
# Pinned, and pinned to versions that support the ansible-core Rocky 9 ships
# (2.14). Installing whatever galaxy serves today would make the template a
# moving target and eventually pull a collection that refuses to run here -
# the unpinned install already warned that ansible.utils does not support
# 2.14.18.
- name: Install the collections the roles use
ansible.builtin.command:
cmd: >-
ansible-galaxy collection install {{ item.name }}:{{ item.version }}
-p /usr/share/ansible/collections
creates: /usr/share/ansible/collections/ansible_collections/{{ item.name | replace('.', '/') }}
loop:
- { name: ansible.posix, version: "1.5.4" }
- { name: ansible.utils, version: "2.12.0" }
# Supplies the yaml stdout callback named in ansible.cfg. Without it
# ansible-playbook refuses to start at all: "Invalid callback for stdout".
- { name: community.general, version: "8.6.0" }
tags: [install]
- name: Install the automation itself
ansible.builtin.copy:
src: "{{ playbook_dir }}/"
dest: /opt/hpcod/ansible/
mode: preserve
tags: [install]
- name: Install the first-boot runner
ansible.builtin.copy:
src: hpcod-firstboot
dest: /usr/local/sbin/hpcod-firstboot
mode: "0755"
tags: [install]
- name: Install the first-boot unit
ansible.builtin.copy:
src: hpcod-firstboot.service
dest: /etc/systemd/system/hpcod-firstboot.service
mode: "0644"
tags: [install]
# Enabled, not started. It is a no-op unless cloud-init has dropped an
# inventory, so it stays harmless in the template and on any clone that is
# provisioned some other way.
- name: Enable the first-boot unit
ansible.builtin.systemd_service:
name: hpcod-firstboot.service
enabled: true
daemon_reload: true
tags: [install]