Skip to content

Commit 2631c71

Browse files
committed
feat: python default module packages
1 parent 024f083 commit 2631c71

File tree

9 files changed

+183
-13
lines changed

9 files changed

+183
-13
lines changed

roles/sap_software_download/README.md

Lines changed: 95 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ The Ansible Role `sap_software_download` is used to download SAP Software Media
88
<!-- END Description -->
99

1010
<!-- BEGIN Dependencies -->
11+
## Dependencies
12+
This role requires the following Python modules to be installed on the target node (the machine where SAP software will be downloaded):
13+
14+
- wheel
15+
- urllib3
16+
- requests
17+
- beautifulsoup4
18+
- lxml
19+
20+
The role installs these modules if they are not already present. Installation can be done in one of the following ways:
21+
22+
- **Virtual Environment (Default):**
23+
- When `sap_software_download_use_venv` is `true` (default), a temporary virtual environment is created, and modules are installed via `pip`.
24+
- The Python version is determined by `sap_software_download_python_interpreter`.
25+
- **System Environment:**
26+
- When `sap_software_download_use_venv` is `false`, modules are installed directly into the system's Python environment using OS packages specified by `sap_software_download_python_module_packages`.
1127
<!-- END Dependencies -->
1228

1329
<!-- BEGIN Prerequisites -->
@@ -34,13 +50,14 @@ The target node must meet the following requirements:
3450
2. **Python Environment Preparation:** The role prepares the Python environment:
3551
* **Virtual Environment (Default):** A temporary Python virtual environment is created, and all necessary dependencies are installed within it.
3652
* **System Environment:** Alternatively, if `sap_software_download_use_venv` is set to `false`, dependencies are installed directly into the system's default Python environment.
37-
3. **Maintenance Plan File List:** If the `sap_software_download_mp_transaction` variable is provided, the role retrieves the list of files associated with the specified Maintenance Plan transaction.
38-
4. **File Relationship Validation:** If `sap_software_download_validate_relationships` is `true`, the role performs validation checks on the relationships between the files to be downloaded.
53+
3. **Validate provided S-User credentials** The role will search for `SAPCAR` file to validate credentials and download authorization.
54+
4. **Maintenance Plan File List:** If the `sap_software_download_mp_transaction` variable is provided, the role retrieves the list of files associated with the specified Maintenance Plan transaction.
55+
5. **File Relationship Validation:** If `sap_software_download_validate_relationships` is `true`, the role performs validation checks on the relationships between the files to be downloaded.
3956
* **Alternative File Search:** If `sap_software_download_find_alternatives` is `true`, the role will search for alternative files if the requested files are not found.
4057
* More information about validation logic is available at [Explanation of relationship validation logic](#explanation-of-relationship-validation-logic)
41-
5. **Maintenance Plan File Download:** If `sap_software_download_mp_transaction` is provided, the role downloads the files associated with the Maintenance Plan.
42-
6. **Direct File Download:** If `sap_software_download_files` is provided, the role downloads the specified files.
43-
7. **Virtual Environment Cleanup:** If a temporary Python virtual environment was used, it is removed.
58+
6. **Maintenance Plan File Download:** If `sap_software_download_mp_transaction` is provided, the role downloads the files associated with the Maintenance Plan.
59+
7. **Direct File Download:** If `sap_software_download_files` is provided, the role downloads the specified files.
60+
8. **Virtual Environment Cleanup:** If a temporary Python virtual environment was used, it is removed.
4461

4562
<!-- END Execution Flow -->
4663

@@ -81,6 +98,62 @@ Download of SAP Software files using Maintenance Plan
8198
sap_software_download_directory: "/software"
8299
sap_software_download_mp_transaction: 'Transaction Name or Display ID from Maintenance Planner'
83100
```
101+
102+
Combined download of SAP Software files and Maintenance Plan transaction together with settings:
103+
- Use default Python instead of Python virtual environment
104+
- No validation of S-User credentials
105+
- No validation of relationships
106+
- No warnings for unavailable files
107+
- No warnings for unavailable Maintenance Plan transaction
108+
```yaml
109+
- name: Ansible Play for downloading SAP Software
110+
hosts: localhost
111+
become: true
112+
tasks:
113+
- name: Include role sap_software_download
114+
ansible.builtin.include_role:
115+
name: community.sap_launchpad.sap_software_download
116+
vars:
117+
sap_software_download_suser_id: "Enter SAP S-User ID"
118+
sap_software_download_suser_password: "Enter SAP S-User Password"
119+
sap_software_download_directory: "/software"
120+
sap_software_download_use_venv: false
121+
sap_software_download_ignore_validate_credentials: true
122+
sap_software_download_ignore_file_not_found: true
123+
sap_software_download_ignore_plan_not_found: true
124+
sap_software_download_validate_relationships: false
125+
sap_software_download_deduplicate: first
126+
sap_software_download_files:
127+
- 'SAPCAR_1115-70006178.EXE'
128+
- 'SAPEXE_100-80005509.SAR'
129+
sap_software_download_mp_transaction: 'Transaction Name or Display ID from Maintenance Planner'
130+
```
131+
Download of SAP Software files using Python version `3.13`.
132+
```yaml
133+
---
134+
- name: Ansible Play for downloading SAP Software
135+
hosts: localhost
136+
become: true
137+
tasks:
138+
- name: Include role sap_software_download
139+
ansible.builtin.include_role:
140+
name: community.sap_launchpad.sap_software_download
141+
vars:
142+
sap_software_download_python_interpreter: python3.13
143+
sap_software_download_python_package: python313
144+
sap_software_download_python_module_packages:
145+
- python313-wheel
146+
- python313-urllib3
147+
- python313-requests
148+
- python313-beautifulsoup4
149+
- python313-lxml
150+
sap_software_download_suser_id: "Enter SAP S-User ID"
151+
sap_software_download_suser_password: "Enter SAP S-User Password"
152+
sap_software_download_directory: "/software"
153+
sap_software_download_files:
154+
- 'SAPCAR_1115-70006178.EXE'
155+
- 'SAPEXE_100-80005509.SAR'
156+
```
84157
<!-- END Execution Example -->
85158

86159
<!-- BEGIN Role Tags -->
@@ -93,20 +166,20 @@ Validation is executed for known combinations of files, where we can validate th
93166
Example for SAP HANA Database Server 2.0 with LCAPPS and AFL.<br>
94167

95168
1. All files are examined, and a file starting with `IMDB_SERVER2` is found: `IMDB_SERVER20_084_0-80002031.SAR (Revision 2.00.084.0 (SPS08))`. This indicates a SAP HANA 2.0 database server file.
96-
2. The HANA version and revision are extracted from the file name: `HANA 2.0`, `Revision 084`.
169+
2. The HANA version and revision are extracted from the file name: `HANA 2.0`, `Version 084`.
97170
3. Validation for HANA 1.0 is skipped because it expects files starting with `IMDB_SERVER1`. The following steps are only for `IMDB_SERVER2` (HANA 2.0).
98171
4. All files are examined for files starting with `IMDB_LCAPPS_2` (indicating LCAPPS for HANA 2.0). Then the list is filtered to only include files starting with `IMDB_LCAPPS_2084` (indicating LCAPPS for HANA 2.0 revision 084).
99172
5. Validation will have two outcomes:
100173
- A file like `IMDB_LCAPPS_2084_0-20010426.SAR` is present. In this case, validation will pass because the LCAPPS version is compatible with the HANA revision.
101174
- No file starting with `IMDB_LCAPPS_2084` is present, but there are files starting with `IMDB_LCAPPS_2`.<br>
102175
This indicates a mismatch because the LCAPPS version is not compatible with the specific HANA revision (084) found in step 2.<br>
103-
In this case, validation will fail. This can be prevented by setting `sap_software_download_ignore_relationship_warning` to `true`.
176+
In this case, validation will fail. This can be ignored by setting `sap_software_download_ignore_relationship_warning` to `true`.
104177
6. All files are examined for files starting with `IMDB_AFL20` (indicating AFL for HANA 2.0). Then the list is filtered to only include files starting with `IMDB_AFL20_084` (indicating AFL for HANA 2.0 revision 084).
105178
7. Validation will have two outcomes:
106179
- A file like `IMDB_AFL20_084_1-80001894.SAR` is present. In this case, validation will pass because the AFL version is compatible with the HANA revision.
107180
- No file starting with `IMDB_AFL20_084` is present, but there are files starting with `IMDB_AFL20`.<br>
108181
This indicates a mismatch because the AFL version is not compatible with the specific HANA revision (084) found in step 2.<br>
109-
In this case, validation will fail. This can be prevented by setting `sap_software_download_ignore_relationship_warning` to `true`.
182+
In this case, validation will fail. This can be ignored by setting `sap_software_download_ignore_relationship_warning` to `true`.
110183

111184
This validation example checks major and minor release (SPS and Revision), but it does not validate patch version.
112185
<!-- END Further Information -->
@@ -125,6 +198,7 @@ Apache 2.0
125198
<!-- BEGIN Role Variables -->
126199
### sap_software_download_python_interpreter
127200
- _Type:_ `string`<br>
201+
- _Default:_ **Determined by the operating system.**<br>
128202

129203
The Python interpreter executable to use when creating a Python virtual environment.<br>
130204
**Mandatory** when `sap_software_download_use_venv` is `true`.<br>
@@ -134,12 +208,25 @@ Examples: `python3.11` (SUSE), `python3.9` (Red Hat)<br>
134208

135209
### sap_software_download_python_package
136210
- _Type:_ `string`<br>
211+
- _Default:_ **Determined by the operating system.**<br>
137212

138213
The name of the OS package that provides the desired Python version.<br>
139214
The Python version provided by this package must match the version specified by `sap_software_download_python_interpreter`.<br>
140215
The default value is determined by the operating system and is set in the corresponding OS-specific variables file.<br>
141216
Examples: `python311` (SUSE), `python3.9` (Red Hat)<br>
142217

218+
### sap_software_download_python_module_packages
219+
- _Type:_ `list` with elements of type `string`<br>
220+
- _Default:_ **Determined by the operating system.**<br>
221+
222+
The list of the OS packages that provide modules for the desired Python version.<br>
223+
Required modules are wheel, urllib3, requests, beautifulsoup4, lxml<br>
224+
The listed package versions must match the Python version specified by `sap_software_download_python_interpreter`.<br>
225+
The default value is determined by the operating system and is set in the corresponding OS-specific variables file.<br>
226+
Examples:<br>
227+
- `['python311-wheel', 'python311-urllib3', 'python311-requests', 'python311-beautifulsoup4', 'python311-lxml']` (SUSE)<br>
228+
- `['python3.9-wheel', 'python3.9-urllib3', 'python3.9-requests', 'python3.9-beautifulsoup4', 'python3.9-lxml']` (Red Hat)<br>
229+
143230
### sap_software_download_use_venv
144231
- _Type:_ `boolean`<br>
145232
- _Default:_ `true`<br>

roles/sap_software_download/defaults/main.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ sap_software_download_python_interpreter:
1616
sap_software_download_python_package:
1717
"{{ __sap_software_download_python_package }}"
1818

19+
# The list of the OS packages that provide modules for the desired Python version.
20+
# Required modules: wheel, urllib3, requests, beautifulsoup4, lxml
21+
# The listed package versions must match the Python version specified by `sap_software_download_python_interpreter`.
22+
# The default value is determined by the operating system and is set in the corresponding OS-specific variables file. Examples:
23+
# python311-wheel, python311-urllib3, python311-requests, python311-beautifulsoup4, python311-lxml (SUSE)
24+
# python3.9-wheel, python3.9-urllib3, python3.9-requests, python3.9-beautifulsoup4, python3.9-lxml (Red Hat)
25+
sap_software_download_python_module_packages:
26+
"{{ __sap_software_download_python_module_packages }}"
27+
1928
# Determines whether to execute the role within a Python virtual environment.
2029
# Using a virtual environment is strongly recommended to isolate dependencies.
2130
# If set to `false`, the role will install Python dependencies directly into the system's Python environment.

roles/sap_software_download/meta/argument_spec.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,25 @@ argument_specs:
2525

2626
sap_software_download_python_package:
2727
type: str
28-
required: true
28+
required: false
2929
description:
3030
- The name of the OS package that provides the desired Python version.
3131
- The Python version provided by this package must match the version specified by `sap_software_download_python_interpreter`.
3232
- The default value is determined by the operating system and is set in the corresponding OS-specific variables file.
3333
- Examples are `python311` (SUSE), `python3.9` (Red Hat)
3434

35+
sap_software_download_python_module_packages:
36+
type: list
37+
elements: str
38+
required: false
39+
description:
40+
- The list of the OS packages that provide modules for the desired Python version.
41+
- Required modules are wheel, urllib3, requests, beautifulsoup4, lxml
42+
- The listed package versions must match the Python version specified by `sap_software_download_python_interpreter`.
43+
- The default value is determined by the operating system and is set in the corresponding OS-specific variables file. Examples are
44+
- python311-wheel, python311-urllib3, python311-requests, python311-beautifulsoup4, python311-lxml (SUSE)
45+
- python3.9-wheel, python3.9-urllib3, python3.9-requests, python3.9-beautifulsoup4, python3.9-lxml (Red Hat)
46+
3547
sap_software_download_use_venv:
3648
type: bool
3749
required: false

roles/sap_software_download/tasks/pre_steps/01_include_variables.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
- name: Pre-Steps - Assert that SAP Software files were specified
3535
ansible.builtin.assert:
3636
that:
37-
- (sap_software_download_files is defined and sap_software_download_files | length > 0)
37+
- (sap_software_download_files is defined and sap_software_download_files | type_debug == 'list' and sap_software_download_files | length > 0)
3838
or (sap_software_download_mp_transaction is defined and sap_software_download_mp_transaction | length > 0)
3939
fail_msg: |
4040
Neither `sap_software_download_files` or `sap_software_download_mp_transaction` are valid.
@@ -76,6 +76,16 @@
7676
Empty variable `sap_software_download_python_package`.
7777
Ensure that it contains correct Python package name or revert back to defaults.
7878
79+
- name: "Pre-Steps - Verify variable: sap_software_download_python_module_packages"
80+
ansible.builtin.assert:
81+
that:
82+
- sap_software_download_python_module_packages is defined
83+
- sap_software_download_python_module_packages | type_debug == 'list'
84+
- sap_software_download_python_module_packages | length > 0
85+
fail_msg: |
86+
Empty variable `sap_software_download_python_module_packages`.
87+
Ensure that it contains correct list of Python module package names or revert back to defaults.
88+
7989
- name: "Pre-Steps - Verify variable: sap_software_download_suser_id"
8090
ansible.builtin.assert:
8191
that:

roles/sap_software_download/tasks/pre_steps/02_prepare_python_environment.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
- name: Pre-Steps - Block for default Python preparation
3636
when: not sap_software_download_use_venv | d(true)
3737
block:
38-
- name: Pre-Steps - Install Python modules in default Python
39-
ansible.builtin.pip:
40-
name: "{{ __sap_software_download_python_modules }}"
38+
# Packages with python modules are installed instead of modules to avoid error:
39+
# `externally-managed-environment` which requires `--break-system-packages`
40+
- name: Pre-Steps - Install Python module packages
41+
ansible.builtin.package:
42+
name: "{{ __sap_software_download_python_module_packages }}"
43+
state: present

roles/sap_software_download/vars/RedHat.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ __sap_software_download_python_interpreter: 'python3.9'
1111

1212
# Set which Python package will be installed on destination node.
1313
__sap_software_download_python_package: 'python3.9'
14+
15+
# The list of required Python Modules in packages
16+
# This is required in order to avoid externally-managed-environment error.
17+
__sap_software_download_python_module_packages:
18+
- python3.9-wheel
19+
- python3.9-urllib3
20+
- python3.9-requests
21+
- python3.9-beautifulsoup4
22+
- python3.9-lxml

roles/sap_software_download/vars/RedHat_10.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ __sap_software_download_python_interpreter: 'python3.12'
1010

1111
# Set which Python package will be installed on destination node.
1212
__sap_software_download_python_package: 'python3.12'
13+
14+
# The list of required Python Modules in packages
15+
# This is required in order to avoid externally-managed-environment error.
16+
__sap_software_download_python_module_packages:
17+
- python3.12-wheel
18+
- python3.12-urllib3
19+
- python3.12-requests
20+
- python3.12-beautifulsoup4
21+
- python3.12-lxml

roles/sap_software_download/vars/Suse.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,24 @@ __sap_software_download_python_package: >-
2323
{%- else -%}
2424
python311
2525
{%- endif -%}
26+
27+
# The list of required Python Modules in packages
28+
# This is required in order to avoid externally-managed-environment error.
29+
__sap_software_download_python_module_packages: >-
30+
{%- if ansible_distribution_major_version == '15' and ansible_distribution_version.split('.')[1] | int < 5 -%}
31+
[
32+
"python3-wheel",
33+
"python3-urllib3",
34+
"python3-requests",
35+
"python3-beautifulsoup4",
36+
"python3-lxml"
37+
]
38+
{%- else -%}
39+
[
40+
"python311-wheel",
41+
"python311-urllib3",
42+
"python311-requests",
43+
"python311-beautifulsoup4",
44+
"python311-lxml"
45+
]
46+
{%- endif -%}

roles/sap_software_download/vars/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,13 @@ __sap_software_download_python_modules:
88
- requests
99
- beautifulsoup4
1010
- lxml
11+
12+
# The list of required Python Modules in packages
13+
# This is required in order to avoid externally-managed-environment error.
14+
# Specific packages are available in OS specific var files
15+
__sap_software_download_python_module_packages:
16+
- python3-wheel
17+
- python3-urllib3
18+
- python3-requests
19+
- python3-beautifulsoup4
20+
- python3-lxml

0 commit comments

Comments
 (0)