Skip to content

Commit b74145a

Browse files
authored
Merge pull request stackhpc#18 from stackhpc/group-resources-wip
Group resources wip
2 parents 0a4b052 + 5d3e729 commit b74145a

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

tasks/main.yml

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,48 @@
4646
when: cluster_venv != None
4747

4848
- 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+
4991
- name: Ensure cluster inventory directory exists
5092
file:
5193
path: "{{ cluster_inventory | dirname }}"
@@ -56,17 +98,14 @@
5698
src: cluster_inventory.j2
5799
dest: "{{ cluster_inventory }}"
58100

59-
- name: Extract node objects
60-
set_fact:
61-
cluster_nodes: "{{ cluster_group.output_value | map(attribute='nodes') | list }}"
62-
63101
- name: Wait for SSH access to the nodes
64-
local_action:
65-
module: wait_for
102+
wait_for:
66103
host: "{{ item.ip }}"
67104
port: 22
68105
state: started
69106
timeout: "{{ cluster_ssh_timeout }}"
70-
with_flattened:
107+
with_items:
71108
- "{{ cluster_nodes }}"
109+
delegate_to: "{{ cluster_gw_ip | default('localhost') }}"
110+
72111
when: cluster_state != 'absent'

templates/cluster_inventory.j2

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@ cluster
1616
{% for group_data in cluster_group.output_value %}
1717
[{{ cluster_name }}_{{ group_data.group }}]
1818
{% for node_data in group_data.nodes %}
19-
{{ node_data.name }} ansible_host={{ node_data.ip }} ansible_user={{ cluster_params.cluster_groups | selectattr("name", "equalto", group_data.group) | map(attribute='user') | join }}
19+
{{ node_data.name }} ansible_host={{ node_data.ip }}
2020
{% endfor %}
2121

22+
[{{ cluster_name }}_{{ group_data.group }}:vars]
23+
ansible_user={{ cluster_params.cluster_groups | selectattr("name", "equalto", group_data.group) | map(attribute='user') | join }}
24+
{% if cluster_gw_group is defined %}
25+
{% if cluster_gw_group != group_data.group %}
26+
ansible_ssh_common_args='-o ProxyJump={{ cluster_gw_user }}@{{ cluster_gw_ip }}'
27+
{% endif %}
28+
{% endif %}
29+
2230
{% endfor %}
2331
# Specific roles for cluster deployment assignments
2432
{% for role in cluster_roles %}

0 commit comments

Comments
 (0)