|
9 | 9 | ansible_python_interpreter: "{{ cluster_venv }}/bin/python"
|
10 | 10 | when: cluster_venv != None
|
11 | 11 |
|
12 |
| -- name: Orchestrate OpenStack infrastructure |
13 |
| - register: cluster_stack |
14 |
| - os_stack: |
15 |
| - auth_type: "{{ cluster_auth_type or omit }}" |
16 |
| - auth: "{{ cluster_auth or omit }}" |
17 |
| - cloud: "{{ cluster_cloud or omit }}" |
18 |
| - name: "{{ cluster_name }}" |
19 |
| - state: "{{ cluster_state }}" |
20 |
| - environment: "{{ cluster_environment }}" |
21 |
| - template: "{{ cluster_template }}" |
22 |
| - parameters: "{{ cluster_params }}" |
| 12 | +# Case 1: we are modifying the cluster. |
| 13 | +- block: |
| 14 | + - name: Orchestrate OpenStack infrastructure |
| 15 | + register: cluster_stack |
| 16 | + os_stack: |
| 17 | + auth_type: "{{ cluster_auth_type or omit }}" |
| 18 | + auth: "{{ cluster_auth or omit }}" |
| 19 | + cloud: "{{ cluster_cloud or omit }}" |
| 20 | + name: "{{ cluster_name }}" |
| 21 | + state: "{{ cluster_state }}" |
| 22 | + environment: "{{ cluster_environment }}" |
| 23 | + template: "{{ cluster_template }}" |
| 24 | + parameters: "{{ cluster_params }}" |
| 25 | + |
| 26 | + - name: Extract node groups |
| 27 | + set_fact: |
| 28 | + cluster_group: "{{ cluster_stack.stack.outputs | selectattr('output_key', 'equalto', 'cluster_group') | first }}" |
| 29 | + when: cluster_state != 'query' |
| 30 | + |
| 31 | +# Case 2: we are performing a read-only query of the cluster configuration. |
| 32 | +# Read the stack's outputs via the API. |
| 33 | +- block: |
| 34 | + - name: Gather OpenStack infrastructure information |
| 35 | + command: openstack stack output show {{ cluster_name }} cluster_group -f json |
| 36 | + register: stack_output |
| 37 | + |
| 38 | + - name: Extract node groups |
| 39 | + set_fact: |
| 40 | + cluster_group: "{{ stack_output.stdout | from_json }}" |
| 41 | + when: cluster_state == 'query' |
23 | 42 |
|
24 | 43 | - name: Reset the python interpreter
|
25 | 44 | set_fact:
|
|
37 | 56 | src: cluster_inventory.j2
|
38 | 57 | dest: "{{ cluster_inventory }}"
|
39 | 58 |
|
40 |
| - - name: Extract node groups |
41 |
| - set_fact: |
42 |
| - cluster_group: "{{ cluster_stack.stack.outputs | selectattr('output_key', 'equalto', 'cluster_group') | first }}" |
43 |
| - |
44 | 59 | - name: Extract node objects
|
45 | 60 | set_fact:
|
46 | 61 | cluster_nodes: "{{ cluster_group.output_value | map(attribute='nodes') | list }}"
|
|
54 | 69 | timeout: "{{ cluster_ssh_timeout }}"
|
55 | 70 | with_flattened:
|
56 | 71 | - "{{ cluster_nodes }}"
|
57 |
| - when: cluster_state == 'present' |
| 72 | + when: cluster_state != 'absent' |
0 commit comments