Skip to content

Commit 4dc0990

Browse files
committed
first commit towards issue #10
1 parent 9e2e1f4 commit 4dc0990

File tree

9 files changed

+281
-0
lines changed

9 files changed

+281
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
language: python
3+
python: "2.7"
4+
5+
# Use the new container infrastructure
6+
sudo: false
7+
8+
# Install ansible
9+
addons:
10+
apt:
11+
packages:
12+
- python-pip
13+
14+
install:
15+
# Install ansible
16+
- pip install ansible
17+
18+
# Check ansible version
19+
- ansible --version
20+
21+
# Create ansible.cfg with correct roles_path
22+
- printf '[defaults]\nroles_path=../' >ansible.cfg
23+
24+
script:
25+
# Basic role syntax check
26+
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
27+
28+
notifications:
29+
webhooks: https://galaxy.ansible.com/api/v1/notifications/

roles/sap_hana_sr_takeover/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
sap_hana_sr_takeover
2+
=====================
3+
4+
This role can be used to ensure, control and change SAP HANA System Replication
5+
6+
Requirements
7+
------------
8+
9+
This role requires SAP HANA System Replication configure, e.g. using the community.sap_install.sap_ha_install_hana_hsr role
10+
11+
Role Variables
12+
--------------
13+
14+
The follwoing variables are mandatory for running this role unless a default value is specified
15+
16+
| Variable Name | Description |
17+
|-------------------------------------|-----------------------------------------------------------|
18+
| sap_hana_sr_takeover_primary | Server to become the primary server |
19+
| sap_hana_sr_takeover_secondary | Server to register as secondary. The role can be run twice if more than one secondary is needed by looping over this variable |
20+
| sap_hana_sr_takeover_sitename | Name of the site being registered as secondary i |
21+
| sap_hana_sr_takeover_rep_mode | HANA replication mode (defaults to sync if not set) |
22+
| sap_hana_sr_takeover_hsr_oper_mode | HANA replication operation mpode (defaults to logreplay ) |
23+
| sap_hana_sid | HANA SID |
24+
| sap_hana_instance_number | HANA instance number
25+
26+
27+
Dependencies
28+
------------
29+
30+
`sap_hana_sid` and `sap_hana_instance_number` may already be set or used in other roles
31+
32+
Example Playbook
33+
----------------
34+
35+
If you have `hana1` and `hana2` configured for SAP HSR with SID RHE and instance 00 the following playbook
36+
ensures that `hana1` is the primary and `hana2` is the secondary
37+
38+
The role will fail if `hana1` is not configured for system replication (mode: none in `hdbnsutil -sr_state`).
39+
`hana1` needs to be primary or secondary in sync
40+
41+
The role will do nothing if `hana1` is the primary and `hana2` is the secondary.
42+
43+
It also ensures that the secondary HANA DB is started
44+
45+
```yaml
46+
- name: Ensure hana1 is primary
47+
hosts: hanas
48+
become: true
49+
tasks:
50+
- name: Switch to hana1
51+
include_role:
52+
name: community.sap_operations.sap_hana_sr_takeover
53+
vars:
54+
sap_hana_sr_takeover_primary: hana2
55+
sap_hana_sr_takeover_secondary: hana1
56+
sap_hana_sr_takeover_sitename: DC01
57+
sap_hana_sid: "RHE"
58+
sap_hana_instance_number: "00"
59+
```
60+
61+
62+
License
63+
-------
64+
Apache-2.0
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
# defaults file for hana_sr_takeover
3+
#
4+
# Define the new primary
5+
sap_hana_sr_takeover_primary:
6+
7+
# Machine to be the primary (can be run twice if more than one secondary)
8+
sap_hana_sr_takeover_secondary:
9+
# Name of the site being registered
10+
sap_hana_sr_takeover_sitename:
11+
12+
# Default replication method
13+
sap_hana_sr_takeover_rep_mode: sync
14+
sap_hana_sr_takeover_hsr_oper_mode: logreplay
15+
16+
# Common HANA Database parameter
17+
sap_hana_sid:
18+
sap_hana_instance_number:
19+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
galaxy_info:
2+
author: Markus Koch
3+
description: Ensure/Change HANA System Replication Primary and Secondary server
4+
company: redhat
5+
6+
# If the issue tracker for your role is not on github, uncomment the
7+
# next line and provide a value
8+
# issue_tracker_url: http://example.com/issue/tracker
9+
10+
license: Apache-2.0
11+
min_ansible_version: 2.9
12+
platforms:
13+
- name: EL
14+
versions: [ 7, 8, 9 ]
15+
- name: SLES
16+
versions: [ 15SP3 ]
17+
galaxy_tags: [ 'sap', 'rfc', 'pyrfc', 'rhel', 'redhat', 'sles', 'suse' ]
18+
19+
dependencies: []
20+
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
21+
# if you add dependencies to this list.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
# tasks file for sap_hana_sr_takeover
3+
#
4+
5+
- name: get hdb online state
6+
shell: |
7+
set -o pipefail
8+
source /usr/sap/{{ sap_hana_sid | upper }}/home/.sapenv.sh && \
9+
/usr/sap/{{ sap_hana_sid | upper }}/HDB{{ sap_hana_instance_number }}/exe/hdbnsutil \
10+
-sr_state | awk '($1 == "online:") {print $2}'
11+
args:
12+
executable: /bin/bash
13+
become: true
14+
become_user: "{{ sap_hana_sid | lower }}adm"
15+
changed_when: false
16+
register: register_sap_hana_sr_takeover_online
17+
18+
# returns: none, primary or replication method (on secondary)
19+
- name: get mode of system
20+
shell: |
21+
set -o pipefail
22+
source /usr/sap/{{ sap_hana_sid | upper }}/home/.sapenv.sh && \
23+
/usr/sap/{{ sap_hana_sid | upper }}/HDB{{ sap_hana_instance_number }}/exe/hdbnsutil \
24+
-sr_state | awk '($1 == "mode:") {print $2}'
25+
args:
26+
executable: /bin/bash
27+
become: true
28+
become_user: "{{ sap_hana_sid | lower }}adm"
29+
changed_when: false
30+
register: register_sap_hana_sr_takeover_mode
31+
32+
##
33+
# enable the right primary
34+
#
35+
- name: Fail, when planned primary cannot take over (no hsr configured)
36+
fail:
37+
msg: "This system is not part of HANA SR."
38+
when:
39+
- ansible_hostname == sap_hana_sr_takeover_primary
40+
- register_sap_hana_sr_takeover_mode.stdout == "none"
41+
42+
- name: make 'sap_hana_sr_takeover_primary' the new primary
43+
shell: |
44+
source /usr/sap/{{ sap_hana_sid | upper }}/home/.sapenv.sh && \
45+
/usr/sap/{{ sap_hana_sid | upper }}/HDB{{ sap_hana_instance_number }}/exe/hdbnsutil \
46+
-sr_takeover
47+
args:
48+
executable: /bin/bash
49+
become: true
50+
become_user: "{{ sap_hana_sid | lower }}adm"
51+
when:
52+
- ansible_hostname == sap_hana_sr_takeover_primary
53+
- register_sap_hana_sr_takeover_mode.stdout != "primary"
54+
55+
56+
###
57+
# register the secondary
58+
#
59+
- name: register 'sap_hana_sr_takeover_secondary' to the new primary
60+
block:
61+
- name: Ensure HDB on 'sap_hana_sr_takeover_secondary' is stopped
62+
shell: |
63+
source /usr/sap/{{ sap_hana_sid | upper }}/home/.sapenv.sh && \
64+
/usr/sap/{{ sap_hana_sid | upper }}/HDB{{ sap_hana_instance_number }}/HDB stop
65+
args:
66+
executable: /bin/bash
67+
when:
68+
- register_sap_hana_sr_takeover_online.stdout == 'true'
69+
70+
- name: Register 'sap_hana_sr_takeover_secondary' to the primary
71+
shell: |
72+
source /usr/sap/{{ sap_hana_sid | upper }}/home/.sapenv.sh && \
73+
/usr/sap/{{ sap_hana_sid | upper }}/HDB{{ sap_hana_instance_number }}/exe/hdbnsutil \
74+
-sr_register \
75+
--name="{{ sap_hana_sr_takeover_sitename }}" \
76+
--remoteHost={{ sap_hana_sr_takeover_primary }} \
77+
--remoteInstance={{ sap_hana_instance_number }} \
78+
--replicationMode={{ sap_hana_sr_takeover_rep_mode }} \
79+
--operationMode={{ sap_hana_sr_takeover_hsr_oper_mode }}
80+
args:
81+
executable: /bin/bash
82+
83+
become: true
84+
become_user: "{{ sap_hana_sid | lower }}adm"
85+
when:
86+
- ansible_hostname == sap_hana_sr_takeover_secondary
87+
- register_sap_hana_sr_takeover_mode.stdout != sap_hana_sr_takeover_rep_mode
88+
89+
## Check Online state and start HDB
90+
- name: get hdb online state
91+
shell: |
92+
set -o pipefail
93+
source /usr/sap/{{ sap_hana_sid | upper }}/home/.sapenv.sh && \
94+
/usr/sap/{{ sap_hana_sid | upper }}/HDB{{ sap_hana_instance_number }}/exe/hdbnsutil \
95+
-sr_state | awk '($1 == "online:") {print $2}'
96+
args:
97+
executable: /bin/bash
98+
become: true
99+
become_user: "{{ sap_hana_sid | lower }}adm"
100+
changed_when: false
101+
register: register_sap_hana_sr_takeover_online
102+
103+
- name: Ensure HDB is running
104+
shell: |
105+
source /usr/sap/{{ sap_hana_sid | upper }}/home/.sapenv.sh && \
106+
/usr/sap/{{ sap_hana_sid | upper }}/HDB{{ sap_hana_instance_number }}/HDB start
107+
args:
108+
executable: /bin/bash
109+
become: true
110+
become_user: "{{ sap_hana_sid | lower }}adm"
111+
when:
112+
- register_sap_hana_sr_takeover_online.stdout == 'false'
113+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
localhost
2+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
- name: Ensure hana1 is primary
2+
hosts: hanas
3+
become: true
4+
tasks:
5+
- name: Switch to hana1
6+
include_role:
7+
name: community.sap_install.sap_hana_sr_takeover
8+
vars:
9+
sap_hana_sr_takeover_primary: hana1
10+
sap_hana_sr_takeover_secondary: hana2
11+
sap_hana_sr_takeover_sitename: DC02
12+
sap_hana_sid: "RHE"
13+
sap_hana_instance_number: "00"
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
- name: Ensure hana2 is primary
2+
hosts: hanas
3+
become: true
4+
tasks:
5+
- name: Switch to hana2
6+
include_role:
7+
name: community.sap_install.sap_hana_sr_takeover
8+
vars:
9+
sap_hana_sr_takeover_primary: hana2
10+
sap_hana_sr_takeover_secondary: hana1
11+
sap_hana_sr_takeover_sitename: DC01
12+
sap_hana_sid: "RHE"
13+
sap_hana_instance_number: "00"
14+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- hosts: localhost
3+
remote_user: root
4+
roles:
5+
- hana_sr_takeover

0 commit comments

Comments
 (0)