From c1ec50309c86efcf87559c54f734d0cb3b693841 Mon Sep 17 00:00:00 2001 From: Bernd Finger Date: Wed, 6 Nov 2024 11:12:36 +0100 Subject: [PATCH] sap_swpm: Fix /etc/hosts ip address resolution Also modify the fail_msg to not resolve sap_swpm_virtual_hostname Signed-off-by: Bernd Finger --- .../tasks/pre_install/assert_hostname_resolution_for_ha.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/roles/sap_swpm/tasks/pre_install/assert_hostname_resolution_for_ha.yml b/roles/sap_swpm/tasks/pre_install/assert_hostname_resolution_for_ha.yml index c97fbcd4..4f9e075a 100644 --- a/roles/sap_swpm/tasks/pre_install/assert_hostname_resolution_for_ha.yml +++ b/roles/sap_swpm/tasks/pre_install/assert_hostname_resolution_for_ha.yml @@ -23,9 +23,10 @@ when: __sap_swpm_register_virtual_ip_dns.stdout_lines | length == 0 block: +# We assign the IP address only if there is exactly one line containing ipv4 and hostname: - name: SAP SWPM Pre Install - HA settings - Try to resolve sap_swpm_virtual_hostname from /etc/hosts ansible.builtin.shell: | - awk '/^[^#]/&&(/\s{{ sap_swpm_virtual_hostname }}\./||/\s{{ sap_swpm_virtual_hostname }}/){print $1}' /etc/hosts + awk 'BEGIN{a=0}/^[^#]/&&(/\s{{ sap_swpm_virtual_hostname }}\./||/\s{{ sap_swpm_virtual_hostname }}/){a++; ipaddr=$1}END{if(a==1){print ipaddr}}' /etc/hosts register: __sap_swpm_register_virtual_ip_etc_hosts changed_when: false failed_when: false @@ -38,7 +39,7 @@ - name: SAP SWPM Pre Install - HA settings - Assert that sap_swpm_virtual_hostname can be resolved ansible.builtin.assert: that: __sap_swpm_fact_virtual_ip is defined and __sap_swpm_fact_virtual_ip | length > 0 - fail_msg: "FAIL: {{ sap_swpm_virtual_hostname }} cannot be resolved!" + fail_msg: "FAIL: 'sap_swpm_virtual_hostname' is not defined or cannot be resolved correctly!" success_msg: "PASS: {{ sap_swpm_virtual_hostname }} can be resolved." - name: SAP SWPM Pre Install - HA settings - Assert that sap_swpm_fact_virtual_ip is part of ansible_all_ipv4_addresses