Skip to content

Commit dbccf26

Browse files
committed
lambdalabs: Validate tier selection script output format
The tier selection script outputs "instance_type region" which is then parsed by splitting on whitespace and accessing indices [0] and [1]. If the script produces unexpected output such as an empty line or a single word, the split operation produces a list with fewer than two elements, causing Ansible to fail with a cryptic index error. Add an explicit validation task using ansible.builtin.assert to verify the output contains exactly two whitespace-separated values before attempting to parse it. This provides a clear error message showing the actual output when the format is invalid, making debugging easier. Generated-by: Claude AI Signed-off-by: Chuck Lever <cel@kernel.org>
1 parent eebb25d commit dbccf26

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

playbooks/roles/terraform/tasks/main.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,21 @@
138138
tags:
139139
- bringup
140140

141+
- name: Validate Lambda Labs tier selection output format
142+
ansible.builtin.assert:
143+
that:
144+
- lambdalabs_auto_instance_type.stdout.split() | length == 2
145+
fail_msg: |
146+
Invalid output from tier selection script.
147+
Expected format: "instance_type region"
148+
Got: "{{ lambdalabs_auto_instance_type.stdout }}"
149+
when:
150+
- kdevops_terraform_provider == "lambdalabs"
151+
- terraform_lambdalabs_instance_type in ["GH200_OR_LESS", "H100_OR_LESS", "A100_OR_LESS", "A6000_OR_LESS", "8X_B200_OR_LESS", "8X_H100_OR_LESS", "8X_A100_OR_LESS"]
152+
- lambdalabs_auto_instance_type.rc == 0
153+
tags:
154+
- bringup
155+
141156
- name: Parse Lambda Labs auto-selected instance type and region
142157
set_fact:
143158
lambdalabs_auto_selected_instance: "{{ lambdalabs_auto_instance_type.stdout.split()[0] }}"

0 commit comments

Comments
 (0)