Skip to content

Commit ee4142b

Browse files
authored
Merge pull request #30 from quadsproject/development
fix: more bulletproofing for R&D usage and new users
2 parents c129f71 + 822b434 commit ee4142b

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

quads_self_schedule.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
ansible.builtin.assert:
1515
that:
1616
- workload_name is defined
17-
- workload_name | length > 0
17+
- workload_name | trim | length > 0
1818
fail_msg: >-
1919
Please run the playbook with '-e workload_name=' per the docs.
2020
Make sure you wrap the 'workload_name' value in single quotes.
@@ -169,11 +169,11 @@
169169
assignments_summary: >-
170170
{%- set result = [] -%}
171171
{%- for asn in active_assignments.json -%}
172-
{%- set check_cmd = "curl -s https://{}/api/v3/assignments/{} | jq '.validated'".format(quads_api_server, asn.id) -%}
173-
{%- set login_cmd = "curl -s -k -X POST -u '{}:{}' https://{}/api/v3/login/ | jq -r '.auth_token'".format(
172+
{%- set check_cmd = "curl -s https://%s/api/v3/assignments/%s | jq '.validated'" | format(quads_api_server, asn.id) -%}
173+
{%- set login_cmd = "curl -s -k -X POST -u '%s:%s' https://%s/api/v3/login/ | jq -r '.auth_token'" | format(
174174
quads_user_email, quads_password, quads_api_server) -%}
175-
{%- set term_cmd = 'curl -s -k -X POST -H "Authorization: Bearer $({login})" https://{server}/api/v3/assignments/terminate/{id} | jq'.format(
176-
login=login_cmd, server=quads_api_server, id=asn.id) -%}
175+
{%- set term_cmd = 'curl -s -k -X POST -H "Authorization: Bearer $(%s)" https://%s/api/v3/assignments/terminate/%s | jq' | format(
176+
login_cmd, quads_api_server, asn.id) -%}
177177
{%- set _ = asn.update({'check_status_command': check_cmd, 'terminate_command': term_cmd}) -%}
178178
{%- set _ = result.append(asn) -%}
179179
{%- endfor -%}
@@ -225,7 +225,7 @@
225225
- name: Prepare user-specified hosts for scheduling
226226
when: schedule_servers is defined
227227
ansible.builtin.set_fact:
228-
hosts_to_schedule: "{{ schedule_servers.split(',') | map('trim') | map('community.general.dict_kv', 'name') }}"
228+
hosts_to_schedule: "{{ schedule_servers.split(',') | map('trim') | map('community.general.dict_kv', 'name') | list }}"
229229

230230
- name: Auto-select hosts when none are specified
231231
when: schedule_servers is not defined
@@ -247,7 +247,7 @@
247247
needed: "{{ num_hosts | default(1) | int }}"
248248
selected_json: >-
249249
{%- set result = [] -%}
250-
{%- for model_result in available_by_model.results -%}
250+
{%- for model_result in available_by_model.results | default([]) -%}
251251
{%- set hosts = model_result.json | default([]) -%}
252252
{%- if hosts is sequence and not hosts is string -%}
253253
{%- if result | length < needed | int -%}
@@ -272,7 +272,7 @@
272272
vars:
273273
selected_hosts_info: >-
274274
{%- set lines = [] -%}
275-
{%- for model_result in available_by_model.results -%}
275+
{%- for model_result in available_by_model.results | default([]) -%}
276276
{%- set hosts = model_result.json | default([]) -%}
277277
{%- if hosts is sequence and not hosts is string -%}
278278
{%- for h in hosts_to_schedule -%}
@@ -290,7 +290,7 @@
290290
- name: Select first available hosts (no model preference)
291291
when: preferred_models is not defined or preferred_models is string
292292
ansible.builtin.set_fact:
293-
hosts_to_schedule: "{{ selected_hostnames | map('community.general.dict_kv', 'name') }}"
293+
hosts_to_schedule: "{{ selected_hostnames | map('community.general.dict_kv', 'name') | list }}"
294294
vars:
295295
selected_hostnames: "{{ available_hosts.json[: (num_hosts | default(1) | int)] }}"
296296
changed_when: false
@@ -370,12 +370,12 @@
370370
- name: Set facts from unified assignment data
371371
ansible.builtin.set_fact:
372372
assignment_id: "{{ assignment_data.id }}"
373-
assignment_cloud: "{{ assignment_data.cloud.name }}"
374-
generated_jira_ticket: "{{ assignment_data.ticket }}"
373+
assignment_cloud: "{{ assignment_data.cloud.name | default('unknown') }}"
374+
generated_jira_ticket: "{{ assignment_data.ticket | default('None') }}"
375375
changed_when: false
376376

377377
- name: Display generated Jira ticket number
378-
when: generated_jira_ticket is defined
378+
when: generated_jira_ticket != 'None'
379379
ansible.builtin.debug:
380380
msg: "Using assignment with Jira Ticket: {{ generated_jira_ticket }}"
381381
changed_when: false
@@ -435,13 +435,13 @@
435435
quads_username: {{ quads_username }}
436436
quads_password: {{ quads_password }}
437437
quads_token: {{ quads_token }}
438-
mode: '0600'
438+
mode: "0600"
439439

440440
- name: Generate YAML file with scheduled hosts
441441
ansible.builtin.copy:
442442
dest: "./scheduled_hosts_{{ ansible_date_time.date }}_{{ ansible_date_time.hour }}-{{ ansible_date_time.minute }}-{{ ansible_date_time.second }}.yml"
443443
content: "{{ {'scheduled_hosts': hosts_to_schedule} | to_nice_yaml }}"
444-
mode: '0644'
444+
mode: "0644"
445445

446446
- name: Generate file with helper commands
447447
ansible.builtin.copy:
@@ -452,4 +452,4 @@
452452
453453
# Command to terminate your assignment when you are finished:
454454
{{ terminate_command }}
455-
mode: '0644'
455+
mode: "0644"

0 commit comments

Comments
 (0)