Skip to content

Commit

Permalink
[TEAM-9968] Cluster deployment SAPHanaSR-angi package in Public Clouds (
Browse files Browse the repository at this point in the history
#307)

* Added support of the SAPHanaSR-angi package

* On Azure maintenance need to be turned off and added missing refresh of the facts

* Changing use_sap_hana_sr_angi to be read from the hana_vars, with proper default values

* HANA vars now sourced in  hana_preconfigure step

* Added the special SAPHanaSR-angi ofc module

* Indentation correction and typo in statement corrected, lint suggested corrections
  • Loading branch information
jankohoutek authored Jan 21, 2025
1 parent 0d639aa commit f09aa15
Show file tree
Hide file tree
Showing 6 changed files with 380 additions and 66 deletions.
22 changes: 15 additions & 7 deletions ansible/playbooks/sap-hana-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
become: true
become_user: root
vars:
# SAPHahaSR-angi
use_hana_sr_angi: "{{ use_sap_hana_sr_angi | default(false) }}"
# is_primary is selected so that tasks that need to be issued one are honoured correctly
is_primary: "{{ ansible_play_hosts[0] == inventory_hostname }}"
primary_hostname: "{{ ansible_play_hosts[0] }}"
Expand All @@ -19,6 +21,7 @@
# Define some names in a central place
rsc_socat: "rsc_socat_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}"
rsc_saphanactl: "rsc_SAPHanaCtl_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}"
ms_saphanactl: "msl_SAPHanaCtl_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}"


handlers:
Expand All @@ -40,6 +43,11 @@
- name: Load SAP HANA variables
ansible.builtin.include_vars: ./vars/hana_vars.yaml

- name: Re-set HANA Angi vars
ansible.builtin.set_fact:
ms_saphanactl: "mst_SAPHanaCtl_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}"
when:
- use_hana_sr_angi | bool

tasks:
- name: Base Cluster Configuration [azure]
Expand Down Expand Up @@ -81,19 +89,19 @@
cmd: >-
crm resource
refresh
msl_SAPHanaCtl_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}
when: is_primary

- name: Wait for cluster to settle
ansible.builtin.command:
cmd: cs_wait_for_idle -s 5
{{ ms_saphanactl }}
when: is_primary

- name: MS Resource Maintenance off
ansible.builtin.command:
cmd: >-
crm resource
maintenance
msl_SAPHanaCtl_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}
{{ ms_saphanactl }}
off
when: is_primary

- name: Wait for cluster to settle
ansible.builtin.command:
cmd: cs_wait_for_idle -s 5
when: is_primary
27 changes: 26 additions & 1 deletion ansible/playbooks/sap-hana-preconfigure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
remote_user: cloudadmin
become: true
become_user: root

pre_tasks:
- name: Source hana install variables
include_vars: ./vars/hana_vars.yaml

vars:
# SAPHahaSR-angi
use_hana_sr_angi: "{{ use_sap_hana_sr_angi | default(false) }}"
scale_out: false
use_sapconf: false
# Set use_reboottimeout default value to 1200,
Expand Down Expand Up @@ -36,7 +43,7 @@
state: present
replacefiles: true
when:
- ansible_facts['distribution_version'] == '15.1'
- ansible_facts['distribution_version'] == '15.1' and not use_hana_sr_angi | bool
register: result
until: result is succeeded
retries: 3
Expand Down Expand Up @@ -72,6 +79,24 @@
ansible.builtin.include_tasks: ./tasks/saptune.yaml
when: not use_sapconf | bool

# SAPHanaSR-angi -BEGIN-
- name: Ensure SAPHanaSR-doc and SAPHanaSR is NOT installed when angi is used
community.general.zypper:
name: "{{ item }}"
state: absent
loop:
- 'SAPHanaSR-doc'
- 'SAPHanaSR'
when: use_hana_sr_angi | bool

- name: Ensure SAPHanaSR-angi and supportutils plugin is installed when angi is used
community.general.zypper:
name: "{{ item }}"
state: present
loop:
- 'SAPHanaSR-angi'
- 'supportutils-plugin-ha-sap'
when: cluster_node and use_hana_sr_angi | bool

# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/reboot_module.html#parameters
# reboot_timeout Maximum seconds to wait for machine to reboot and respond to a test command. Default: 600
Expand Down
55 changes: 54 additions & 1 deletion ansible/playbooks/sap-hana-system-replication-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# https://documentation.suse.com/sbp/sap-15/html/SLES4SAP-hana-sr-guide-PerfOpt-15/index.html#cha.s4s.hana-hook
__hooks_dir: "/usr/share/SAPHanaSR/"
__sapcontrol: "/usr/sap/hostctrl/exe/sapcontrol"
# SAPHahaSR-angi
use_hana_sr_angi: "{{ use_sap_hana_sr_angi | default(false) }}"
__hooks_dir_angi: "/usr/share/SAPHanaSR-angi/"

handlers:
- name: Stop HANA
Expand Down Expand Up @@ -53,13 +56,23 @@
- 'sap_hana_install_sid'
- 'sap_hana_install_instance_number'

- name: Ensure hooks directory exists
- name: Ensure SAPHanaSR hooks directory exists
ansible.builtin.file:
path: "{{ __hooks_dir }}"
owner: "{{ sap_hana_install_sid | lower }}adm"
group: sapsys
state: directory
mode: '0775'
when: not use_hana_sr_angi | bool

- name: Ensure SAPHanaSR-angi hooks directory exists
ansible.builtin.file:
path: "{{ __hooks_dir_angi }}"
owner: "{{ sap_hana_install_sid | lower }}adm"
group: sapsys
state: directory
mode: '0775'
when: use_hana_sr_angi | bool

- name: Ensure System Replication hooks are installed and configured
notify:
Expand All @@ -81,6 +94,30 @@
- {'section': 'ha_dr_provider_SAPHanaSR', 'key': 'path', 'value': '{{ __hooks_dir }}'}
- {'section': 'ha_dr_provider_SAPHanaSR', 'key': 'execution_order', 'value': '1'}
- {'section': 'trace', 'key': 'ha_dr_saphanasr', 'value': 'info'}
when: not use_hana_sr_angi | bool

- name: Ensure ha_dr_provider_SAPHanaSR-angi section exists in global.ini
community.general.ini_file:
path: /usr/sap/{{ sap_hana_install_sid }}/SYS/global/hdb/custom/config/global.ini
section: "{{ item.section }}"
option: "{{ item.key }}"
value: "{{ item.value }}"
mode: '0644'
backup: true
loop:
- {'section': 'ha_dr_provider_sushanasr', 'key': 'provider', 'value': 'susHanaSR'}
- {'section': 'ha_dr_provider_sushanasr', 'key': 'path', 'value': '{{ __hooks_dir_angi }}'}
- {'section': 'ha_dr_provider_sushanasr', 'key': 'execution_order', 'value': '1'}
- {'section': 'ha_dr_provider_sustkover', 'key': 'provider', 'value': 'susTkOver'}
- {'section': 'ha_dr_provider_sustkover', 'key': 'path', 'value': '{{ __hooks_dir_angi }}'}
- {'section': 'ha_dr_provider_sustkover', 'key': 'execution_order', 'value': '2'}
- {'section': 'ha_dr_provider_suschksrv', 'key': 'provider', 'value': 'susChkSrv'}
- {'section': 'ha_dr_provider_suschksrv', 'key': 'path', 'value': '{{ __hooks_dir_angi }}'}
- {'section': 'ha_dr_provider_suschksrv', 'key': 'execution_order', 'value': '3'}
- {'section': 'trace', 'key': 'ha_dr_sushanasr', 'value': 'info'}
- {'section': 'trace', 'key': 'ha_dr_suschksrv', 'value': 'info'}
- {'section': 'trace', 'key': 'ha_dr_sustkover', 'value': 'info'}
when: use_hana_sr_angi | bool

- name: Add hooks into sudoers
ansible.builtin.lineinfile:
Expand All @@ -98,3 +135,19 @@
- {'regexp': '^Cmnd_Alias SOK_SITEB', 'line': 'Cmnd_Alias SOK_SITEB = /usr/sbin/crm_attribute -n hana_{{ sap_hana_install_sid | lower }}_site_srHook_{{ secondary_site }} -v SOK -t crm_config -s SAPHanaSR'}
- {'regexp': '^Cmnd_Alias SFAIL_SITEB', 'line': 'Cmnd_Alias SFAIL_SITEB = /usr/sbin/crm_attribute -n hana_{{ sap_hana_install_sid | lower }}_site_srHook_{{ secondary_site }} -v SFAIL -t crm_config -s SAPHanaSR'}
- {'regexp': '^{{ sap_hana_install_sid | lower }}adm ALL=(ALL) NOPASSWD', 'line': '{{ sap_hana_install_sid | lower }}adm ALL=(ALL) NOPASSWD: SOK_SITEA, SFAIL_SITEA, SOK_SITEB, SFAIL_SITEB'}
when: not use_hana_sr_angi | bool

- name: Add angi hooks into sudoers
ansible.builtin.lineinfile:
path: /etc/sudoers.d/HanaSystemReplication
state: present
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
validate: /usr/sbin/visudo -cf %s
create: true
mode: '0440'
loop:
- {'regexp': '^#ANSIBLE MANAGED DOCUMENT', 'line': '#ANSIBLE MANAGED DOCUMENT - no manual edits!'}
- {'regexp': '^{{ sap_hana_install_sid | lower }}adm ALL=(ALL) NOPASSWD', 'line': '{{ sap_hana_install_sid | lower }}adm ALL=(ALL) NOPASSWD: /usr/sbin/crm_attribute -n hana_{{ sap_hana_install_sid | lower }}_*'}
- {'regexp': '^{{ sap_hana_install_sid | lower }}adm ALL=(ALL) NOPASSWD', 'line': '{{ sap_hana_install_sid | lower }}adm ALL=(ALL) NOPASSWD: /usr/bin/SAPHanaSR-hookHelper --sid={{ sap_hana_install_sid | upper }} *'}
when: use_hana_sr_angi | bool
104 changes: 88 additions & 16 deletions ansible/playbooks/tasks/aws-cluster-hana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

- name: Set hana crm facts
ansible.builtin.set_fact:
crm_maintainence_mode: "{{ (crm_conf_hana_show.stdout | regex_search('maintenance-mode=([a-z]*)', '\\1'))[0] | default('unknown') }}"
crm_maintenance_mode: "{{ (crm_conf_hana_show.stdout | regex_search('maintenance-mode=([a-z]*)', '\\1'))[0] | default('unknown') }}"
stonith_timeout: "{{ crm_conf_hana_show.stdout | regex_search('stonith-timeout') }}" # this should be variable!
hana_resource: "{{ crm_conf_hana_show.stdout | regex_search('primitive rsc_SAPHanaCtl_') }}"
hana_clone: "{{ crm_conf_hana_show.stdout | regex_search('ms msl_SAPHanaCtl_') }}"
hana_clone: "{{ crm_conf_hana_show.stdout | regex_search('ms ms(.)_SAPHanaCtl_') }}"
hana_topology_resource: "{{ crm_conf_hana_show.stdout | regex_search('primitive rsc_SAPHanaTpg') }}"
hana_topology_clone: "{{ crm_conf_hana_show.stdout | regex_search('clone cln_SAPHanaTpg') }}"
hana_filesystem_resource: "{{ crm_conf_show.stdout | regex_search('primitive rsc_SAPHanaFil_') }}"
hana_filesystem_clone: "{{ crm_conf_show.stdout | regex_search('primitive cln_SAPHanaFil_') }}"
ip_resource: "{{ crm_conf_hana_show.stdout | regex_search('primitive rsc_ip_') }}"
ip_nc: "{{ crm_conf_hana_show.stdout | regex_search('primitive rsc_socat_') }}"
ip_grp: "{{ crm_conf_hana_show.stdout | regex_search('group g_ip_') }}"
Expand All @@ -22,10 +24,10 @@
when: is_primary
changed_when: false

- name: Ensure maintainence mode is active
- name: Ensure maintenance mode is active
ansible.builtin.command:
cmd: crm configure property maintenance-mode=true
when: crm_maintainence_mode is false or crm_maintainence_mode == 'unknown'
cmd: crm maintenance on
when: crm_maintenance_mode is false or crm_maintenance_mode == 'unknown'

- name: Create HANA topology resource
ansible.builtin.command:
Expand Down Expand Up @@ -62,7 +64,7 @@
ansible.builtin.command:
cmd: >-
crm configure primitive
rsc_SAPHanaCtl_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}
{{ rsc_saphanactl }}
ocf:suse:SAPHana
operations
$id="rsc_sap_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}-operations"
Expand All @@ -79,14 +81,40 @@
AUTOMATED_REGISTER="false"
when:
- hana_resource | length == 0
- not use_hana_sr_angi | bool
- is_primary

- name: Create HANA angi resource
ansible.builtin.command:
cmd: >-
crm configure primitive
{{ rsc_saphanactl }}
ocf:suse:SAPHanaController
op start interval="0" timeout="3600"
op stop interval="0" timeout="3600"
op promote interval="0" timeout="900"
op demote interval="0" timeout="320"
op monitor interval="60" role="Promoted" timeout="700"
op monitor interval="61" role="Unpromoted" timeout="700"
params
SID="{{ sap_hana_install_sid }}"
InstanceNumber="{{ sap_hana_install_instance_number }}"
PREFER_SITE_TAKEOVER="true"
DUPLICATE_PRIMARY_TIMEOUT="7200"
AUTOMATED_REGISTER="false"
meta
priority="100"
when:
- hana_resource | length == 0
- use_hana_sr_angi | bool
- is_primary

- name: Create HANA resource clone
ansible.builtin.command:
cmd: >-
crm configure ms
msl_SAPHanaCtl_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}
rsc_SAPHanaCtl_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}
{{ ms_saphanactl }}
{{ rsc_saphanactl }}
meta
notify="true"
clone-max="2"
Expand All @@ -97,14 +125,52 @@
- hana_clone | length == 0
- is_primary

- name: Create HANA Filesystem resource
ansible.builtin.command:
cmd: >-
crm configure primitive
rsc_SAPHanaFil_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}
ocf:suse:SAPHanaFilesystem
operations
$id="rsc_sap3_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}-operations"
op start interval="0" timeout="10"
op stop interval="0" timeout="20"
op monitor interval="120" timeout="120"
params
SID="{{ sap_hana_install_sid }}"
InstanceNumber="{{ sap_hana_install_instance_number }}"
ON_FAIL_ACTION="fence"
register: cmd_crm_chfr_output
changed_when: cmd_crm_chfr_output.rc != 0
when:
- use_hana_sr_angi | bool
- hana_filesystem_resource | length == 0

- name: Create HANA Filesystem clone
ansible.builtin.command:
cmd: >-
crm configure clone
cln_SAPHanaFil_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}
rsc_SAPHanaFil_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}
meta
clone-max="2"
clone-node-max="1"
target-role="Started"
interleave="true"
register: cmd_crm_chfc_output
changed_when: cmd_crm_chfc_output.rc != 0
when:
- use_hana_sr_angi | bool
- hana_filesystem_clone | length == 0

- name: Configure colocation
ansible.builtin.command:
cmd: >-
crm configure colocation
col_saphana_ip_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}
2000:
rsc_ip_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}:Started
msl_SAPHanaCtl_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}:Master
{{ ms_saphanactl }}
when: ip_colo | length == 0

- name: Configure order
Expand All @@ -114,22 +180,28 @@
ord_SAPHana
Optional:
cln_SAPHanaTpg_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}
msl_SAPHanaCtl_{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_instance_number }}
{{ ms_saphanactl }}
when: cluster_order | length == 0

# Get current maintainence state
# Get current maintenance state
- name: Refresh cluster status
ansible.builtin.command:
cmd: crm configure show
register: refreshed_crm_conf_show
changed_when: false

- name: Set crm facts
- name: Refresh crm facts
ansible.builtin.set_fact:
refreshed_crm_maintainence_mode: "{{ (refreshed_crm_conf_show.stdout | regex_search('maintenance-mode=([a-z]*)', '\\1'))[0] | default('unknown') }}"
refreshed_crm_maintenance_mode: "{{ (refreshed_crm_conf_show.stdout | regex_search('maintenance-mode=([a-z]*)', '\\1'))[0] | default('unknown') }}"
changed_when: false

- name: Ensure maintainence mode is disabled
- name: Ensure maintenance mode is disabled
ansible.builtin.command:
cmd: crm configure property maintenance-mode=false
when: refreshed_crm_maintainence_mode is true or refreshed_crm_maintainence_mode == 'unknown'
cmd: crm maintenance off
when: refreshed_crm_maintenance_mode is true or refreshed_crm_maintenance_mode == 'unknown'

# For debug purpose only
- name: Get cluster status at the end
ansible.builtin.command:
cmd: crm configure show
changed_when: false
Loading

0 comments on commit f09aa15

Please sign in to comment.