From b0a9526e2832f18013fd6b843a39ff0a62861fd7 Mon Sep 17 00:00:00 2001 From: Steve Brasier Date: Tue, 9 Sep 2025 10:28:19 +0000 Subject: [PATCH 1/2] add validation for tofu-templated vars --- ansible/validate.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ansible/validate.yml b/ansible/validate.yml index 33412756c..51f91fd2c 100644 --- a/ansible/validate.yml +++ b/ansible/validate.yml @@ -43,6 +43,34 @@ # below produced by dev/setup-env.sh - gives empty list if file is missing: _requirements_installed: "{{ ((lookup('file', _requirements_path + '.last', errors='ignore') or '{}') | from_yaml ).values() | flatten }}" +- name: Validate OpenTofu templated inventory is appropriate + # This "documents" the assumptions that Ansible makes about the + # OpenTofu-provided inventory + hosts: localhost + gather_facts: false + tags: + - validate + - opentofu + tasks: + - name: Check templated groups + assert: + that: + - item in groups + - groups[item] | length > 0 + fail_msg: "Expected inventory group '{{ item }}' is missing or empty: is OpenTofu inventory template up to date?" + loop: + - control + - compute + - login + - name: Check templated 'all' vars + assert: + that: + - openhpc_cluster_name is defined + - cluster_domain_suffix is defined + - cluster_home_volume is defined + - cluster_compute_groups is defined + fail_msg: "One or more expected variables are missing: is OpenTofu inventory template up to date?" + - name: Ensure control node is in inventory hosts: all gather_facts: false From 437c78d6ef2f041a1ac7b9805fbd1e84d48b503e Mon Sep 17 00:00:00 2001 From: Steve Brasier Date: Wed, 10 Sep 2025 14:26:57 +0000 Subject: [PATCH 2/2] update error message iaw review --- ansible/validate.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ansible/validate.yml b/ansible/validate.yml index 51f91fd2c..034f4698a 100644 --- a/ansible/validate.yml +++ b/ansible/validate.yml @@ -57,7 +57,10 @@ that: - item in groups - groups[item] | length > 0 - fail_msg: "Expected inventory group '{{ item }}' is missing or empty: is OpenTofu inventory template up to date?" + fail_msg: > + Expected inventory group '{{ item }}' is missing or empty: + - Check OpenTofu inventory template is up to date + - Check OpenTofu configuration defines 'login' and 'compute' variables properly loop: - control - compute