Skip to content

Commit 0ee7de2

Browse files
committed
sap_rfc: overhaul of structure
1 parent 9991fdd commit 0ee7de2

File tree

8 files changed

+225
-93
lines changed

8 files changed

+225
-93
lines changed

roles/sap_rfc/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# sap_rfc Ansible Role
22

3-
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)).
3+
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)).
44

55
## Ansible Role Overview
66

77
The sap_rfc Ansible Role uses:
88
- 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).
99
- 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).
1010

11-
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.
11+
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.
1212

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

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

6161
`Ansible Task code example for data element:`
6262
```yaml
63-
target_parameters:
63+
sap_rfc_target_parameters:
6464
VAR: 'ECHO'
6565
```
6666
@@ -71,7 +71,7 @@ target_parameters:
7171
7272
`Ansible Task code example for ABAP Struture:`
7373
```yaml
74-
target_parameters:
74+
sap_rfc_target_parameters:
7575
IMPORTSTRUCT:
7676
RFCFLOAT: 1.1
7777
RFCCHAR1: 'A'
@@ -84,7 +84,7 @@ target_parameters:
8484

8585
`Ansible Task code example for ABAP Table:`
8686
```yaml
87-
target_parameters:
87+
sap_rfc_target_parameters:
8888
RFCTABLE:
8989
- COLUMN0: SAP
9090
- COLUMN1: 1.23

roles/sap_rfc/defaults/main.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#pyrfc_first_run: true
1+
---
22

3-
#sap_nwrfc_sdk: nwrfc750P_10-70002752.zip
3+
# sap_rfc_first_run_download_sap_user_id: ""
4+
# sap_rfc_first_run_download_sap_user_password: ""
5+
sap_rfc_first_run_download_path: /software
46

5-
#target_connection:
7+
#sap_rfc_target_connection:
68
# ashost: s4hana.poc.cloud
79
# sysid: TDT
810
# sysnr: "01"
@@ -15,7 +17,22 @@
1517
# gwhost: gateway.poc.cloud
1618
# ghserv: gateway.poc.cloud
1719

18-
target_function: STFC_CONNECTION
20+
sap_rfc_target_function: STFC_CONNECTION
1921

20-
target_parameters:
22+
sap_rfc_target_parameters:
2123
REQUTEXT: "Hello SAP!"
24+
25+
26+
# Override default for detected CPU Architecture (x86_64, ppc64le)
27+
# Contains /usr/local/sap/nwrfcsdk/lib with libsapnwrfc.so , libicuuc.so.50 , libicudata.so.50 , libicui18n.so.50 , libsapucum.so
28+
# Contains /usr/local/sap/nwrfcsdk/include with sapdecf.h , sapnwrfc.h , sapucrfc.h
29+
# sap_rfc_first_run_download_nwrfc_sdk: "" # 7.50 x86_64 = nwrfc750P_12-70002752.zip , ppc64le = nwrfc750P_12-70002761.zip
30+
31+
32+
# NOT USED:
33+
# May cause errors with additional dependency libs not available in the LD_LIBRARY_PATH '/usr/local/sap/nwrfcsdk/lib'
34+
# (e.g. libicuuc65.so, libicudata65.so, libicui18n65.so)
35+
# Not recommended as per SAP Note 3384574 - SAP NW RFC SDK 7.50 hotfix installation
36+
# Therefore Ansible Tasks code exists, but commented-out
37+
# sap_rfc_first_run_download_sapcar: "" # x86_64 = SAPCAR_1115-70006178.EXE , ppc64le = SAPCAR_1115-70006238.EXE
38+
# sap_rfc_first_run_download_nwrfc_sdk_patch: "" # 7.93 Backwards Compatible x86_64 = sapnwrfc_69-70007807.sar , ppc64le = sapnwrfc_69-70007832.sar

roles/sap_rfc/meta/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ galaxy_info:
1414
dependencies: []
1515
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
1616
collections:
17-
- community.sap_libs
18-
- community.sap_launchpad
17+
- community.sap_libs
18+
- community.sap_launchpad

roles/sap_rfc/tasks/main.yml

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,47 @@
11
---
2-
- name: Initial install of Python altinstall for PyRFC
3-
ansible.builtin.include_tasks: python_pyrfc_init.yml
4-
when: pyrfc_first_run | bool
52

6-
- name: Discover Python altinstall for PyRFC
7-
ansible.builtin.include_tasks: python_pyrfc_discover.yml
8-
when: not pyrfc_first_run | bool
3+
- name: Identify SAP NW RFC Library home directory
4+
ansible.builtin.find:
5+
paths: /usr/local/sap
6+
recurse: true
7+
file_type: directory
8+
patterns: include
9+
register: __sap_rfc_nwrfc_home
10+
11+
- name: Identify SAP NW RFC Library compiled shared library (libsapnwrfc.so)
12+
ansible.builtin.find:
13+
paths: /usr/local/sap/nwrfcsdk
14+
recurse: true
15+
file_type: file
16+
patterns: libsapnwrfc.so
17+
register: __sap_rfc_nwrfc_lib
18+
19+
- name: Identify Python virtual environment for sap_rfc Ansible Role
20+
ansible.builtin.stat:
21+
path: ~/env/pyrfc_env
22+
register: __sap_rfc_python_virtual_env
23+
24+
- name: Set fact based on identified SAP NW RFC Library
25+
ansible.builtin.set_fact:
26+
__sap_rfc_first_run: "{{ true if ((__sap_rfc_nwrfc_home.files | length) == 0 or (__sap_rfc_nwrfc_lib.files | length) == 0) else false }}"
27+
28+
- name: Initial install of SAP NW RFC SDK Library
29+
ansible.builtin.include_tasks: setup/nwrfcsdk_init.yml
30+
when: __sap_rfc_first_run | bool
31+
32+
- name: Initial install of Python virtual environment for PyRFC
33+
ansible.builtin.include_tasks: setup/python_init.yml
34+
when: (__sap_rfc_first_run | bool) or (not __sap_rfc_python_virtual_env.stat.exists)
935

1036
# Use Ansible Task block to call sap_pyrfc Ansible Module in the Ansible Collection for sap_libs
1137
# RFC call using variables set by the Ansible Playbook when calling this Ansible Role
1238
- name: Execute Ansible Module to call PyRFC using the virtualenv Python3
13-
community.sap_libs.sap_pyrfc:
14-
function: "{{ target_function }}"
15-
parameters: "{{ target_parameters }}"
16-
connection: "{{ target_connection }}"
39+
environment:
40+
SAPNWRFC_HOME: "{{ __sap_rfc_nwrfc_home.files[0].path | dirname }}"
41+
LD_LIBRARY_PATH: "$LD_LIBRARY_PATH:$SAPNWRFC_HOME/lib"
1742
vars:
1843
ansible_python_interpreter: ~/env/pyrfc_env/bin/python3
44+
community.sap_libs.sap_pyrfc:
45+
function: "{{ sap_rfc_target_function }}"
46+
parameters: "{{ sap_rfc_target_parameters }}"
47+
connection: "{{ sap_rfc_target_connection }}"

roles/sap_rfc/tasks/python_pyrfc_discover.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

roles/sap_rfc/tasks/python_pyrfc_init.yml

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
3+
- name: Set fact x86_64 sap_rfc_first_run_download_nwrfc_sdk
4+
ansible.builtin.set_fact:
5+
sap_rfc_first_run_download_nwrfc_sdk: "nwrfc750P_12-70002752.zip"
6+
when: ansible_architecture == "x86_64"
7+
8+
- name: Set fact x86_64 sap_rfc_first_run_download_nwrfc_sdk
9+
ansible.builtin.set_fact:
10+
sap_rfc_first_run_download_nwrfc_sdk: "nwrfc750P_12-70002761.zip"
11+
when: ansible_architecture == "ppc64le"
12+
13+
- name: Create directories if does not exist
14+
ansible.builtin.file:
15+
path: "{{ item }}"
16+
state: directory
17+
mode: "0755"
18+
loop:
19+
- "{{ sap_rfc_first_run_download_path }}"
20+
- "/usr/local/sap"
21+
- "/usr/local/sap/nwrfcsdk"
22+
# - "/tmp/nwrfcsdk_patch_extract"
23+
24+
# Use task block to call Ansible Module in the Ansible Collection for sap_launchpad
25+
- name: Execute Ansible Module to download SAP software
26+
community.sap_launchpad.software_center_download:
27+
suser_id: "{{ sap_rfc_first_run_download_sap_user_id }}"
28+
suser_password: "{{ sap_rfc_first_run_download_sap_user_password }}"
29+
softwarecenter_search_query: "{{ item }}"
30+
dest: "{{ sap_rfc_first_run_download_path }}"
31+
loop:
32+
- "{{ sap_rfc_first_run_download_nwrfc_sdk }}"
33+
# - "{{ sap_rfc_first_run_download_sapcar }}"
34+
# - "{{ sap_rfc_first_run_download_nwrfc_sdk_patch }}"
35+
36+
- name: Discover zip of the SAP NWRFC SDK (7.5x Original) on target host
37+
ansible.builtin.find:
38+
paths: "{{ sap_rfc_first_run_download_path }}"
39+
recurse: true
40+
patterns: "nwrfc*.zip"
41+
register: __sap_rfc_nwrfc_sdk_zip
42+
43+
- name: Extract zip of the SAP NWRFC SDK (7.5x) on target host
44+
ansible.builtin.unarchive:
45+
remote_src: true
46+
src: "{{ __sap_rfc_nwrfc_sdk_zip.files[0].path }}"
47+
dest: /usr/local/sap # ZIP contains nwrfcsdk subdirectory
48+
when: __sap_rfc_nwrfc_sdk_zip.files | length > 0
49+
50+
# - name: Discover SAR of the SAP NWRFC SDK Patch on target host
51+
# ansible.builtin.find:
52+
# paths: "{{ sap_rfc_first_run_download_path }}"
53+
# recurse: true
54+
# patterns: "sapnwrfc_*.sar"
55+
# register: __sap_rfc_nwrfc_sdk_sar
56+
57+
# - name: Discover SAPCAR on target host
58+
# ansible.builtin.find:
59+
# paths: "{{ sap_rfc_first_run_download_path }}"
60+
# recurse: true
61+
# patterns: "SAPCAR*"
62+
# register: __sap_rfc_sapcar_exe
63+
64+
# - name: Extract SAR of the SAP NWRFC SDK Patch on target host
65+
# ansible.builtin.shell: |
66+
# {{ __sap_rfc_sapcar_exe.files[0].path }} \
67+
# -R /tmp/nwrfcsdk_patch_extract \
68+
# -xvf "{{ __sap_rfc_nwrfc_sdk_sar.files[0].path }}"
69+
# when: __sap_rfc_nwrfc_sdk_sar.files | length > 0
70+
71+
# - name: Find patched compiled shared library (libsapnwrfc.so)
72+
# ansible.builtin.find:
73+
# paths: /tmp/nwrfcsdk_patch_extract
74+
# recurse: true
75+
# patterns: libsapnwrfc.so
76+
# register: __sap_rfc_nwrfc_lib_patch
77+
78+
- name: Find compiled shared library (libsapnwrfc.so)
79+
ansible.builtin.find:
80+
paths: /usr/local/sap/nwrfcsdk
81+
recurse: true
82+
patterns: libsapnwrfc.so
83+
register: __sap_rfc_nwrfc_lib
84+
85+
# - name: Copy patched compiled shared library (libsapnwrfc.so) to replace original
86+
# ansible.builtin.copy:
87+
# backup: false # Otherwise ldconfig will identify multiple copies of libsapnwrfc.so
88+
# remote_src: true
89+
# mode: 755
90+
# src: "{{ __sap_rfc_nwrfc_lib_patch.files[0].path }}"
91+
# dest: "{{ __sap_rfc_nwrfc_lib.files[0].path }}"
92+
93+
# - name: Create ld.so.conf configuration file with path to compiled shared library (libsapnwrfc.so)
94+
# ansible.builtin.copy:
95+
# dest: /etc/ld.so.conf.d/nwrfcsdk.conf
96+
# mode: '0444'
97+
# content: |
98+
# # include nwrfcsdk
99+
# {{ __sap_rfc_nwrfc_lib.files[0].path | dirname }}
100+
# # include /usr/sap (e.g. libstdc++.so.6)
101+
# /usr/sap/lib
102+
103+
- name: Reload system-wide library paths (ldconfig)
104+
ansible.builtin.shell: ldconfig
105+
106+
- name: Ensure compiled shared library (libsapnwrfc.so) is registered as system-wide library
107+
ansible.builtin.shell: ldconfig -p | grep sapnwrfc
108+
register: __sap_rfc_nwrfc_lib_discover_path
109+
110+
- name: Identify SAP NW RFC Library home directory
111+
ansible.builtin.find:
112+
paths: /usr/local/sap
113+
recurse: true
114+
file_type: directory
115+
patterns: include
116+
register: __sap_rfc_nwrfc_home
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
3+
# PyRFC v2.7.0 dropped support for CPython 3.6 (OS System Python version), use CPython 3.9 instead
4+
- name: Install Python package manager pip3, and compiler/library for C and C++
5+
ansible.builtin.package:
6+
name:
7+
- python39
8+
- python39-pip
9+
- python39-wheel
10+
- python39-devel # Required for PyRFC compile with GCC
11+
- gcc
12+
- glibc
13+
- gcc-c++
14+
- libstdc++
15+
state: present
16+
17+
- name: Install virtualenv to system Python
18+
ansible.builtin.pip:
19+
name:
20+
- virtualenv
21+
22+
- name: Create virtualenv for python3, install dependencies to virtualenv. Do not inherit system Python modules
23+
ansible.builtin.pip:
24+
name:
25+
- cython
26+
- wheel
27+
- pytest
28+
- sphinx
29+
virtualenv: ~/env/pyrfc_env
30+
virtualenv_command: virtualenv
31+
virtualenv_python: python3.9
32+
33+
- name: Install pyrfc to virtualenv on target host. Do not inherit system Python modules
34+
environment:
35+
SAPNWRFC_HOME: "{{ __sap_rfc_nwrfc_home.files[0].path | dirname }}"
36+
ansible.builtin.pip:
37+
name:
38+
- pyrfc
39+
virtualenv: ~/env/pyrfc_env
40+
virtualenv_command: virtualenv
41+
virtualenv_python: python3.9

0 commit comments

Comments
 (0)