Skip to content

Commit

Permalink
sap_swpm: Fix issues with localhost delegation on certain control nodes
Browse files Browse the repository at this point in the history
Solves issue #890.

Signed-off-by: Bernd Finger <[email protected]>
  • Loading branch information
berndfinger committed Nov 20, 2024
1 parent 0822cb5 commit c1def5b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 64 deletions.
20 changes: 8 additions & 12 deletions roles/sap_swpm/tasks/pre_install/detect_variables_from_inifile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
ansible.builtin.command: |
awk 'BEGIN{IGNORECASE=1;a=0}
/Product ID/&&a==0{a=1; gsub ("#", ""); gsub ("\047", ""); product_id=$NF}
END{print product_id}' {{ sap_swpm_tmpdir_local.path }}/inifile.params
delegate_to: localhost
END{print product_id}' {{ sap_swpm_tmpdir.path }}/inifile.params
register: sap_swpm_inifile_product_id_detect
changed_when: false

- name: SAP SWPM Pre Install - Report if 'sap_swpm_product_catalog_id' has been defined differently
ansible.builtin.debug:
msg: "NOTE: The Product ID in '{{ sap_swpm_tmpdir_local.path }}/inifile.params' is different from the role parameter 'sap_swpm_inifile_product_id_detect'."
msg: "NOTE: The Product ID in '{{ sap_swpm_tmpdir.path }}/inifile.params' is different from the role parameter 'sap_swpm_inifile_product_id_detect'."
when:
- sap_swpm_product_catalog_id
- sap_swpm_inifile_product_id_detect.stdout != sap_swpm_product_catalog_id
Expand All @@ -25,14 +24,13 @@
# Detect and set Software Path
- name: SAP SWPM Pre Install - Detect Software Path from inifile
ansible.builtin.command: |
awk '!/^#/&&/archives.downloadBasket/{print $3}' {{ sap_swpm_tmpdir_local.path }}/inifile.params
delegate_to: localhost
awk '!/^#/&&/archives.downloadBasket/{print $3}' {{ sap_swpm_tmpdir.path }}/inifile.params
register: sap_swpm_inifile_software_path_detect
changed_when: false

- name: SAP SWPM Pre Install - Report if 'sap_swpm_software_path' has been defined differently
ansible.builtin.debug:
msg: "NOTE: The Software Path in '{{ sap_swpm_tmpdir_local.path }}/inifile.params' is different from the role parameter 'sap_swpm_software_path'."
msg: "NOTE: The Software Path in '{{ sap_swpm_tmpdir.path }}/inifile.params' is different from the role parameter 'sap_swpm_software_path'."
when:
- sap_swpm_software_path
- sap_swpm_inifile_software_path_detect.stdout != sap_swpm_software_path
Expand All @@ -44,14 +42,13 @@
# Detect and set SID
- name: SAP SWPM Pre Install - Detect SID from inifile
ansible.builtin.command: |
awk '!/^#/&&/NW_GetSidNoProfiles.sid/{print $3}' {{ sap_swpm_tmpdir_local.path }}/inifile.params
delegate_to: localhost
awk '!/^#/&&/NW_GetSidNoProfiles.sid/{print $3}' {{ sap_swpm_tmpdir.path }}/inifile.params
register: sap_swpm_inifile_sid_detect
changed_when: false

- name: SAP SWPM Pre Install - Report if 'sap_swpm_sid' has been defined differently
ansible.builtin.debug:
msg: "NOTE: The SID in '{{ sap_swpm_tmpdir_local.path }}/inifile.params' is different from the role parameter 'sap_swpm_sid'."
msg: "NOTE: The SID in '{{ sap_swpm_tmpdir.path }}/inifile.params' is different from the role parameter 'sap_swpm_sid'."
when:
- sap_swpm_sid
- sap_swpm_inifile_sid_detect.stdout != sap_swpm_sid
Expand All @@ -63,14 +60,13 @@
# Detect and set FQDN
- name: SAP SWPM Pre Install - Detect FQDN from inifile
ansible.builtin.command: |
awk '!/^#/&&/NW_getFQDN.FQDN/{print $3}' {{ sap_swpm_tmpdir_local.path }}/inifile.params
delegate_to: localhost
awk '!/^#/&&/NW_getFQDN.FQDN/{print $3}' {{ sap_swpm_tmpdir.path }}/inifile.params
register: sap_swpm_inifile_fqdn_detect
changed_when: false

- name: SAP SWPM Pre Install - Report if 'sap_swpm_fqdn' has been defined differently
ansible.builtin.debug:
msg: "NOTE: The FQDN in '{{ sap_swpm_tmpdir_local.path }}/inifile.params' is different from the role parameter 'sap_swpm_fqdn'."
msg: "NOTE: The FQDN in '{{ sap_swpm_tmpdir.path }}/inifile.params' is different from the role parameter 'sap_swpm_fqdn'."
when:
- sap_swpm_fqdn
- sap_swpm_inifile_sid_detect.stdout != sap_swpm_fqdn
Expand Down
49 changes: 7 additions & 42 deletions roles/sap_swpm/tasks/pre_install/generate_inifile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,19 @@
ansible.builtin.debug:
msg: "INFO: Using existing sapinst inifile '{{ sap_swpm_inifile_directory }}/inifile.params'."

# Note: Attempting to fetch and store into sap_swpm_tmpdir_local.path results in a 'Permission denied' error.
# So we are using 'slurp' and 'copy' for this purpose.
- name: SAP SWPM Pre Install, existing inifile - Slurp the remote 'inifile.params' for copying to control node
ansible.builtin.slurp:
src: "{{ sap_swpm_inifile_directory }}/inifile.params"
register: sap_swpm_slurped_remote_inifile

- name: SAP SWPM Pre Install, existing inifile - Copy 'inifile.params' to the control node
# - name: SAP SWPM Pre Install, existing inifile - Copy 'inifile.params' to the control node
- name: SAP SWPM Pre Install, existing inifile - Copy 'inifile.params' to sap_swpm_tmpdir
ansible.builtin.copy:
content: "{{ sap_swpm_slurped_remote_inifile['content'] | b64decode }}"
dest: "{{ sap_swpm_tmpdir_local.path }}/inifile.params"
src: "{{ sap_swpm_inifile_directory }}/inifile.params"
dest: "{{ sap_swpm_tmpdir.path }}/inifile.params"
owner: 'root'
group: 'root'
mode: '0640'
delegate_to: localhost

# Now we need to confirm that des25 is not in the inifile
- name: SAP SWPM Pre Install, existing inifile - Search inifile for for des25
ansible.builtin.shell: |
set -o pipefail && awk 'BEGIN{a=0}!/^#/&&/des25\(/{a++}END{print a}' {{ sap_swpm_tmpdir_local.path }}/inifile.params
delegate_to: localhost
set -o pipefail && awk 'BEGIN{a=0}!/^#/&&/des25\(/{a++}END{print a}' {{ sap_swpm_tmpdir.path }}/inifile.params
register: sap_swpm_inifile_count_des25
changed_when: false

Expand Down Expand Up @@ -123,11 +115,10 @@
- name: SAP SWPM Pre Install, create inifile - Process SWPM inifile template for for creating 'inifile.params'
ansible.builtin.template:
src: "{{ role_path }}/templates/inifile_params.j2"
dest: "{{ sap_swpm_tmpdir_local.path }}/inifile.params"
dest: "{{ sap_swpm_tmpdir.path }}/inifile.params"
owner: 'root'
group: 'root'
mode: '0640'
delegate_to: localhost
when:
- sap_swpm_inifile_sections_list is defined
- sap_swpm_inifile_sections_list | length > 0
Expand All @@ -141,7 +132,7 @@

- name: SAP SWPM Pre Install, create inifile - Configure entries in 'inifile.params' from 'sap_swpm_inifile_parameters_dict'
ansible.builtin.lineinfile:
path: "{{ sap_swpm_tmpdir_local.path }}/inifile.params"
path: "{{ sap_swpm_tmpdir.path }}/inifile.params"
create: true
state: present
line: "{{ sap_swpm_line_item.key }} = {{ sap_swpm_line_item.value }}"
Expand All @@ -153,12 +144,10 @@
loop_control:
loop_var: sap_swpm_line_item
register: replace_result
delegate_to: localhost

- name: SAP SWPM Pre Install, create inifile - Detect variables again if 'sap_swpm_inifile_parameters_dict' had been used
ansible.builtin.import_tasks:
file: detect_variables_from_inifile.yml
delegate_to: localhost

- name: SAP SWPM Pre Install, create inifile - Display these variables again if 'sap_swpm_inifile_parameters_dict' had been used
ansible.builtin.debug:
Expand All @@ -167,27 +156,3 @@
- "sap_swpm_software_path: >{{ sap_swpm_software_path }}<"
- "sap_swpm_sid: >{{ sap_swpm_sid }}<"
- "sap_swpm_fqdn: >{{ sap_swpm_fqdn }}<"
delegate_to: localhost

- name: SAP SWPM Pre Install - Display the path of the local 'inifile.params'
ansible.builtin.debug:
msg: "The local inifile.params is: '{{ sap_swpm_tmpdir_local.path }}/inifile.params'"
tags: sap_swpm_generate_inifile

- name: SAP SWPM Pre Install - Slurp the local 'inifile.params' for copying to managed node
ansible.builtin.slurp:
src: "{{ sap_swpm_tmpdir_local.path }}/inifile.params"
register: sap_swpm_slurped_local_inifile
delegate_to: localhost

- name: SAP SWPM Pre Install - Copy 'inifile.params' to the managed node
ansible.builtin.copy:
content: "{{ sap_swpm_slurped_local_inifile['content'] | b64decode }}"
dest: "{{ sap_swpm_tmpdir.path }}/inifile.params"
owner: 'root'
group: 'root'
mode: '0640'

- name: SAP SWPM Pre Install - Display the path of the remote 'inifile.params'
ansible.builtin.debug:
msg: "The local inifile.params has been copied to: '{{ sap_swpm_tmpdir.path }}/inifile.params'"
10 changes: 0 additions & 10 deletions roles/sap_swpm/tasks/pre_install/swpm_prepare.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
---

- name: SAP SWPM Pre Install - Create temporary directory on control node
ansible.builtin.tempfile:
state: directory
suffix: _swpm_tmp
delegate_to: localhost
register: sap_swpm_tmpdir_local
tags:
- sap_swpm_generate_inifile
- sap_swpm_sapinst_commandline

- name: SAP SWPM Pre Install - Create temporary directory on managed node
ansible.builtin.tempfile:
state: directory
Expand Down

0 comments on commit c1def5b

Please sign in to comment.