2018-11-06 16:35:06 +00:00
|
|
|
---
|
2022-09-06 07:56:29 +02:00
|
|
|
- name: Wait for resources
|
|
|
|
hosts: localhost
|
2019-03-27 16:42:35 +00:00
|
|
|
tags:
|
|
|
|
- resource-wait
|
2018-11-06 16:35:06 +00:00
|
|
|
tasks:
|
2018-11-22 16:50:08 +00:00
|
|
|
- name: Set default value for expected resources
|
|
|
|
set_fact:
|
|
|
|
tenks_expected_resources: []
|
2018-11-06 16:35:06 +00:00
|
|
|
|
2018-11-22 16:50:08 +00:00
|
|
|
- name: Build list of expected resources
|
|
|
|
# takes the form: [{ resource_class: CUSTOM_TEST_RC, amount: 2, traits: [] }, ]
|
|
|
|
vars:
|
|
|
|
resource:
|
|
|
|
amount: "{{ spec.count | int }}" # this gets converted back to a string
|
|
|
|
resource_class: "{{ 'CUSTOM_' ~ spec.ironic_config.resource_class | upper | replace('-', '_') }}"
|
2018-12-18 17:09:54 +00:00
|
|
|
traits: "{{ spec.ironic_config.traits | default([]) }}"
|
2018-11-22 16:50:08 +00:00
|
|
|
set_fact:
|
|
|
|
tenks_expected_resources: >-
|
|
|
|
{{ tenks_expected_resources + [resource] }}
|
|
|
|
loop: "{{ specs }}"
|
|
|
|
when: "'ironic_config' in spec"
|
|
|
|
loop_control:
|
|
|
|
loop_var: spec
|
2018-11-06 16:35:06 +00:00
|
|
|
|
2022-07-25 14:29:55 +02:00
|
|
|
- name: Include the wait-for-resources role
|
2023-04-19 16:41:42 +01:00
|
|
|
when: tenks_expected_resources | length > 0
|
2022-07-25 14:29:55 +02:00
|
|
|
block:
|
2022-03-29 11:29:20 +01:00
|
|
|
- name: Check that OpenStack credentials exist in the environment
|
|
|
|
fail:
|
|
|
|
msg: >
|
|
|
|
$OS_USERNAME was not found in the environment. Ensure the OpenStack
|
|
|
|
credentials exist in your environment, perhaps by sourcing your RC file.
|
|
|
|
when: not lookup('env', 'OS_USERNAME')
|
2018-11-06 16:35:06 +00:00
|
|
|
|
2022-03-29 11:29:20 +01:00
|
|
|
- name: Gather list of OpenStack services
|
|
|
|
command: >-
|
|
|
|
{{ virtualenv_path }}/bin/openstack service list -f json
|
|
|
|
register: service_list_output
|
|
|
|
changed_when: false
|
2018-11-06 16:35:06 +00:00
|
|
|
|
2022-03-29 11:29:20 +01:00
|
|
|
- name: Include the wait-for-resources role
|
|
|
|
include_role:
|
|
|
|
name: wait-for-resources
|
|
|
|
vars:
|
|
|
|
wait_for_resources_required_resources: "{{ tenks_expected_resources }}"
|
|
|
|
wait_for_resources_venv: "{{ virtualenv_path }}"
|
|
|
|
wait_for_resources_python_upper_constraints_url: >-
|
|
|
|
{{ python_upper_constraints_url }}
|
|
|
|
# Only attempt to wait for resources when the placement service is running
|
|
|
|
when: service_list_output.stdout | from_json | selectattr('Type', 'equalto', 'placement') | list | length >= 1
|