|
14 | 14 | ansible.builtin.assert: |
15 | 15 | that: |
16 | 16 | - workload_name is defined |
17 | | - - workload_name | length > 0 |
| 17 | + - workload_name | trim | length > 0 |
18 | 18 | fail_msg: >- |
19 | 19 | Please run the playbook with '-e workload_name=' per the docs. |
20 | 20 | Make sure you wrap the 'workload_name' value in single quotes. |
|
169 | 169 | assignments_summary: >- |
170 | 170 | {%- set result = [] -%} |
171 | 171 | {%- 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( |
174 | 174 | 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) -%} |
177 | 177 | {%- set _ = asn.update({'check_status_command': check_cmd, 'terminate_command': term_cmd}) -%} |
178 | 178 | {%- set _ = result.append(asn) -%} |
179 | 179 | {%- endfor -%} |
|
225 | 225 | - name: Prepare user-specified hosts for scheduling |
226 | 226 | when: schedule_servers is defined |
227 | 227 | 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 }}" |
229 | 229 |
|
230 | 230 | - name: Auto-select hosts when none are specified |
231 | 231 | when: schedule_servers is not defined |
|
247 | 247 | needed: "{{ num_hosts | default(1) | int }}" |
248 | 248 | selected_json: >- |
249 | 249 | {%- set result = [] -%} |
250 | | - {%- for model_result in available_by_model.results -%} |
| 250 | + {%- for model_result in available_by_model.results | default([]) -%} |
251 | 251 | {%- set hosts = model_result.json | default([]) -%} |
252 | 252 | {%- if hosts is sequence and not hosts is string -%} |
253 | 253 | {%- if result | length < needed | int -%} |
|
272 | 272 | vars: |
273 | 273 | selected_hosts_info: >- |
274 | 274 | {%- set lines = [] -%} |
275 | | - {%- for model_result in available_by_model.results -%} |
| 275 | + {%- for model_result in available_by_model.results | default([]) -%} |
276 | 276 | {%- set hosts = model_result.json | default([]) -%} |
277 | 277 | {%- if hosts is sequence and not hosts is string -%} |
278 | 278 | {%- for h in hosts_to_schedule -%} |
|
290 | 290 | - name: Select first available hosts (no model preference) |
291 | 291 | when: preferred_models is not defined or preferred_models is string |
292 | 292 | 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 }}" |
294 | 294 | vars: |
295 | 295 | selected_hostnames: "{{ available_hosts.json[: (num_hosts | default(1) | int)] }}" |
296 | 296 | changed_when: false |
|
370 | 370 | - name: Set facts from unified assignment data |
371 | 371 | ansible.builtin.set_fact: |
372 | 372 | 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') }}" |
375 | 375 | changed_when: false |
376 | 376 |
|
377 | 377 | - name: Display generated Jira ticket number |
378 | | - when: generated_jira_ticket is defined |
| 378 | + when: generated_jira_ticket != 'None' |
379 | 379 | ansible.builtin.debug: |
380 | 380 | msg: "Using assignment with Jira Ticket: {{ generated_jira_ticket }}" |
381 | 381 | changed_when: false |
|
435 | 435 | quads_username: {{ quads_username }} |
436 | 436 | quads_password: {{ quads_password }} |
437 | 437 | quads_token: {{ quads_token }} |
438 | | - mode: '0600' |
| 438 | + mode: "0600" |
439 | 439 |
|
440 | 440 | - name: Generate YAML file with scheduled hosts |
441 | 441 | ansible.builtin.copy: |
442 | 442 | dest: "./scheduled_hosts_{{ ansible_date_time.date }}_{{ ansible_date_time.hour }}-{{ ansible_date_time.minute }}-{{ ansible_date_time.second }}.yml" |
443 | 443 | content: "{{ {'scheduled_hosts': hosts_to_schedule} | to_nice_yaml }}" |
444 | | - mode: '0644' |
| 444 | + mode: "0644" |
445 | 445 |
|
446 | 446 | - name: Generate file with helper commands |
447 | 447 | ansible.builtin.copy: |
|
452 | 452 |
|
453 | 453 | # Command to terminate your assignment when you are finished: |
454 | 454 | {{ terminate_command }} |
455 | | - mode: '0644' |
| 455 | + mode: "0644" |
0 commit comments