|
| 1 | +# Developer notes for community.sap_launchpad Ansible Collection |
| 2 | + |
| 3 | +This document contains details for maintaining Ansible Collection. |
| 4 | + |
| 5 | +## Dependencies for all modules |
| 6 | +Modules require the following Python modules to be installed on the target node (the machine where SAP software will be downloaded): |
| 7 | + |
| 8 | +- wheel |
| 9 | +- urllib3 |
| 10 | +- requests |
| 11 | +- beautifulsoup4 |
| 12 | +- lxml |
| 13 | + |
| 14 | +### Installation of dependencies using role `sap_software_download` |
| 15 | +Ansible Role `sap_software_download` installs all required dependencies as part of `02_prepare_python_environment.yml` task file. |
| 16 | + |
| 17 | +### Installation of dependencies with Python Virtual Environment (venv) |
| 18 | +It is recommended to install dependencies in venv that can be removed after execution is completed. |
| 19 | +```yaml |
| 20 | +- name: Example play to install prerequisites with Python Virtual Environment |
| 21 | + hosts: all |
| 22 | + tasks: |
| 23 | + - name: Create temporary directory for Python Virtual Environment |
| 24 | + ansible.builtin.tempfile: |
| 25 | + state: directory |
| 26 | + suffix: __sap_software_download_venv |
| 27 | + register: __sap_software_download_venv |
| 28 | + |
| 29 | + - name: Install Python and Python package manager pip |
| 30 | + ansible.builtin.package: |
| 31 | + name: |
| 32 | + - python311 |
| 33 | + - python311-pip |
| 34 | + state: present |
| 35 | + |
| 36 | + - name: Install Python modules to Python Virtual Environment |
| 37 | + ansible.builtin.pip: |
| 38 | + name: |
| 39 | + - wheel |
| 40 | + - urllib3 |
| 41 | + - requests |
| 42 | + - beautifulsoup4 |
| 43 | + - lxml |
| 44 | + virtualenv: "{{ __sap_software_download_venv.path }}" |
| 45 | + virtualenv_command: "python3.11 -m venv" |
| 46 | + |
| 47 | + - name: Remove temporary Python Virtual Environment |
| 48 | + ansible.builtin.file: |
| 49 | + path: "{{ __sap_software_download_venv.path }}" |
| 50 | + state: absent |
| 51 | +``` |
| 52 | +
|
| 53 | +### Installation of dependencies with Python system default |
| 54 | +```yaml |
| 55 | +- name: Example play to install prerequisites with Python system default |
| 56 | + hosts: all |
| 57 | + tasks: |
| 58 | + - name: Install Python and Python package manager pip |
| 59 | + ansible.builtin.package: |
| 60 | + name: |
| 61 | + - python31 |
| 62 | + - python311-pip |
| 63 | + state: present |
| 64 | + |
| 65 | + - name: Install Python modules to Python system default |
| 66 | + ansible.builtin.pip: |
| 67 | + name: |
| 68 | + - wheel |
| 69 | + - urllib3 |
| 70 | + - requests |
| 71 | + - beautifulsoup4 |
| 72 | + - lxml |
| 73 | +``` |
| 74 | +
|
| 75 | +## Additional execution methods |
| 76 | +### Execution of Ansible Playbook, with in-line Ansible Inventory set as localhost |
| 77 | +
|
| 78 | +```shell |
| 79 | +# Install from local source directory for Ansible 2.11+ |
| 80 | +ansible-galaxy collection install community.sap_launchpad |
| 81 | + |
| 82 | +# Workaround install from local source directory for Ansible 2.9.x |
| 83 | +# mv ./community.sap_launchpad ~/.ansible/collections/ansible_collections/community |
| 84 | + |
| 85 | +# Run Ansible Collection on localhost |
| 86 | +ansible-playbook --timeout 60 ./community.sap_launchpad/playbooks/sample-download-install-media.yml --inventory "localhost," --connection=local |
| 87 | +``` |
| 88 | + |
| 89 | +### Execution of Ansible Playbook, with in-line Ansible Inventory of target/remote hosts |
| 90 | + |
| 91 | +```shell |
| 92 | +# Install from local source directory for Ansible 2.11+ |
| 93 | +ansible-galaxy collection install ./community.sap_launchpad |
| 94 | + |
| 95 | +# Workaround install from local source directory for Ansible 2.9.x |
| 96 | +# mv ./community.sap_launchpad ~/.ansible/collections/ansible_collections/community |
| 97 | + |
| 98 | +# SSH Connection details |
| 99 | +bastion_private_key_file="$PWD/bastion_rsa" |
| 100 | +bastion_host="169.0.40.4" |
| 101 | +bastion_port="50222" |
| 102 | +bastion_user="bastionuser" |
| 103 | + |
| 104 | +target_private_key_file="$PWD/vs_rsa" |
| 105 | +target_host="10.0.50.5" |
| 106 | +target_user="root" |
| 107 | + |
| 108 | +# Run Ansible Collection to target/remote hosts via Proxy/Bastion |
| 109 | +ansible-playbook --timeout 60 ./sample-playbook.yml \ |
| 110 | +--connection 'ssh' --user "$target_user" --inventory "$target_host," --private-key "$target_private_key_file" \ |
| 111 | +--ssh-extra-args="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ProxyCommand='ssh -W %h:%p $bastion_user@$bastion_host -p $bastion_port -i $bastion_private_key_file -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'" |
| 112 | +``` |
| 113 | + |
| 114 | +## Execution of Python Modules directly |
| 115 | +### Setup local Python environment |
| 116 | +```shell |
| 117 | +# Change directory to Python scripts source |
| 118 | +cd ./plugins |
| 119 | + |
| 120 | +# Create isolated Python (protect system Python) |
| 121 | +pyenv install 3.9.6 |
| 122 | +pyenv virtualenv 3.9.6 sap_launchpad |
| 123 | +pyenv activate sap_launchpad |
| 124 | + |
| 125 | +# Install Python Modules to current Python environment |
| 126 | +pip3 install beautifulsoup4 lxml requests |
| 127 | + |
| 128 | +# Run Python, import Python Modules and run Python Functions |
| 129 | +python3 |
| 130 | +``` |
| 131 | + |
| 132 | +### Execute Python Functions |
| 133 | +```python |
| 134 | +>>> from module_utils.sap_id_sso import sap_sso_login |
| 135 | +>>> from module_utils.sap_launchpad_software_center_download_runner import * |
| 136 | +>>> |
| 137 | +>>> # Debug |
| 138 | +>>> # from module_utils.sap_api_common import debug_https |
| 139 | +>>> # debug_https() |
| 140 | +>>> |
| 141 | +>>> ## Perform API login requests to SAP Support |
| 142 | +>>> username='S0000000' |
| 143 | +>>> password='password' |
| 144 | +>>> sap_sso_login(username, password) |
| 145 | +>>> ## Perform API activity requests to SAP Support (e.g. software search without deduplication, and download software) |
| 146 | +>>> query_result = search_software_filename("HCMT_057_0-80003261.SAR",'') |
| 147 | +>>> download_software(*query_result, output_dir='/tmp') |
| 148 | +... |
| 149 | +>>> ## API responses from SAP Support |
| 150 | +>>> exit() |
| 151 | +``` |
0 commit comments