The working rules come first because they are what the rest of this commit came out of. Every expensive mistake in this work had one shape: an action reported success, had not changed anything, and a measurement was built on top of it. A sed whose pattern did not match. A str.replace guarded by an assertion that only checked the value was absent beforehand. A wwctl image import that refused an existing name, so a full boot measurement ran against the old image and 234s was reported as real. A pgrep completion check that matched its own shell and could never report completion. The rule is to read the changed state back rather than trust an exit code, and to assert what a measurement depends on before measuring. Profiling a cold provision - which needed a fix of its own, since the first-boot runner started ansible-playbook from / and so never loaded ansible.cfg at all, quietly using stock defaults for the tmp paths that file exists to set - showed one task dominating: 33.6s of the 80s went to "Install epel-release", which installs nothing. The template already has it. The time was dnf rebuilding the metadata cache that the template build deletes on its way out; the same task against a warm cache takes 2.7s. Keeping the cache would have been the smaller fix and the wrong one: the saving decays as the template ages and dnf expires the metadata anyway. The first-boot path now skips install-tagged tasks outright. They put software on disk, this only ever runs on a clone of a template that has it, and skipping them also takes EPEL and OpenHPC back out of the provisioning path - an outage at either meant no tenant could be created at all. The control plane still runs the full playbook for day-2 work. The template cleanup now also removes /root/.docker/config.json. With the image inherited rather than pulled, no tenant needs the registry credential, and leaving it there shipped one - narrow, read-only, but real - into every tenant ever cloned. A control-plane run that does need to pull writes it again from the environment. Task profiling is on permanently. A provision getting slower is the failure mode here, and without per-task timings the only way to find out where the time went is to instrument it again afterwards, on a cluster that has since been destroyed. Not yet measured: the expected drop from 80s. Last verified provision was 178s total - terraform 32s, configuration 80s, node PXE 66s.
54 lines
2.3 KiB
Bash
Executable File
54 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# Configure this head node from the inventory cloud-init left for it.
|
|
#
|
|
# Runs once, on the first boot of a clone. Does nothing at all if there is no
|
|
# inventory, so the template itself and any clone provisioned another way are
|
|
# unaffected.
|
|
set -euo pipefail
|
|
|
|
INVENTORY=/etc/hpcod/inventory.yml
|
|
PLAYBOOK=/opt/hpcod/ansible/site.yml
|
|
STATE=/var/lib/hpcod-firstboot
|
|
LOG=/var/log/hpcod-firstboot.log
|
|
|
|
[ -f "${INVENTORY}" ] || { echo "no inventory at ${INVENTORY}; nothing to do"; exit 0; }
|
|
[ -e "${STATE}/done" ] && { echo "already provisioned"; exit 0; }
|
|
|
|
mkdir -p "${STATE}"
|
|
|
|
# The status file is what the control plane polls. It is written before the
|
|
# run starts so that a caller can tell "still working" from "never started" -
|
|
# a distinction that matters when the interesting failures are the ones where
|
|
# nothing happens at all.
|
|
echo "running" > "${STATE}/status"
|
|
|
|
# ansible.cfg is found relative to the working directory, and systemd starts
|
|
# this in /. Without ANSIBLE_CONFIG the run silently used stock defaults -
|
|
# no profiling, and none of the tmp paths the config exists to set - while
|
|
# looking like it had worked, because the defaults happen to be adequate.
|
|
rc=0
|
|
#
|
|
# --skip-tags install: every install-tagged task puts software on disk, and
|
|
# this script only ever runs on a clone of a template that already has it.
|
|
# Re-running them cost 34s of the 80s a provision took - not installing
|
|
# anything, just rebuilding the dnf metadata cache that the template build
|
|
# deletes on its way out. It also put the external package repositories back
|
|
# in the provisioning path, where an outage at EPEL or OpenHPC would have
|
|
# meant no tenant could be created. The control plane still runs the full
|
|
# playbook for day-2 work, where the software genuinely may be missing.
|
|
ANSIBLE_CONFIG=/opt/hpcod/ansible/ansible.cfg \
|
|
ANSIBLE_COLLECTIONS_PATH=/usr/share/ansible/collections \
|
|
ansible-playbook -i "${INVENTORY}" "${PLAYBOOK}" --skip-tags install \
|
|
>>"${LOG}" 2>&1 || rc=$?
|
|
|
|
if [ "${rc}" -eq 0 ]; then
|
|
echo "ok" > "${STATE}/status"
|
|
touch "${STATE}/done"
|
|
else
|
|
# Left as "failed", not retried. A half-configured cluster that keeps
|
|
# reconfiguring itself is harder to diagnose than one that stopped and says
|
|
# where the log is.
|
|
echo "failed rc=${rc}; see ${LOG}" > "${STATE}/status"
|
|
fi
|
|
exit "${rc}"
|