|
46 | 46 | when: cluster_venv != None
|
47 | 47 |
|
48 | 48 | - block:
|
| 49 | + - name: Extract node objects |
| 50 | + set_fact: |
| 51 | + cluster_nodes: "{{ cluster_group.output_value | sum(attribute='nodes', start=[]) }}" |
| 52 | + |
| 53 | + - name: Prepare access via intermediate gateway |
| 54 | + block: |
| 55 | + |
| 56 | + - name: Extract gateway host username and ip |
| 57 | + set_fact: |
| 58 | + cluster_gw_user: "{{ cluster_params.cluster_groups | selectattr('name', 'equalto', cluster_gw_group) | map(attribute='user') | join }}" |
| 59 | + cluster_gw_ip: "{{ (cluster_group.output_value | selectattr('group', 'equalto', cluster_gw_group) | first).nodes | map(attribute='ip') | first }}" |
| 60 | + |
| 61 | + - name: Add gateway to dynamic inventory |
| 62 | + add_host: |
| 63 | + hostname: "{{ cluster_gw_ip }}" |
| 64 | + ansible_host: "{{ cluster_gw_ip }}" |
| 65 | + ansible_user: "{{ cluster_gw_user }}" |
| 66 | + |
| 67 | + - name: Wait for direct SSH access to the designated gateway |
| 68 | + wait_for: |
| 69 | + host: "{{ cluster_gw_ip }}" |
| 70 | + port: 22 |
| 71 | + state: started |
| 72 | + timeout: "{{ cluster_ssh_timeout }}" |
| 73 | + |
| 74 | + - name: Scan for SSH keys |
| 75 | + command: ssh-keyscan {{ cluster_gw_ip }} |
| 76 | + register: keyscan_cluster_gw |
| 77 | + changed_when: False |
| 78 | + |
| 79 | + - name: Ensure gateway is in SSH known hosts |
| 80 | + blockinfile: |
| 81 | + block: | |
| 82 | + {% for key in keyscan_cluster_gw.stdout_lines %} |
| 83 | + {{ key }} |
| 84 | + {% endfor %} |
| 85 | + create: true |
| 86 | + marker: "# P3-APPLIANCES MANAGED BLOCK FOR {{ cluster_name }}" |
| 87 | + path: "~/.ssh/known_hosts" |
| 88 | + |
| 89 | + when: cluster_gw_group is defined |
| 90 | + |
49 | 91 | - name: Ensure cluster inventory directory exists
|
50 | 92 | file:
|
51 | 93 | path: "{{ cluster_inventory | dirname }}"
|
|
56 | 98 | src: cluster_inventory.j2
|
57 | 99 | dest: "{{ cluster_inventory }}"
|
58 | 100 |
|
59 |
| - - name: Extract node objects |
60 |
| - set_fact: |
61 |
| - cluster_nodes: "{{ cluster_group.output_value | map(attribute='nodes') | list }}" |
62 |
| - |
63 | 101 | - name: Wait for SSH access to the nodes
|
64 |
| - local_action: |
65 |
| - module: wait_for |
| 102 | + wait_for: |
66 | 103 | host: "{{ item.ip }}"
|
67 | 104 | port: 22
|
68 | 105 | state: started
|
69 | 106 | timeout: "{{ cluster_ssh_timeout }}"
|
70 |
| - with_flattened: |
| 107 | + with_items: |
71 | 108 | - "{{ cluster_nodes }}"
|
| 109 | + delegate_to: "{{ cluster_gw_ip | default('localhost') }}" |
| 110 | + |
72 | 111 | when: cluster_state != 'absent'
|
0 commit comments