Skip to content

Commit 226275f

Browse files
authored
Align gcp and aws boostrap tasks (#458)
Align variable names across these two very similar files. Add pacemaker and corosync service logs collections.
1 parent 9a72899 commit 226275f

3 files changed

Lines changed: 54 additions & 32 deletions

File tree

ansible/playbooks/sap-hana-cluster.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
name: pacemaker
3434
state: started
3535
enabled: true
36+
register: pacemaker_start_result
37+
ignore_errors: true
3638

3739
# When the stonith device is changed the file /var/lib/sbd is changed
3840
- name: Write stonith status file

ansible/playbooks/tasks/aws-cluster-bootstrap.yaml

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,30 @@
158158
ansible.builtin.set_fact:
159159
pacemaker_is_running: "{{ ansible_facts.services['pacemaker.service'].state | default('') == 'running' }}"
160160

161-
- name: Collect pacemaker diagnostics on failure
162-
ansible.builtin.command: "{{ item }}" # noqa command-instead-of-module
163-
loop:
164-
- systemctl status pacemaker.service --no-pager -l
165-
- journalctl --no-pager -u pacemaker --lines=50
166-
register: pacemaker_diag
161+
- name: Collect cluster diagnostics on failure
162+
ansible.builtin.command: "{{ item.1 | format(item.0) }}" # noqa command-instead-of-module
163+
loop: "{{ services | product(diag_commands) | list }}"
164+
loop_control:
165+
label: "{{ item.1 | format(item.0) }}"
166+
vars:
167+
services:
168+
- pacemaker
169+
- corosync
170+
diag_commands:
171+
- "systemctl status %s.service --no-pager -l"
172+
- "systemctl list-dependencies %s.service"
173+
- "journalctl --no-pager -u %s --lines=50"
174+
register: cluster_diag
167175
failed_when: false
168176
changed_when: false
169177
when: not pacemaker_is_running | bool
170178

171-
- name: Display pacemaker diagnostics
179+
- name: Display cluster diagnostics
172180
ansible.builtin.debug:
173-
msg: "{{ item.item }}:\n{{ item.stdout }}"
174-
loop: "{{ pacemaker_diag.results }}"
181+
msg: "{{ item.item.1 | format(item.item.0) }}:\n{{ item.stdout }}"
182+
loop: "{{ cluster_diag.results }}"
175183
loop_control:
176-
label: "{{ item.item }}"
184+
label: "{{ item.item.1 | format(item.item.0) }}"
177185
when: not pacemaker_is_running | bool
178186

179187
- name: Fail if pacemaker is not running
@@ -323,8 +331,8 @@
323331
crm configure property
324332
$id="cib-bootstrap-options"
325333
stonith-timeout=600s
326-
register: set_stonith_timeout_aws_result
327-
changed_when: set_stonith_timeout_aws_result.rc == 0
334+
register: set_stonith_timeout_native_result
335+
changed_when: set_stonith_timeout_native_result.rc == 0
328336
when:
329337
- stonith_timeout != '600s'
330338
- is_primary

ansible/playbooks/tasks/gcp-cluster-bootstrap.yaml

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,30 @@
139139
ansible.builtin.set_fact:
140140
pacemaker_is_running: "{{ ansible_facts.services['pacemaker.service'].state | default('') == 'running' }}"
141141

142-
- name: Collect pacemaker diagnostics on failure
143-
ansible.builtin.command: "{{ item }}" # noqa command-instead-of-module
144-
loop:
145-
- systemctl status pacemaker.service --no-pager -l
146-
- journalctl --no-pager -u pacemaker --lines=50
147-
register: pacemaker_diag
142+
- name: Collect cluster diagnostics on failure
143+
ansible.builtin.command: "{{ item.1 | format(item.0) }}" # noqa command-instead-of-module
144+
loop: "{{ services | product(diag_commands) | list }}"
145+
loop_control:
146+
label: "{{ item.1 | format(item.0) }}"
147+
vars:
148+
services:
149+
- pacemaker
150+
- corosync
151+
diag_commands:
152+
- "systemctl status %s.service --no-pager -l"
153+
- "systemctl list-dependencies %s.service"
154+
- "journalctl --no-pager -u %s --lines=50"
155+
register: cluster_diag
148156
failed_when: false
149157
changed_when: false
150158
when: not pacemaker_is_running | bool
151159

152-
- name: Display pacemaker diagnostics
160+
- name: Display cluster diagnostics
153161
ansible.builtin.debug:
154-
msg: "{{ item.item }}:\n{{ item.stdout }}"
155-
loop: "{{ pacemaker_diag.results }}"
162+
msg: "{{ item.item.1 | format(item.item.0) }}:\n{{ item.stdout }}"
163+
loop: "{{ cluster_diag.results }}"
156164
loop_control:
157-
label: "{{ item.item }}"
165+
label: "{{ item.item.1 | format(item.item.0) }}"
158166
when: not pacemaker_is_running | bool
159167

160168
- name: Fail if pacemaker is not running
@@ -247,6 +255,10 @@
247255
migration_threshold: "{{ (crm_rsc_options_show.stdout | regex_search('migration-threshold=([0-9]*)', '\\1'))[0] | default('false') }}"
248256
op_default_timeout: "{{ (crm_op_options_show.stdout | regex_search('timeout=([0-9]*)', '\\1'))[0] | default('false') }}"
249257

258+
# GCP native fencing requires per-node stonith primitives (fence_gce),
259+
# each referencing a specific hostname and zone.
260+
# AWS uses a single tag-based stonith resource (external/ec2) that
261+
# discovers instances automatically, so it does not need these variables.
250262
- name: Set primary and secondary hostnames
251263
ansible.builtin.set_fact:
252264
primary_hostname: "{{ groups['hana'][0] }}"
@@ -257,8 +269,8 @@
257269
- name: Enable SBD [sbd]
258270
ansible.builtin.command:
259271
cmd: crm configure primitive rsc_iscsi_sbd stonith:external/sbd
260-
register: reg_iscsi
261-
changed_when: reg_iscsi.rc == 0
272+
register: enable_sbd_result
273+
changed_when: enable_sbd_result.rc == 0
262274
when:
263275
- sbd_stonith | string | lower == 'false'
264276
- use_sbd | default(false) | bool
@@ -348,8 +360,8 @@
348360
crm configure property
349361
$id="cib-bootstrap-options"
350362
stonith-timeout=300s
351-
register: reg_st
352-
changed_when: reg_st.rc == 0
363+
register: set_stonith_timeout_native_result
364+
changed_when: set_stonith_timeout_native_result.rc == 0
353365
when:
354366
- stonith_timeout != '300s'
355367
- is_primary
@@ -361,8 +373,8 @@
361373
crm configure property
362374
$id="cib-bootstrap-options"
363375
stonith-enabled=true
364-
register: reg_se
365-
changed_when: reg_se.rc == 0
376+
register: enable_stonith_result
377+
changed_when: enable_stonith_result.rc == 0
366378
when:
367379
- stonith_enabled | string | lower != 'true'
368380
- is_primary
@@ -388,17 +400,17 @@
388400
crm configure rsc_defaults
389401
$id="rsc-options"
390402
migration-threshold=5000
391-
register: reg_mig_t
392-
changed_when: reg_mig_t.rc == 0
403+
register: set_migration_threshold_result
404+
changed_when: set_migration_threshold_result.rc == 0
393405
when:
394406
- migration_threshold != '5000'
395407
- is_primary
396408

397409
- name: Set op_defaults timeout
398410
ansible.builtin.command:
399411
cmd: crm configure op_defaults timeout=600
400-
register: reg_op_tim
401-
changed_when: reg_op_tim.rc == 0
412+
register: set_op_defaults_timeout_result
413+
changed_when: set_op_defaults_timeout_result.rc == 0
402414
when:
403415
- op_default_timeout != '600'
404416
- is_primary

0 commit comments

Comments
 (0)