|
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 | sum(attribute='nodes', start=[]) }}" |
62 |
| - |
63 |
| - - name: Prepare access via intermediate gateway |
64 |
| - block: |
65 |
| - - name: Extract gateway host |
66 |
| - set_fact: |
67 |
| - cluster_gw: "{{ cluster_nodes | selectattr('name', 'equalto', cluster_gw_host) | first }}" |
68 |
| - |
69 |
| - - name: Add gateway to dynamic inventory |
70 |
| - add_host: |
71 |
| - hostname: "{{ cluster_gw.ip }}" |
72 |
| - ansible_host: "{{ cluster_gw.ip }}" |
73 |
| - ansible_user: "stelfer" |
74 |
| - |
75 |
| - - name: Wait for direct SSH access to the designated gateway |
76 |
| - wait_for: |
77 |
| - host: "{{ cluster_gw.ip }}" |
78 |
| - port: 22 |
79 |
| - state: started |
80 |
| - timeout: "{{ cluster_ssh_timeout }}" |
81 |
| - |
82 |
| - - name: Scan for SSH keys |
83 |
| - command: ssh-keyscan {{ cluster_gw.ip }} |
84 |
| - register: keyscan_cluster_gw |
85 |
| - changed_when: False |
86 |
| - |
87 |
| - - name: Ensure gateway is in SSH known hosts |
88 |
| - blockinfile: |
89 |
| - block: | |
90 |
| - {% for key in keyscan_cluster_gw.stdout_lines %} |
91 |
| - {{ key }} |
92 |
| - {% endfor %} |
93 |
| - create: true |
94 |
| - marker: "# P3-APPLIANCES MANAGED BLOCK FOR {{ cluster_name }}" |
95 |
| - path: "~/.ssh/known_hosts" |
96 |
| - |
97 |
| - when: cluster_gw_host is defined |
98 |
| - |
99 | 101 | - name: Wait for SSH access to the nodes
|
100 | 102 | wait_for:
|
101 | 103 | host: "{{ item.ip }}"
|
|
104 | 106 | timeout: "{{ cluster_ssh_timeout }}"
|
105 | 107 | with_items:
|
106 | 108 | - "{{ cluster_nodes }}"
|
107 |
| - delegate_to: "{{ cluster_gw.ip | default('localhost') }}" |
| 109 | + delegate_to: "{{ cluster_gw_ip | default('localhost') }}" |
108 | 110 |
|
109 | 111 | when: cluster_state != 'absent'
|
0 commit comments