From c1def5b52c6cba842221e8c0c05cb0c546c96650 Mon Sep 17 00:00:00 2001 From: Bernd Finger Date: Wed, 20 Nov 2024 16:22:40 +0100 Subject: [PATCH] sap_swpm: Fix issues with localhost delegation on certain control nodes Solves issue #890. Signed-off-by: Bernd Finger --- .../detect_variables_from_inifile.yml | 20 +++----- .../tasks/pre_install/generate_inifile.yml | 49 +++---------------- .../tasks/pre_install/swpm_prepare.yml | 10 ---- 3 files changed, 15 insertions(+), 64 deletions(-) diff --git a/roles/sap_swpm/tasks/pre_install/detect_variables_from_inifile.yml b/roles/sap_swpm/tasks/pre_install/detect_variables_from_inifile.yml index 54137896..a70e6479 100644 --- a/roles/sap_swpm/tasks/pre_install/detect_variables_from_inifile.yml +++ b/roles/sap_swpm/tasks/pre_install/detect_variables_from_inifile.yml @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/roles/sap_swpm/tasks/pre_install/generate_inifile.yml b/roles/sap_swpm/tasks/pre_install/generate_inifile.yml index 53f4809f..979bb063 100644 --- a/roles/sap_swpm/tasks/pre_install/generate_inifile.yml +++ b/roles/sap_swpm/tasks/pre_install/generate_inifile.yml @@ -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 @@ -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 @@ -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 }}" @@ -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: @@ -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'" diff --git a/roles/sap_swpm/tasks/pre_install/swpm_prepare.yml b/roles/sap_swpm/tasks/pre_install/swpm_prepare.yml index f2ae6cb6..6a1915ed 100644 --- a/roles/sap_swpm/tasks/pre_install/swpm_prepare.yml +++ b/roles/sap_swpm/tasks/pre_install/swpm_prepare.yml @@ -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