community.sap_operations icon indicating copy to clipboard operation
community.sap_operations copied to clipboard

sap_control role can't call sap_system_facts module

Open ge87sik opened this issue 1 year ago • 5 comments

Hello everyone,

I've encountered an issue when trying to use the sap_operations.sap_control role (with sap_control_function set to 'stop_all_nw').

code_snippet

When running the playbook i get the following error message:

nw_restart_error

From what I understand the role is trying to call the sap_system_facts module with a parameter named 'param', but sap_system_facts doesn't accept any parameters. I've tried removing the offending line (l. 90) and calling the module without any parameters but then the sap_facts_register variable has no entry 'sap_facts'. Am I doing something wrong or is there an issue in the code?

Greetings Manuel

ge87sik avatar Apr 25 '24 09:04 ge87sik

Hi @ge87sik I've gone through the code and there is definitely a problem in https://github.com/sap-linuxlab/community.sap_operations/blob/e247f47e7172c7f9e48c2bc87ea466b7a4ce1e47/roles/sap_control/tasks/main.yml#L89

The problem came from the fact that the module sap_libs.sap_system_facts doesn't take any options with it so the param is an element no known by the task. You can see it here: https://github.com/sap-linuxlab/community.sap_libs/blob/7d8bc0f11c2e1f58da73710e7925f456d011ec0c/plugins/modules/sap_system_facts.py

Regarding the no entry sap_facts the problem came by the fact that sap_facts_register return ansible_facts and not sap_facts.

For now just try to replace sap_facts with ansible_facts and copy-paste the results here, I'll reach out the other developers to understand what is the correction that need to be done here.

Thanks for reporting this 🥇

Wabri avatar May 02 '24 13:05 Wabri

Just to add to this. Even when the parameters are removed from line 90 to allow community.sap_libs.sap_system_facts to work, the role fails further down as the returned values are not as expected by the rest of the code. community.sap_libs.sap_system_facts is not compatible with this role, making it unuseable :(.. This was probably introduced by commit #bfd09a5 ? I will try to test the code as it was before to see if it works.

rob0d avatar Jun 05 '24 16:06 rob0d

Thanks @rob0d we have already started an internal discussion about the sap_libs and how to handle the maintenance.

Wabri avatar Jun 12 '24 08:06 Wabri

This is a way to stop all SAP ABAP systems using sap.sap_operations collection See https://docs.galaxy.saponrhel.org/ https://galaxy.ansible.com/ui/repo/published/sap/sap_operations/

- name: Stop all ABAP instances on the host
   hosts: <hostname>
   gather_facts: false
   become: true
   become_user: root
   tasks: 
     - name: Get all instances on the host
        sap.sap_operations.host_info
        register: host_info

     - name: Stop all ABAP instances on the host
        sap.sap_operations.system:
           name: ABAP
           state: stopped
           instance_number: "{{ instance_number }}"
         loop: "{{ host_info.instances }}"
         vars:
             instance_number: "{{ item.mSystemNumber }}"

I just types this playbook, please use with caution, GPL3.0-only license and warranty.

python-suds package have to be installed on the host you want to run these modules against (if this is a RHEL system). Any other ways to install suds python package should also work.

Hope that helps

kksat avatar Jun 12 '24 08:06 kksat

Hi all, I just suffered the same issue and figured out that with some minor changes on the main.yml and prepare.yml it started to work.

roles/sap_control/tasks/prepare.yml

- name: SAP Control
  vars:
    sap_control_execute_sid: "{{ item.SID }}"
    sap_control_execute_type: "{{ item.Type }}"
    sap_control_execute_instance_nr: "{{ item.NR }}"
    sap_control_execute_instance_type: "{{ item.InstanceType }}"
  ansible.builtin.include_tasks: "sapcontrol.yml"
  loop: "{{ sap_facts_register.ansible_facts.sap }}"
  when:
    - "item.InstanceType | lower == sap_type | lower"

Just changed following:

  • the loop to use the dict as it is given by sap_libs module
  • the when condition to use the result from InstanceType instead of Type and put both to lower case
  • in the vars change item.InstanceNumber to item.Nr

See the screenshots:

diff_main_yml main.yml

diff_prepare_yml prepare.yml

For my situation that worked.

Let me know what you think. Id' be glad if you consider to use my solution.

Cheers, Rainer

crweller avatar Aug 01 '24 16:08 crweller