Skip to content

Commit

Permalink
Merge pull request #10 from sap-linuxlab/dev
Browse files Browse the repository at this point in the history
Merge dev to main for release 1.0.0
  • Loading branch information
sean-freeman authored Aug 4, 2023
2 parents d286cc0 + 0120ad5 commit 52a97e0
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 53 deletions.
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,9 @@ Within this Ansible Collection, there are various Ansible Modules.
| [sap_launchpad.maintenance_planner_files](./docs/module_maintenance_planner_files.md) | maintenance planner files retrieval |
| [sap_launchpad.maintenance_planner_stack_xml_download](./docs/module_maintenance_planner_stack_xml_download.md) | maintenance planner stack xml download |

## Execution examples
## Execution

There are various methods to execute the Ansible Collection, dependant on the use case. For more information, see [Execution examples with code samples](./docs/EXEC_EXAMPLES.md) and the summary below:

| Execution Scenario | Use Case | Target |
| --- | --- | --- |
| Ansible Playbook <br/>-> source Ansible Collection <br/>-> execute Ansible Task <br/>--> run Ansible Module <br/>---> run Python/Bash Functions | Simple executions with a few activities | Localhost or Remote |
| Ansible Playbook <br/>-> source Ansible Collection <br/>-> execute Ansible Task <br/>--> run Ansible Role <br/>---> run Ansible Module <br/>----> run Python/Bash Functions <br/>--> run Ansible Role<br/>---> ... | Complex executions with various interlinked activities;<br/> run in parallel or sequentially | Localhost or Remote |
| Python/Bash Functions | Simple testing or non-Ansible use cases | Localhost |

## Requirements, Dependencies and Testing

### SAP User ID credentials
### Credentials - SAP User ID

SAP software installation media must be obtained from SAP directly, and requires valid license agreements with SAP in order to access these files.

Expand All @@ -55,6 +45,22 @@ When an SAP User ID (e.g. S-User) is enabled with and part of an SAP Universal I

In addition, if a SAP Universal ID is used then the recommendation is to check and reset the SAP User ID ‘Account Password’ in the [SAP Universal ID Account Manager](https://account.sap.com/manage/accounts), which will help to avoid any potential conflicts.

For further information regarding connection errors, please see the FAQ section [Errors with prefix 'SAP SSO authentication failed - '](./docs/FAQ.md#errors-with-prefix-sap-sso-authentication-failed---).

### Execution examples

There are various methods to execute the Ansible Collection, dependant on the use case. For more information, see [Execution examples with code samples](./docs/EXEC_EXAMPLES.md) and the summary below:

| Execution Scenario | Use Case | Target |
| --- | --- | --- |
| Ansible Playbook <br/>-> source Ansible Collection <br/>-> execute Ansible Task <br/>--> run Ansible Module <br/>---> run Python/Bash Functions | Simple executions with a few activities | Localhost or Remote |
| Ansible Playbook <br/>-> source Ansible Collection <br/>-> execute Ansible Task <br/>--> run Ansible Role <br/>---> run Ansible Module <br/>----> run Python/Bash Functions <br/>--> run Ansible Role<br/>---> ... | Complex executions with various interlinked activities;<br/> run in parallel or sequentially | Localhost or Remote |
| Python/Bash Functions | Simple testing or non-Ansible use cases | Localhost |

---

## Requirements, Dependencies and Testing

### Operating System requirements

Designed for Linux operating systems, e.g. RHEL.
Expand Down
50 changes: 33 additions & 17 deletions docs/EXEC_EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,25 @@

# Use task block to call Ansible Module
tasks:
- name: Execute Ansible Module to download SAP software
community.sap_launchpad.software_center_download:
suser_id: "{{ suser_id }}"
suser_password: "{{ suser_password }}"
softwarecenter_search_query: "{{ item }}"
dest: "/tmp/"
with_items: "{{ softwarecenter_search_list }}"
- name: Execute Ansible Module to download SAP software
community.sap_launchpad.software_center_download:
suser_id: "{{ suser_id }}"
suser_password: "{{ suser_password }}"
softwarecenter_search_query: "{{ item }}"
dest: "/tmp/"
loop: "{{ softwarecenter_search_list }}"
loop_control:
label: "{{ item }} : {{ download_task.msg }}"
register: download_task
retries: 1
until: download_task is not failed
```
**Execution of Ansible Playbook, with in-line Ansible Inventory set as localhost**
```shell
# Install from local source directory for Ansible 2.11+
ansible-galaxy collection install ./community.sap_launchpad
ansible-galaxy collection install community.sap_launchpad

# Workaround install from local source directory for Ansible 2.9.x
# mv ./community.sap_launchpad ~/.ansible/collections/ansible_collections/community
Expand Down Expand Up @@ -108,14 +113,20 @@ ansible-playbook --timeout 60 ./community.sap_launchpad/playbooks/sample-downloa

# Option 2: Use sequential parse/execution, by using include_role inside Task block
tasks:
- name: Execute Ansible Role to download SAP software
include_role:
name: { role: community.sap_launchpad.software_center_download }
vars:
suser_id: "{{ suser_id }}"
suser_password: "{{ suser_password }}"
softwarecenter_search_query: "{{ item }}"
with_items: "{{ softwarecenter_search_list }}"
- name: Execute Ansible Role to download SAP software
include_role:
name: { role: community.sap_launchpad.software_center_download }
vars:
suser_id: "{{ suser_id }}"
suser_password: "{{ suser_password }}"
softwarecenter_search_query: "{{ item }}"
loop: "{{ softwarecenter_search_list }}"
loop_control:
label: "{{ item }} : {{ download_task.msg }}"
register: download_task
retries: 1
until: download_task is not failed


# Option 3: Use task block with import_roles
tasks:
Expand All @@ -126,7 +137,12 @@ ansible-playbook --timeout 60 ./community.sap_launchpad/playbooks/sample-downloa
suser_id: "{{ suser_id }}"
suser_password: "{{ suser_password }}"
softwarecenter_search_query: "{{ item }}"
with_items: "{{ softwarecenter_search_list }}"
loop: "{{ softwarecenter_search_list }}"
loop_control:
label: "{{ item }} : {{ download_task.msg }}"
register: download_task
retries: 1
until: download_task is not failed

```

Expand Down
2 changes: 1 addition & 1 deletion docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The error HTTP 401 refers to either:
- Unauthorized, the SAP User ID is part of an SAP Universal ID and must use the password of the SAP Universal ID
- In addition, if a SAP Universal ID is used then the recommendation is to check and reset the SAP User ID ‘Account Password’ in the [SAP Universal ID Account Manager](https://account.sap.com/manage/accounts), which will help to avoid any potential conflicts.

This is documented under [Ansible Collection for SAP Launchpad - Requirements, Dependencies and Testing](https://github.com/sap-linuxlab/community.sap_launchpad#requirements-dependencies-and-testing)
This is documented under [Execution - Credentials](https://github.com/sap-linuxlab/community.sap_launchpad#requirements-dependencies-and-testing).

### <samp>'SAP SSO authentication failed - 404 Client Error: Not Found for url: `https://origin.softwaredownloads.sap.com/tokengen/?file=___`'</samp>

Expand Down
19 changes: 12 additions & 7 deletions playbooks/sample-download-install-media.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@

# Use task block to call Ansible Module
tasks:
- name: Execute Ansible Module to download SAP software
community.sap_launchpad.software_center_download:
suser_id: "{{ suser_id }}"
suser_password: "{{ suser_password }}"
softwarecenter_search_query: "{{ item }}"
dest: "/tmp/"
with_items: "{{ softwarecenter_search_list }}"
- name: Execute Ansible Module to download SAP software
community.sap_launchpad.software_center_download:
suser_id: "{{ suser_id }}"
suser_password: "{{ suser_password }}"
softwarecenter_search_query: "{{ item }}"
dest: "/tmp/"
loop: "{{ softwarecenter_search_list }}"
loop_control:
label: "{{ item }} : {{ download_task.msg }}"
register: download_task
retries: 1
until: download_task is not failed
33 changes: 19 additions & 14 deletions playbooks/sample-maintenance-planner-files-download.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,27 @@

# Use task block to call Ansible Module
tasks:
- name: Execute Ansible Module 'maintenance_planner_files' to get files from MP
community.sap_launchpad.maintenance_planner_files:
suser_id: "{{ suser_id }}"
suser_password: "{{ suser_password }}"
transaction_name: "{{ mp_transaction_name }}"
register: sap_maintenance_planner_basket_register
- name: Execute Ansible Module 'maintenance_planner_files' to get files from MP
community.sap_launchpad.maintenance_planner_files:
suser_id: "{{ suser_id }}"
suser_password: "{{ suser_password }}"
transaction_name: "{{ mp_transaction_name }}"
register: sap_maintenance_planner_basket_register

# - debug:
# msg:
# - "{{ sap_maintenance_planner_basket_register.download_basket }}"

- name: Execute Ansible Module 'software_center_download' to download files
community.sap_launchpad.software_center_download:
suser_id: "{{ suser_id }}"
suser_password: "{{ suser_password }}"
download_link: "{{ item.DirectLink }}"
download_filename: "{{ item.Filename }}"
dest: "/tmp/test"
loop: "{{ sap_maintenance_planner_basket_register.download_basket }}"
- name: Execute Ansible Module 'software_center_download' to download files
community.sap_launchpad.software_center_download:
suser_id: "{{ suser_id }}"
suser_password: "{{ suser_password }}"
download_link: "{{ item.DirectLink }}"
download_filename: "{{ item.Filename }}"
dest: "/tmp/test"
loop: "{{ sap_maintenance_planner_basket_register.download_basket }}"
loop_control:
label: "{{ item }} : {{ download_task.msg }}"
register: download_task
retries: 1
until: download_task is not failed
10 changes: 8 additions & 2 deletions plugins/modules/software_center_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
#########################

import requests
import glob
from ansible.module_utils.basic import AnsibleModule

# Import runner
Expand Down Expand Up @@ -132,10 +133,15 @@ def run_module():
# Main run

try:

# Search directory and subdirectories for filename without file extension
filename = query if query else download_filename
if os.path.exists(os.path.join(dest, filename)):
module.exit_json(skipped=True, msg="file {} already exists".format(filename))
pattern = dest + '/**/' + os.path.splitext(filename)[0] + '*'
for file in glob.glob(pattern, recursive=True):
if os.path.exists(file):
module.exit_json(skipped=True, msg="file {} already exists".format(file))

# Initiate login with given credentials
sap_sso_login(username, password)

# EXEC: query
Expand Down

0 comments on commit 52a97e0

Please sign in to comment.