forked from tim/k3s-ansible
feat(site): fail fast when cluster nodes share a hostname (#697)
Add a preflight assertion to site.yml that confirms every host in the k3s_cluster group reports a unique hostname. k3s registers each node keyed by its hostname, so duplicate hostnames prevent nodes from joining the cluster and are hard to troubleshoot. The check fails fast in the Pre tasks instead of surfacing as a cryptic registration failure later. - site.yml: assert (cluster_hostnames | unique | length) == length for the k3s_cluster group, skipping hosts outside that group - README.md: document the unique-hostname requirement - .github/scripts/test-unique-hostname-precheck.sh: regression test - .pre-commit-config.yaml: wire the test into pre-commit Closes #636
This commit is contained in:
@@ -8,6 +8,23 @@
|
||||
msg: >
|
||||
"Ansible is out of date. See here for more info: https://docs.technotim.com/posts/ansible-automation/"
|
||||
|
||||
- name: Verify all cluster nodes have unique hostnames
|
||||
ansible.builtin.assert:
|
||||
that: (cluster_hostnames | unique | length) == (cluster_hostnames | length)
|
||||
msg: >-
|
||||
k3s nodes must have unique hostnames. Found a duplicate in:
|
||||
{{ cluster_hostnames | unique }}. Each node registers in the cluster
|
||||
keyed by its hostname, so matching hostnames prevent nodes from joining.
|
||||
vars:
|
||||
cluster_hostnames: >-
|
||||
{{
|
||||
groups['k3s_cluster']
|
||||
| map('extract', hostvars, 'ansible_hostname')
|
||||
| list
|
||||
}}
|
||||
run_once: true
|
||||
when: "'k3s_cluster' in groups"
|
||||
|
||||
- name: Prepare Proxmox cluster
|
||||
hosts: proxmox
|
||||
gather_facts: true
|
||||
|
||||
Reference in New Issue
Block a user