Skip to content

Commit

Permalink
Refactor SAP HANA Pacemaker tasks to improve package installation log…
Browse files Browse the repository at this point in the history
…ic and add conditional checks for SUSE and RHEL distributions
  • Loading branch information
hdamecharla committed Nov 12, 2024
1 parent 24c14c1 commit c8c6469
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
changed_when: false

- name: "5.5 HANA Pacemaker - Extract version components"
when: hdbversion.rc == 0
ansible.builtin.set_fact:
version_string: "{{ hdbversion.stdout | regex_search('version:\\s+([0-9.]+)', '\\1') | first }}"
when: hdbversion.rc == 0

- name: "5.5 HANA Pacemaker - Parse version numbers"
ansible.builtin.set_fact:
Expand All @@ -93,23 +93,22 @@
saphanaSR_angi_version: "{{ ansible_facts.packages['SAPHanaSR-angi'][0].version if 'SAPHanaSR-angi' in ansible_facts.packages else '0.0.0' }}"

- name: "5.5 HANA Pacemaker - Install SAPHanaSR package if not installed"
community.general.zypper:
name: "SAPHanaSR>=0.161.1_BF"
state: present
when:
- saphanaSR_version == '0.0.0'
- not use_hanasr_angi

- name: "5.5 HANA Pacemaker - Install SAPHanaSR-angi package if not installed"
community.general.zypper:
name: SAPHanaSR-angi
name: "SAPHanaSR>=0.161.1_BF"
state: present

- name: "5.5 HANA Pacemaker - Install SAPHanaSR-angi package if not installed"
when:
- saphanaSR_angi_version == '0.0.0'
- use_hanasr_angi
- distribution_full_id in ['sles_sap15.4', 'sles_sap15.5', 'sles_sap15.6']
community.general.zypper:
name: SAPHanaSR-angi
state: present

# old code left here for backwards comaptibility
- name: "5.5 HANA Pacemaker - Capture the Hana DB version"
ansible.builtin.set_fact:
hdb_version: "{{ hdbversion.stdout_lines.1.split().1 }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

# susChkSrv Python Hook Check
- name: "5.5 HANA Pacemaker - Validate susChkSrv Python hook requirements"
when: ansible_os_family | upper == 'SUSE'
ansible.builtin.assert:
that:
- hana_major_version >= min_hana_version
Expand All @@ -65,11 +66,14 @@
- Required: HANA 2.0 SPS 05 or higher (Current: {{ hana_major_version }}.0 SPS {{ hana_sps_level }})
- Required: SAPHanaSR {{ min_saphanaSR_version_suschk }} or higher (Current: {{ saphanaSR_version }})
register: suschk_hook_check
when: ansible_os_family | upper == 'SUSE'

# SAPHanaSR-angi Python Hook Check
# currently we do not have any version requirements for SAPHanaSR-angi
- name: "5.5 HANA Pacemaker - Validate SAPHanaSR-angi Python hook requirements"
when:
- ansible_os_family | upper == 'SUSE'
- distribution_full_id in ['sles_sap15.4', 'sles_sap15.5', 'sles_sap15.6']
- use_hanasr_angi
ansible.builtin.assert:
that:
- hana_major_version >= min_hana_major_version
Expand All @@ -82,17 +86,15 @@
- Required: SLES for SAP Applications 15 SP4, SP5, or SP6 (Current: {{ distribution_full_id }})
- Required: SAPHanaSR-angi, should be installed
register: angi_hook_check
when:
- ansible_os_family | upper == 'SUSE'
- distribution_full_id in ['sles_sap15.4', 'sles_sap15.5', 'sles_sap15.6']
- use_hanasr_angi


- name: "5.5 HANA Pacemaker - Can the SLES distribution be used with SAPHanaSR-angi"
ansible.builtin.set_fact:
is_certified_for_hanasr_angi: "{{ distribution_full_id in ['sles_sap15.4', 'sles_sap15.5', 'sles_sap15.6'] | default(false) }}"
when:
- ansible_os_family | upper == "SUSE"
- use_hanasr_angi
ansible.builtin.set_fact:
is_certified_for_hanasr_angi: "{{ distribution_full_id in ['sles_sap15.4', 'sles_sap15.5', 'sles_sap15.6'] | default(false) }}"


- name: HANA 2.0 only - Implement the classic Python system replication hook SAPHanaSR
when:
Expand Down Expand Up @@ -132,28 +134,29 @@
seconds: 120

- name: "5.5 HANA Pacemaker - copy SAPHanaSR.py (SUSE)"
when:
- ansible_os_family | upper == "SUSE"
- not my_hooks_stat.stat.exists
ansible.builtin.copy:
src: /usr/share/SAPHanaSR/SAPHanaSR.py
dest: /hana/shared/myHooks/
remote_src: true
owner: root
group: root # TODO - check the correct group once the python hook package is installed
mode: '0644'
when:
- ansible_os_family | upper == "SUSE"
- not my_hooks_stat.stat.exists


- name: "5.5 HANA Pacemaker - copy SAPHanaSR.py (RHEL)"
when:
- ansible_os_family | upper == "REDHAT"
- not my_hooks_stat.stat.exists
ansible.builtin.copy:
src: /usr/share/SAPHanaSR/srHook/SAPHanaSR.py
dest: /hana/shared/myHooks/
remote_src: true
owner: root
group: root # TODO - check the correct group once the python hook package is installed
mode: '0644'
when:
- ansible_os_family | upper == "REDHAT"
- not my_hooks_stat.stat.exists

- name: "5.5 HANA Pacemaker - Change ownership of the directory"
ansible.builtin.file:
Expand All @@ -164,6 +167,8 @@
group: sapsys

- name: "5.5 HANA Pacemaker - Adjust global.ini on each cluster node (RHEL)"
when:
- ansible_os_family | upper == "REDHAT"
ansible.builtin.blockinfile:
path: /hana/shared/{{ db_sid | upper }}/global/hdb/custom/config/global.ini
block: |
Expand All @@ -181,10 +186,11 @@
[trace]
ha_dr_saphanasr = info
ha_dr_chksrv = info
when:
- ansible_os_family | upper == "REDHAT"
- name: "5.5 HANA Pacemaker - Adjust global.ini on each cluster node (SLES)"
when:
- suschk_hook_check is success
- ansible_os_family | upper == "SUSE"
ansible.builtin.blockinfile:
path: /hana/shared/{{ db_sid | upper }}/global/hdb/custom/config/global.ini
block: |
Expand All @@ -201,27 +207,24 @@
[trace]
ha_dr_saphanasr = info
when:
- suschk_hook_check is success
- ansible_os_family | upper == "SUSE"
- name: "5.5 HANA Pacemaker - Create sudoers file 20-saphana for SLES"
when: ansible_os_family | upper == "SUSE"
ansible.builtin.template:
src: "20-saphana-suse.j2"
dest: "/etc/sudoers.d/20-saphana"
mode: "0440"
owner: root
group: root
when: ansible_os_family | upper == "SUSE"

- name: "5.5 HANA Pacemaker - Create sudoers file 20-saphana for RHEL"
when: ansible_os_family | upper == "REDHAT"
ansible.builtin.template:
src: "20-saphana-rhel.j2"
dest: "/etc/sudoers.d/20-saphana"
mode: "0440"
owner: root
group: root
when: ansible_os_family | upper == "REDHAT"

- name: "5.5 HANA Pacemaker - Start HANA System on both nodes"
become_user: "{{ db_sid | lower }}adm"
Expand All @@ -245,6 +248,7 @@
when: inventory_hostname == primary_instance_name
block:
- name: "5.5 HANA Pacemaker - Verify the hook Installation"
when: inventory_hostname == primary_instance_name
become_user: "{{ db_sid | lower }}adm"
become: true
ansible.builtin.shell: |
Expand All @@ -257,13 +261,14 @@
until: saphanasr_verification.stdout is search("SOK")
retries: 10
delay: 30
when: inventory_hostname == primary_instance_name

rescue:
- name: "5.5 HANA Pacemaker - [Rescue] - Pause to give HANA replication time to stabilize"
ansible.builtin.pause:
seconds: "{{ rescue_hsr_status_report_wait_in_s }}"

- name: "5.5 HANA Pacemaker - [Rescue] - Verify the hook Installation"
when: inventory_hostname == primary_instance_name
become_user: "{{ db_sid | lower }}adm"
become: true
ansible.builtin.shell: |
Expand All @@ -276,9 +281,10 @@
until: saphanasr_verification.stdout is search("SOK")
retries: 10
delay: 30
when: inventory_hostname == primary_instance_name


- name: "5.5 HANA Pacemaker - Log that the hook script is working as expected"
when: inventory_hostname == primary_instance_name
block:

- name: "5.5 HANA Pacemaker - Debug (saphanasr_verification)"
Expand All @@ -300,7 +306,7 @@
that:
- "'SFAIL' != hsr_hook_verify_result"
fail_msg: "Unable to determine if HSR Hook is working"
when: inventory_hostname == primary_instance_name
success_msg: "HSR Hook is working as expected"

- name: "5.5 HANA Pacemaker - Verify the hook Installation"
ansible.builtin.debug:
Expand Down Expand Up @@ -404,13 +410,14 @@

rescue:
- name: "5.5 HANA Pacemaker - Handle HANA System start failure"
when: hana_system_started.rc not in [0, 3]
ansible.builtin.fail:
msg: |
Failed to start SAP system:
Return code: {{ hana_system_started.rc }}
stdout: {{ hana_system_started.stdout }}
stderr: {{ hana_system_started.stderr }}
when: hana_system_started.rc not in [0, 3]
- name: "5.5 HANA Pacemaker - Start HANA Database"
ansible.builtin.import_tasks: ../../../roles-misc/0.4-helpers/tasks/04.01-start_hana.yml
Expand Down

0 comments on commit c8c6469

Please sign in to comment.