From 5706c1b2126cfb59991cb9538c91b7b6982283af Mon Sep 17 00:00:00 2001 From: Carl-Rainer Weller Date: Wed, 7 Aug 2024 15:40:20 +0200 Subject: [PATCH 1/3] my solution to issue#25 --- roles/sap_control/tasks/main.yml | 7 ++++--- roles/sap_control/tasks/prepare.yml | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/roles/sap_control/tasks/main.yml b/roles/sap_control/tasks/main.yml index 81a3a68..2210742 100644 --- a/roles/sap_control/tasks/main.yml +++ b/roles/sap_control/tasks/main.yml @@ -87,12 +87,13 @@ # Get SAP Facts - name: Run sap_facts module to gather SAP facts community.sap_libs.sap_system_facts: - param: "{{ sap_facts_param }}" + # param: "{{ sap_facts_param }}" register: sap_facts_register -- name: Debug facts +- name: Debug result from sap_libs.sap_system_facts ansible.builtin.debug: - msg: "{{ sap_facts_register.sap_facts }}" + msg: "{{ sap_facts_register.ansible_facts.sap }}" + verbosity: 1 - name: pause for 10 Seconds ansible.builtin.pause: diff --git a/roles/sap_control/tasks/prepare.yml b/roles/sap_control/tasks/prepare.yml index 64f8f40..a15777f 100644 --- a/roles/sap_control/tasks/prepare.yml +++ b/roles/sap_control/tasks/prepare.yml @@ -13,9 +13,9 @@ vars: sap_control_execute_sid: "{{ item.SID }}" sap_control_execute_type: "{{ item.Type }}" - sap_control_execute_instance_nr: "{{ item.InstanceNumber }}" + sap_control_execute_instance_nr: "{{ item.NR }}" sap_control_execute_instance_type: "{{ item.InstanceType }}" ansible.builtin.include_tasks: "sapcontrol.yml" - loop: "{{ sap_facts_register.sap_facts }}" + loop: "{{ sap_facts_register.ansible_facts.sap }}" when: - - "item.Type == sap_type" + - "item.InstanceType | lower == sap_type | lower" From 8ee89932d821d57b4d7a6ac0150ef1aaff503103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hohwieler?= <108819130+jhohwieler@users.noreply.github.com> Date: Mon, 19 Aug 2024 09:47:30 +0200 Subject: [PATCH 2/3] sap_facts.sh - ps print only executable with path The output of "ps -ef" not also includes the command but also the process age and process arguments. Both can have digits in its string which may interfere when grepping for an instance number like 00 or 01. To fix this, let ps print only the executable with its path. Example: ps with default output - 2 lines match where only 1st line should match /usr/sap/A22/D01/exe/sapstartsrv pf=/usr/sap/A22/SYS/profile/A22_D01_sapa22u01 -D -u a22adm /usr/sap/A22/ASCS02/exe/sapstartsrv pf=/usr/sap/A22/SYS/profile/A22_ASCS02_sapa22u01 -D -u a22adm Example: ps with custom layout, only one line matches as expected /usr/sap/A22/D01/exe/sapstartsrv --- plugins/modules/sap_facts.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/sap_facts.sh b/plugins/modules/sap_facts.sh index 8706585..389e345 100755 --- a/plugins/modules/sap_facts.sh +++ b/plugins/modules/sap_facts.sh @@ -286,7 +286,7 @@ function check_sapstartsrv(){ # $3 - NR ## Count the number of sapstartsrv processes - SAPSTARTSRV=$(ps -ef | grep $2 | grep $3 | grep sapstartsrv | wc -l) + SAPSTARTSRV=$(ps -eo exe | grep $2 | grep $3 | grep sapstartsrv | wc -l) if [[ $SAPSTARTSRV = 0 ]]; then ## No sapstartsrv process running - attempt to start From 0a8c1bd26a1adcbb139bc953a9e33a9de2b92aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hohwieler?= Date: Tue, 20 Aug 2024 16:23:29 +0200 Subject: [PATCH 3/3] Replace ansible.builtin.pause with ansible.builtin.wait_for This fixes an issue when running with strategy free: > ERROR! The 'ansible.builtin.pause' module bypasses the host loop, which > is currently not supported in the free strategy and would instead > execute for every host in the inventory list. Furthermore, the documentation for ansible.builtin.pause states: To pause/wait/sleep per host, use the ansible.builtin.wait_for module. See https://docs.ansible.com/ansible/latest/collections/ansible/builtin/pause_module.html --- roles/sap_control/tasks/functions/restart_sapstartsrv.yml | 4 ++-- roles/sap_control/tasks/main.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/roles/sap_control/tasks/functions/restart_sapstartsrv.yml b/roles/sap_control/tasks/functions/restart_sapstartsrv.yml index 8ea6558..73165c1 100644 --- a/roles/sap_control/tasks/functions/restart_sapstartsrv.yml +++ b/roles/sap_control/tasks/functions/restart_sapstartsrv.yml @@ -33,5 +33,5 @@ register: sap_start_sapstartsrv - name: SAPstartsrv - Wait for 10 seconds for sapstartsrv to initialize - ansible.builtin.pause: - seconds: 10 + ansible.builtin.wait_for: + timeout: 10 diff --git a/roles/sap_control/tasks/main.yml b/roles/sap_control/tasks/main.yml index 81a3a68..a431124 100644 --- a/roles/sap_control/tasks/main.yml +++ b/roles/sap_control/tasks/main.yml @@ -95,8 +95,8 @@ msg: "{{ sap_facts_register.sap_facts }}" - name: pause for 10 Seconds - ansible.builtin.pause: - seconds: 10 + ansible.builtin.wait_for: + timeout: 10 # Debugging stuff - name: Display parameters for runtime