Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sap_rfc: overhaul #21

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions roles/sap_control/tasks/functions/restart_sapstartsrv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Stop sapstartsrv
- name: SAPstartsrv - Stop sapstartsrv {{ passed_sap_sid }}-{{ passed_sap_nr }}
ansible.builtin.shell: |
source ~/.profile && cdexe; sapcontrol -nr {{ passed_sap_nr }} -function StopService {{ passed_sap_sid }}
source ~/.profile ; sapcontrol -nr {{ passed_sap_nr }} -function StopService {{ passed_sap_sid }}
args:
executable: /bin/bash
become: true
Expand All @@ -25,7 +25,7 @@
# Start sapstartsrv
- name: SAPstartsrv - Start sapstartsrv {{ passed_sap_sid }}-{{ passed_sap_nr }}
ansible.builtin.shell: |
source ~/.profile && cdexe; sapcontrol -nr {{ passed_sap_nr }} -function StartService {{ passed_sap_sid }}
source ~/.profile ; sapcontrol -nr {{ passed_sap_nr }} -function StartService {{ passed_sap_sid }}
args:
executable: /bin/bash
become: true
Expand Down
2 changes: 1 addition & 1 deletion roles/sap_control/tasks/functions/sapstartsrv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Check sapstartsrv
- name: SAPstartsrv - Check sapstartsrv
ansible.builtin.shell: |
source ~/.profile && cdexe; sapcontrol -nr {{ passed_sap_nr }} -function GetSystemInstanceList
source ~/.profile ; sapcontrol -nr {{ passed_sap_nr }} -function GetSystemInstanceList
args:
executable: /bin/bash
become: true
Expand Down
1 change: 0 additions & 1 deletion roles/sap_control/tasks/sapcontrol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
source ~/.profile && sapcontrol -nr {{ passed_sap_nr }} -function {{ vars['sap_control_' + funct_type] }}
args:
executable: /bin/bash
warn: false
become: true
become_user: "{{ passed_sap_sid | lower }}adm"
register: sapcontrol_status
Expand Down
4 changes: 2 additions & 2 deletions roles/sap_profile_update/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
- name: SAP Profile Update - Get Instance Profile
ansible.builtin.shell: |
set -o pipefail
source ~/.profile && cdexe; sapcontrol -nr {{ sap_update_profile_instance_nr }} -function ParameterValue SAPPROFILE | grep profile
source ~/.profile ; sapcontrol -nr {{ sap_update_profile_instance_nr }} -function ParameterValue SAPPROFILE | grep profile
args:
executable: /bin/bash
become: true
become_user: "{{ sap_update_profile_sid | lower }}adm"
register: get_instance_profile

- name: setup facts
- name: SAP Profile Update - Setup facts
ansible.builtin.set_fact:
sap_update_profile_default_profile_file_path: "/sapmnt/{{ sap_update_profile_sid }}/profile/DEFAULT.PFL"
sap_update_profile_instance_profile_file_path: "{{ get_instance_profile.stdout }}"
Expand Down
10 changes: 5 additions & 5 deletions roles/sap_rfc/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# sap_rfc Ansible Role

The sap_rfc Ansible Role executes an SAP Remote Function Call (RFC), and performs setup as necessary ([`PyRFC`](https://github.com/SAP/PyRFC) open source by SAP, and [`SAP NWRFC SDK`](https://support.sap.com/en/product/connectors/nwrfcsdk.html)).
The sap_rfc Ansible Role executes an SAP Remote Function Call (RFC) from a server-side host with connectivity to the SAP System host/s, and performs setup as necessary ([`PyRFC`](https://github.com/SAP/PyRFC) open source by SAP, and [`SAP NWRFC SDK`](https://support.sap.com/en/product/connectors/nwrfcsdk.html)).

## Ansible Role Overview

The sap_rfc Ansible Role uses:
- the Ansible Module `sap_pyrfc` from the Ansible Collection `sap_libs`, which leverages the open-source [`PyRFC`](https://github.com/SAP/PyRFC) bindings for the proprietary [`SAP NWRFC SDK`](https://support.sap.com/en/product/connectors/nwrfcsdk.html).
- the Ansible Module `software_center_download` from the Ansible Collection `sap_launchpad`, which on first-run is used to download the [`SAP NWRFC SDK`](https://support.sap.com/en/product/connectors/nwrfcsdk.html).

Appropriate target SAP System user authorizations are required for the execute of the RFCs, and on first-run to obtain the [`SAP NWRFC SDK`](https://support.sap.com/en/product/connectors/nwrfcsdk.html) an SAP User ID with download privileges is required.
Appropriate target SAP System user authorizations are required for the execution of the RFCs, and on first-run to obtain the [`SAP NWRFC SDK`](https://support.sap.com/en/product/connectors/nwrfcsdk.html) an SAP User ID with download privileges is required.

The Ansible Role does not contain any system-altering RFCs by default when executed.

Expand Down Expand Up @@ -60,7 +60,7 @@ These RFC parameter data elements are mapped to the equivilant Python data type

`Ansible Task code example for data element:`
```yaml
target_parameters:
sap_rfc_target_parameters:
VAR: 'ECHO'
```

Expand All @@ -71,7 +71,7 @@ target_parameters:

`Ansible Task code example for ABAP Struture:`
```yaml
target_parameters:
sap_rfc_target_parameters:
IMPORTSTRUCT:
RFCFLOAT: 1.1
RFCCHAR1: 'A'
Expand All @@ -84,7 +84,7 @@ target_parameters:

`Ansible Task code example for ABAP Table:`
```yaml
target_parameters:
sap_rfc_target_parameters:
RFCTABLE:
- COLUMN0: SAP
- COLUMN1: 1.23
Expand Down
27 changes: 22 additions & 5 deletions roles/sap_rfc/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#pyrfc_first_run: true
---

#sap_nwrfc_sdk: nwrfc750P_10-70002752.zip
# sap_rfc_first_run_download_sap_user_id: ""
# sap_rfc_first_run_download_sap_user_password: ""
sap_rfc_first_run_download_path: /software

#target_connection:
#sap_rfc_target_connection:
# ashost: s4hana.poc.cloud
# sysid: TDT
# sysnr: "01"
Expand All @@ -15,7 +17,22 @@
# gwhost: gateway.poc.cloud
# ghserv: gateway.poc.cloud

target_function: STFC_CONNECTION
sap_rfc_target_function: STFC_CONNECTION

target_parameters:
sap_rfc_target_parameters:
REQUTEXT: "Hello SAP!"


# Override default for detected CPU Architecture (x86_64, ppc64le)
# Contains /usr/local/sap/nwrfcsdk/lib with libsapnwrfc.so , libicuuc.so.50 , libicudata.so.50 , libicui18n.so.50 , libsapucum.so
# Contains /usr/local/sap/nwrfcsdk/include with sapdecf.h , sapnwrfc.h , sapucrfc.h
# sap_rfc_first_run_download_nwrfc_sdk: "" # 7.50 x86_64 = nwrfc750P_12-70002752.zip , ppc64le = nwrfc750P_12-70002761.zip


# NOT USED:
# May cause errors with additional dependency libs not available in the LD_LIBRARY_PATH '/usr/local/sap/nwrfcsdk/lib'
# (e.g. libicuuc65.so, libicudata65.so, libicui18n65.so)
# Not recommended as per SAP Note 3384574 - SAP NW RFC SDK 7.50 hotfix installation
# Therefore Ansible Tasks code exists, but commented-out
# sap_rfc_first_run_download_sapcar: "" # x86_64 = SAPCAR_1115-70006178.EXE , ppc64le = SAPCAR_1115-70006238.EXE
# sap_rfc_first_run_download_nwrfc_sdk_patch: "" # 7.93 Backwards Compatible x86_64 = sapnwrfc_69-70007807.sar , ppc64le = sapnwrfc_69-70007832.sar
4 changes: 2 additions & 2 deletions roles/sap_rfc/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ galaxy_info:
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
collections:
- community.sap_libs
- community.sap_launchpad
- community.sap_libs
- community.sap_launchpad
49 changes: 39 additions & 10 deletions roles/sap_rfc/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
---
- name: Initial install of Python altinstall for PyRFC
ansible.builtin.include_tasks: python_pyrfc_init.yml
when: pyrfc_first_run | bool

- name: Discover Python altinstall for PyRFC
ansible.builtin.include_tasks: python_pyrfc_discover.yml
when: not pyrfc_first_run | bool
- name: Identify SAP NW RFC Library home directory
ansible.builtin.find:
paths: /usr/local/sap
recurse: true
file_type: directory
patterns: include
register: __sap_rfc_nwrfc_home

- name: Identify SAP NW RFC Library compiled shared library (libsapnwrfc.so)
ansible.builtin.find:
paths: /usr/local/sap/nwrfcsdk
recurse: true
file_type: file
patterns: libsapnwrfc.so
register: __sap_rfc_nwrfc_lib

- name: Identify Python virtual environment for sap_rfc Ansible Role
ansible.builtin.stat:
path: ~/env/pyrfc_env
register: __sap_rfc_python_virtual_env

- name: Set fact based on identified SAP NW RFC Library
ansible.builtin.set_fact:
__sap_rfc_first_run: "{{ true if ((__sap_rfc_nwrfc_home.files | length) == 0 or (__sap_rfc_nwrfc_lib.files | length) == 0) else false }}"

- name: Initial install of SAP NW RFC SDK Library
ansible.builtin.include_tasks: setup/nwrfcsdk_init.yml
when: __sap_rfc_first_run | bool

- name: Initial install of Python virtual environment for PyRFC
ansible.builtin.include_tasks: setup/python_init.yml
when: (__sap_rfc_first_run | bool) or (not __sap_rfc_python_virtual_env.stat.exists)

# Use Ansible Task block to call sap_pyrfc Ansible Module in the Ansible Collection for sap_libs
# RFC call using variables set by the Ansible Playbook when calling this Ansible Role
- name: Execute Ansible Module to call PyRFC using the virtualenv Python3
community.sap_libs.sap_pyrfc:
function: "{{ target_function }}"
parameters: "{{ target_parameters }}"
connection: "{{ target_connection }}"
environment:
SAPNWRFC_HOME: "{{ __sap_rfc_nwrfc_home.files[0].path | dirname }}"
LD_LIBRARY_PATH: "$LD_LIBRARY_PATH:$SAPNWRFC_HOME/lib"
vars:
ansible_python_interpreter: ~/env/pyrfc_env/bin/python3
community.sap_libs.sap_pyrfc:
function: "{{ sap_rfc_target_function }}"
parameters: "{{ sap_rfc_target_parameters }}"
connection: "{{ sap_rfc_target_connection }}"
1 change: 0 additions & 1 deletion roles/sap_rfc/tasks/python_pyrfc_discover.yml

This file was deleted.

70 changes: 0 additions & 70 deletions roles/sap_rfc/tasks/python_pyrfc_init.yml

This file was deleted.

116 changes: 116 additions & 0 deletions roles/sap_rfc/tasks/setup/nwrfcsdk_init.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---

- name: Set fact x86_64 sap_rfc_first_run_download_nwrfc_sdk
ansible.builtin.set_fact:
sap_rfc_first_run_download_nwrfc_sdk: "nwrfc750P_12-70002752.zip"
when: ansible_architecture == "x86_64"

- name: Set fact x86_64 sap_rfc_first_run_download_nwrfc_sdk
ansible.builtin.set_fact:
sap_rfc_first_run_download_nwrfc_sdk: "nwrfc750P_12-70002761.zip"
when: ansible_architecture == "ppc64le"

- name: Create directories if does not exist
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: "0755"
loop:
- "{{ sap_rfc_first_run_download_path }}"
- "/usr/local/sap"
- "/usr/local/sap/nwrfcsdk"
# - "/tmp/nwrfcsdk_patch_extract"

# Use task block to call Ansible Module in the Ansible Collection for sap_launchpad
- name: Execute Ansible Module to download SAP software
community.sap_launchpad.software_center_download:
suser_id: "{{ sap_rfc_first_run_download_sap_user_id }}"
suser_password: "{{ sap_rfc_first_run_download_sap_user_password }}"
softwarecenter_search_query: "{{ item }}"
dest: "{{ sap_rfc_first_run_download_path }}"
loop:
- "{{ sap_rfc_first_run_download_nwrfc_sdk }}"
# - "{{ sap_rfc_first_run_download_sapcar }}"
# - "{{ sap_rfc_first_run_download_nwrfc_sdk_patch }}"

- name: Discover zip of the SAP NWRFC SDK (7.5x Original) on target host
ansible.builtin.find:
paths: "{{ sap_rfc_first_run_download_path }}"
recurse: true
patterns: "nwrfc*.zip"
register: __sap_rfc_nwrfc_sdk_zip

- name: Extract zip of the SAP NWRFC SDK (7.5x) on target host
ansible.builtin.unarchive:
remote_src: true
src: "{{ __sap_rfc_nwrfc_sdk_zip.files[0].path }}"
dest: /usr/local/sap # ZIP contains nwrfcsdk subdirectory
when: __sap_rfc_nwrfc_sdk_zip.files | length > 0

# - name: Discover SAR of the SAP NWRFC SDK Patch on target host
# ansible.builtin.find:
# paths: "{{ sap_rfc_first_run_download_path }}"
# recurse: true
# patterns: "sapnwrfc_*.sar"
# register: __sap_rfc_nwrfc_sdk_sar

# - name: Discover SAPCAR on target host
# ansible.builtin.find:
# paths: "{{ sap_rfc_first_run_download_path }}"
# recurse: true
# patterns: "SAPCAR*"
# register: __sap_rfc_sapcar_exe

# - name: Extract SAR of the SAP NWRFC SDK Patch on target host
# ansible.builtin.shell: |
# {{ __sap_rfc_sapcar_exe.files[0].path }} \
# -R /tmp/nwrfcsdk_patch_extract \
# -xvf "{{ __sap_rfc_nwrfc_sdk_sar.files[0].path }}"
# when: __sap_rfc_nwrfc_sdk_sar.files | length > 0

# - name: Find patched compiled shared library (libsapnwrfc.so)
# ansible.builtin.find:
# paths: /tmp/nwrfcsdk_patch_extract
# recurse: true
# patterns: libsapnwrfc.so
# register: __sap_rfc_nwrfc_lib_patch

- name: Find compiled shared library (libsapnwrfc.so)
ansible.builtin.find:
paths: /usr/local/sap/nwrfcsdk
recurse: true
patterns: libsapnwrfc.so
register: __sap_rfc_nwrfc_lib

# - name: Copy patched compiled shared library (libsapnwrfc.so) to replace original
# ansible.builtin.copy:
# backup: false # Otherwise ldconfig will identify multiple copies of libsapnwrfc.so
# remote_src: true
# mode: 755
# src: "{{ __sap_rfc_nwrfc_lib_patch.files[0].path }}"
# dest: "{{ __sap_rfc_nwrfc_lib.files[0].path }}"

# - name: Create ld.so.conf configuration file with path to compiled shared library (libsapnwrfc.so)
# ansible.builtin.copy:
# dest: /etc/ld.so.conf.d/nwrfcsdk.conf
# mode: '0444'
# content: |
# # include nwrfcsdk
# {{ __sap_rfc_nwrfc_lib.files[0].path | dirname }}
# # include /usr/sap (e.g. libstdc++.so.6)
# /usr/sap/lib

- name: Reload system-wide library paths (ldconfig)
ansible.builtin.shell: ldconfig

- name: Ensure compiled shared library (libsapnwrfc.so) is registered as system-wide library
ansible.builtin.shell: ldconfig -p | grep sapnwrfc
register: __sap_rfc_nwrfc_lib_discover_path

- name: Identify SAP NW RFC Library home directory
ansible.builtin.find:
paths: /usr/local/sap
recurse: true
file_type: directory
patterns: include
register: __sap_rfc_nwrfc_home
Loading
Loading