From b5f0410fe006ab9edfb80fa8c89ce946eb55e089 Mon Sep 17 00:00:00 2001 From: Bernd Finger Date: Wed, 3 Jan 2024 21:52:10 +0100 Subject: [PATCH] preconfigure roles: Avoid role aborts during assert runs Solves issue #571. Signed-off-by: Bernd Finger --- .../tasks/RedHat/assert-installation.yml | 8 ++++++-- .../tasks/RedHat/generic/assert-tuned.yml | 2 +- .../sap_netweaver_preconfigure/tasks/sapnote/2526952.yml | 8 ++++---- .../tasks/sapnote/assert-2526952.yml | 8 +++++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/roles/sap_hana_preconfigure/tasks/RedHat/assert-installation.yml b/roles/sap_hana_preconfigure/tasks/RedHat/assert-installation.yml index 4e7ddd803..1a829bacc 100644 --- a/roles/sap_hana_preconfigure/tasks/RedHat/assert-installation.yml +++ b/roles/sap_hana_preconfigure/tasks/RedHat/assert-installation.yml @@ -85,9 +85,13 @@ ### # /opt/ibm/lop/configure ### # yum -y install ibm-power-managed-rhel7 ### -- name: Get install status of required IBM packages +# Reasons for noqa: +# command-instead-of-module: I need to examine the output of the yum info command. +# risky-shell-pipe: If a package is not installed, the shell command will fail. But I want the command to +# succeed so that the awk command can examine the result. +- name: Get install status of required IBM packages # noqa command-instead-of-module risky-shell-pipe ansible.builtin.shell: | - set -o pipefail && yum info installed {{ __sap_hana_preconfigure_required_ppc64le | map('quote') | join(' ') }} | + yum info installed {{ __sap_hana_preconfigure_required_ppc64le | map('quote') | join(' ') }} | awk '/Name/{n=$NF}/Version/{v=$NF}/Release/{r=$NF}/Description/{printf ("%s\n", n)}' register: __sap_hana_preconfigure_register_required_ppc64le_packages_assert changed_when: no diff --git a/roles/sap_hana_preconfigure/tasks/RedHat/generic/assert-tuned.yml b/roles/sap_hana_preconfigure/tasks/RedHat/generic/assert-tuned.yml index 29cccaff0..91ca78fc4 100644 --- a/roles/sap_hana_preconfigure/tasks/RedHat/generic/assert-tuned.yml +++ b/roles/sap_hana_preconfigure/tasks/RedHat/generic/assert-tuned.yml @@ -70,7 +70,7 @@ sap_hana_preconfigure_assert_all_config)" - name: Get active tuned profile - ansible.builtin.shell: /usr/sbin/tuned-adm active | grep ":" | cut -d ":" -f 2 | awk '{$1=$1;print}' + ansible.builtin.shell: set -o pipefail && /usr/sbin/tuned-adm active | awk '/:/{print $NF}' check_mode: no register: __sap_hana_preconfigure_register_current_tuned_profile_assert ignore_errors: yes diff --git a/roles/sap_netweaver_preconfigure/tasks/sapnote/2526952.yml b/roles/sap_netweaver_preconfigure/tasks/sapnote/2526952.yml index e0a6bf9fd..19997a328 100644 --- a/roles/sap_netweaver_preconfigure/tasks/sapnote/2526952.yml +++ b/roles/sap_netweaver_preconfigure/tasks/sapnote/2526952.yml @@ -14,11 +14,11 @@ ansible.builtin.service: name: tuned state: started - enabled: yes + enabled: true - name: Show currently active tuned profile ansible.builtin.shell: set -o pipefail && /usr/sbin/tuned-adm active | awk '/:/{print $NF}' - check_mode: no + check_mode: false register: __sap_netweaver_preconfigure_register_current_tuned_profile changed_when: false @@ -39,8 +39,8 @@ changed_when: true - name: Show new active tuned profile - ansible.builtin.shell: set -o pipefail && /usr/sbin/tuned-adm active | awk '{print $NF}' - check_mode: no + ansible.builtin.shell: set -o pipefail && /usr/sbin/tuned-adm active | awk '/:/{print $NF}' + check_mode: false register: __sap_netweaver_preconfigure_register_new_tuned_profile changed_when: false diff --git a/roles/sap_netweaver_preconfigure/tasks/sapnote/assert-2526952.yml b/roles/sap_netweaver_preconfigure/tasks/sapnote/assert-2526952.yml index 1cada2e82..6fc7a4b61 100644 --- a/roles/sap_netweaver_preconfigure/tasks/sapnote/assert-2526952.yml +++ b/roles/sap_netweaver_preconfigure/tasks/sapnote/assert-2526952.yml @@ -39,17 +39,19 @@ when: "'tuned-profiles-sap' in ansible_facts.packages" - name: Get active tuned profile - ansible.builtin.shell: set -o pipefail && /usr/sbin/tuned-adm active | grep ":" | cut -d ":" -f 2 | awk '{$1=$1;print}' - check_mode: no + ansible.builtin.shell: set -o pipefail && /usr/sbin/tuned-adm active | awk '/:/{print $NF}' + check_mode: false register: __sap_netweaver_preconfigure_register_current_tuned_profile + ignore_errors: true changed_when: false - name: Assert - Display the output of the tuned-adm active command ansible.builtin.debug: var: __sap_netweaver_preconfigure_register_current_tuned_profile.stdout_lines, __sap_netweaver_preconfigure_register_current_tuned_profile.stderr_lines + ignore_errors: true -- name: Assert that tuned profile sap-netweaver is currently active +- name: Assert that tuned profile 'sap-netweaver' is currently active ansible.builtin.assert: that: __sap_netweaver_preconfigure_register_current_tuned_profile.stdout == 'sap-netweaver' fail_msg: "FAIL: The tuned profile 'sap-netweaver' is currently not active!