Skip to content

Commit fae01fd

Browse files
authored
Merge pull request #37 from oxya-dev/dev
sap_control: Add SAP System-level Function Support with Asynchronous Status Tracking
2 parents b177316 + 577b25c commit fae01fd

File tree

7 files changed

+164
-5
lines changed

7 files changed

+164
-5
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
minor_changes:
2+
- sap_control - add the mechanisms to handle asynchronous sapcontrol functions
3+
- sap_control - add UpdateSystem, RestartSystem, StartSystem, StopSystem functions

roles/sap_control/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This Ansible Role executes basic SAP administration tasks on Linux operating sys
77
This Ansible Role executes basic SAP administration tasks on Linux operating systems, including:
88
- Start/Stop/Restart of SAP HANA Database Server
99
- Start/Stop/Restart of SAP NetWeaver Application Server
10+
- Start/Stop/Restart/Update of SAP Netweaver System
1011
- Multiple Automatic discovery and Start/Stop/Restart of SAP HANA Database Server or SAP NetWeaver Application Server
1112

1213
## Example execution
@@ -62,7 +63,7 @@ Assumptions for executing this role include:
6263
| :--- |:--- | :--- |
6364
| `SID` | SAP system SID | no, only if you are targetting a single SAP system|
6465
| `nowait` | Default: `false` | no, use only when absolutely sure! This will bypass all waiting and ignore all necessary steps for a graceful stop / start|
65-
| `sap_control_function` | Function to execute:<br/><ul><li>`restart_all_sap`</li><li>`restart_all_nw`</li><li>`restart_all_hana`</li><li>`restart_sap_nw`</li><li>`restart_sap_hana`</li><li>`stop_all_sap`</li><li>`start_all_sap`</li><li>`stop_all_nw`</li><li>`start_all_nw`</li><li>`stop_all_hana`</li><li>`start_all_hana`</li><li>`stop_sap_nw`</li><li>`start_sap_nw`</li><li>`stop_sap_hana`</li><li>`start_sap_hana`</li></ul> | yes, only this is required to detect the Instance Number which is used with SAP Host Agent `sapcontrol` CLI<br/><br/><br/>_Note: Executions using `all` will automatically detect any System IDs and corresponding Instance Numbers_ |
66+
| `sap_control_function` | Function to execute:<br/><ul><li>`restart_all_sap`</li><li>`restart_all_nw`</li><li>`restart_all_hana`</li><li>`restart_sap_nw`</li><li>`restart_sap_hana`</li><li>`stop_all_sap`</li><li>`start_all_sap`</li><li>`stop_all_nw`</li><li>`start_all_nw`</li><li>`stop_all_hana`</li><li>`start_all_hana`</li><li>`stop_sap_nw`</li><li>`start_sap_nw`</li><li>`stop_sap_hana`</li><li>`start_sap_hana`</li><li>`restartsystem_all_nw`</li><li>`updatesystem_all_nw`</li><li>`startsystem_all_nw`</li><li>`stopsystem_all_nw`</li></ul> | yes, only this is required to detect the Instance Number which is used with SAP Host Agent `sapcontrol` CLI<br/><br/><br/>_Note: Executions using `all` will automatically detect any System IDs and corresponding Instance Numbers_ |
6667

6768
## Ansible Role workflow and structure
6869

roles/sap_control/defaults/main.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,41 @@ sap_control_name_header: "initial"
66
nowait: false
77
sap_control_start: "StartWait 180 2"
88
sap_control_stop: "StopWait 180 2"
9+
sap_control_startsystem: "StartSystem ALL 180" # function StartSystem waittimeout
10+
sap_control_stopsystem: "StopSystem ALL 180 480" # function StopSystem waittimeout softtimeout
11+
sap_control_restartsystem: "RestartSystem ALL 180 480" # function RestartSystem waittimeout softtimeout
12+
sap_control_updatesystem: "UpdateSystem 180 480 0" # function UpdateSystem waittimeout softtimeout force
13+
sap_control_waitforstopped: "WaitforStopped 180 2" # function WaitforStopped waittimeout delay
14+
sap_control_waitforstarted: "WaitforStarted 180 2" # function WaitforStarted waittimeout delay
15+
16+
# Parameters to handle async functions in sapcontrol_async.yml
17+
18+
sap_control_startsystem_waitforasync:
19+
test_function: "GetSystemInstanceList"
20+
retries: 60
21+
delay: 10
22+
until_false: 'GRAY\s*$|RED\s*$|YELLOW\s*$'
23+
until_true: 'GREEN\s*$'
24+
25+
sap_control_restartsystem_waitforasync:
26+
test_function: "GetSystemInstanceList"
27+
retries: 60
28+
delay: 10
29+
until_false: 'GRAY\s*$|RED\s*$|YELLOW\s*$'
30+
until_true: 'GREEN\s*$'
31+
32+
sap_control_stopsystem_waitforasync:
33+
test_function: "GetSystemInstanceList"
34+
retries: 60
35+
delay: 10
36+
until_false: 'GREEN\s*$|RED\s*$|YELLOW\s*$'
37+
until_true: 'GRAY\s*$'
38+
39+
sap_control_updatesystem_waitforasync:
40+
test_function: "GetSystemUpdateList"
41+
retries: 60
42+
delay: 10
43+
until_false: 'GRAY\s*$|RED\s*$|YELLOW\s*$|GREEN\s*$'
944

1045
# get_all_sap_sid_dir_nw: "/sapmnt"
1146
# get_all_sap_sid_dir_hana: "/hana/shared"
@@ -22,6 +57,14 @@ sap_control_instance_type_sortorder:
2257

2358
# Functions
2459
sap_control_functions_list:
60+
- restartsystem_all_nw
61+
- updatesystem_all_nw
62+
- startsystem_all_nw
63+
- stopsystem_all_nw
64+
- restartsystem_sap_nw
65+
- updatesystem_sap_nw
66+
- startsystem_sap_nw
67+
- stopsystem_sap_nw
2568
- restart_all_sap
2669
- stop_all_sap
2770
- start_all_sap
@@ -38,7 +81,33 @@ sap_control_functions_list:
3881
- stop_sap_hana
3982
- start_sap_hana
4083

84+
4185
# Functions flow
86+
restartsystem_all_nw_list:
87+
- sap_control_function_current: "nw_restartsystem"
88+
89+
startsystem_all_nw_list:
90+
- sap_control_function_current: "nw_startsystem"
91+
92+
stopsystem_all_nw_list:
93+
- sap_control_function_current: "nw_stopsystem"
94+
95+
updatesystem_all_nw_list:
96+
- sap_control_function_current: "nw_startsystem"
97+
- sap_control_function_current: "nw_updatesystem"
98+
99+
restartsystem_sap_nw_list:
100+
- sap_control_function_current: "nw_restartsystem"
101+
102+
updatesystem_sap_nw_list:
103+
- sap_control_function_current: "nw_updatesystem"
104+
105+
startsystem_sap_nw_list:
106+
- sap_control_function_current: "nw_startsystem"
107+
108+
stopsystem_sap_nw_list:
109+
- sap_control_function_current: "nw_stopsystem"
110+
42111
restart_all_sap_list:
43112
- sap_control_function_current: "nw_stop"
44113
- sap_control_function_current: "hana_stop"

roles/sap_control/tasks/main.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,18 @@
112112
ansible.builtin.debug:
113113
msg:
114114
- "Starting sap_control with the following parameters: "
115-
- "{{ sap_control_function }}"
116-
- "{{ sap_control_start }}"
117-
- "{{ sap_control_stop }}"
118-
- "{{ nowait }}"
115+
- "Function: {{ sap_control_function }}"
116+
- "Standard commands:"
117+
- " Start: {{ sap_control_start }}"
118+
- " Stop: {{ sap_control_stop }}"
119+
- "System commands (if applicable):"
120+
- " StartSystem: {{ sap_control_startsystem }}"
121+
- " StopSystem: {{ sap_control_stopsystem }}"
122+
- " RestartSystem: {{ sap_control_restartsystem }}"
123+
- " UpdateSystem: {{ sap_control_updatesystem }}"
124+
- " WaitforStopped: {{ sap_control_waitforstopped }}"
125+
- " WaitforStarted: {{ sap_control_waitforstarted }}"
126+
- "NoWait: {{ nowait }}"
119127

120128
# Start SAP Control
121129
- name: SAP Control

roles/sap_control/tasks/prepare.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,18 @@
3636
loop: "{{ sorted_sap_facts }}"
3737
when:
3838
- item.InstanceType | lower == sap_type | lower
39+
- not funct_type is match('.*system')
40+
41+
- name: Prepare - SAP Control for system functions
42+
vars:
43+
sap_control_execute_sid: "{{ item.SID }}"
44+
sap_control_execute_type: "{{ item.Type }}"
45+
sap_control_execute_instance_nr: "{{ item.NR }}"
46+
sap_control_execute_instance_type: "{{ item.InstanceType }}"
47+
ansible.builtin.include_tasks: "sapcontrol.yml"
48+
loop: "{{ sorted_sap_facts }}"
49+
when:
50+
- item.InstanceType | lower == sap_type | lower
51+
- funct_type is match('.*system')
52+
- item.TYPE | lower == 'ascs'
53+
or item.TYPE | lower == 'scs'

roles/sap_control/tasks/sapcontrol.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
register: sapcontrol_status
2323
failed_when: "'FAIL' in sapcontrol_status.stdout"
2424

25+
# Include sapcontrol async tasks
26+
- name: SAP {{ sap_control_name_header }} - Include async tasks
27+
vars:
28+
async_function_dict: "{{ vars['sap_control_' + funct_type + '_waitforasync'] }}"
29+
ansible.builtin.include_tasks: sapcontrol_async.yml
30+
when:
31+
- funct_type is match('.*system')
32+
2533
# Cleanipc
2634
- name: SAP {{ sap_control_name_header }} - Cleanipc
2735
ansible.builtin.include_tasks: functions/cleanipc.yml
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
- name: Wait for status to change if using restart or update
3+
when: funct_type is match('restart|update')
4+
block:
5+
- name: SAP {{ sap_control_name_header }} - Getting current system state
6+
ansible.builtin.shell: |
7+
source ~/.profile && sapcontrol -nr {{ passed_sap_nr }} -function {{ async_function_dict.test_function }}
8+
args:
9+
executable: /bin/bash
10+
become: true
11+
become_user: "{{ passed_sap_sid | lower }}adm"
12+
register: initial_test_function_result
13+
14+
- name: SAP {{ sap_control_name_header }} - Waiting for state to change before polling
15+
ansible.builtin.shell: |
16+
source ~/.profile && sapcontrol -nr {{ passed_sap_nr }} -function {{ async_function_dict.test_function }}
17+
args:
18+
executable: /bin/bash
19+
become: true
20+
become_user: "{{ passed_sap_sid | lower }}adm"
21+
register: wait_for_change_result
22+
retries: "{{ async_function_dict.retries | default(0) | int }}"
23+
delay: "{{ async_function_dict.delay | default(0) | int }}"
24+
until: >
25+
(wait_for_change_result.stdout | regex_findall('GREEN|YELLOW|GRAY|RED', multiline=True) | sort | join(','))
26+
!= (initial_test_function_result.stdout | regex_findall('GREEN|YELLOW|GRAY|RED', multiline=True) | sort | join(','))
27+
28+
- name: Pause for 20 Seconds to ensure the async function is started
29+
ansible.builtin.wait_for:
30+
timeout: 20
31+
32+
- name: SAP {{ sap_control_name_header }} - Checking if Async action is over by executing sapcontrol -nr {{ passed_sap_nr }} -function {{ async_function_dict.test_function }}
33+
ansible.builtin.shell: |
34+
source ~/.profile && sapcontrol -nr {{ passed_sap_nr }} -function {{ async_function_dict.test_function }}
35+
args:
36+
executable: /bin/bash
37+
become: true
38+
become_user: "{{ passed_sap_sid | lower }}adm"
39+
register: test_function_result
40+
retries: "{{ async_function_dict.retries | default(0) | int }}"
41+
delay: "{{ async_function_dict.delay | default(0) | int }}"
42+
until: >
43+
(async_function_dict.until_false is not defined
44+
or async_function_dict.until_false is defined
45+
and test_function_result.stdout | regex_search(async_function_dict.until_false, multiline=True) is none) and
46+
(async_function_dict.until_true is not defined or
47+
async_function_dict.until_true is defined
48+
and test_function_result.stdout | regex_search(async_function_dict.until_true, multiline=True) is not none)
49+
50+
- name: Debug stdout
51+
ansible.builtin.debug:
52+
msg: |
53+
Async function {{ async_function_dict.test_function }} for SAP SID {{ passed_sap_sid }}
54+
is done with result:
55+
{{ test_function_result.stdout }}

0 commit comments

Comments
 (0)