Skip to content

Commit

Permalink
sap_swpm: Add support for HA virtual hostname resolution
Browse files Browse the repository at this point in the history
Signed-off-by: Bernd Finger <[email protected]>
  • Loading branch information
berndfinger committed Oct 28, 2024
1 parent c12fa43 commit 54c4ed7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
6 changes: 4 additions & 2 deletions roles/sap_swpm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,9 @@ Define DDIC user password in client 000 for new install, or existing for restore
- _Type:_ `string`

Define virtual hostname when installing High Available instances (e.g. SAP ASCS/ERS cluster).

The role attempts to resolve `sap_swpm_virtual_hostname` on the managed node, using DNS and /etc/hosts, and will fail
if this hostname resolution fails. The role will also fail if the IPv4 address for `sap_swpm_virtual_hostname` is
not part of the IPv4 addresses of the managed node.

### Variables specific to SAP HANA Database Installation

Expand Down Expand Up @@ -856,4 +858,4 @@ Set owner for all non-SAPCAR files in `sap_swpm_software_path` and for SWPM*.SAR
- _Default:_ `root`

Set group ownership for all non-SAPCAR files in `sap_swpm_software_path` and for SWPM*.SAR files in `sap_swpm_swpm_path`.
<!-- END Role Variables -->
<!-- END Role Variables -->
2 changes: 1 addition & 1 deletion roles/sap_swpm/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ sap_swpm_ddic_000_password:

# initial = not an HA setup
# set this in the input file when installing ascs, ers to indicate an HA setup
sap_swpm_virtual_hostname: "initial"
sap_swpm_virtual_hostname:


########################################
Expand Down
12 changes: 12 additions & 0 deletions roles/sap_swpm/tasks/pre_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@

# /etc/hosts

- name: SAP SWPM Pre Install - Assert hostname resolution for HA
ansible.builtin.include_tasks:
file: pre_install/assert_hostname_resolution_for_ha.yml
apply:
tags: sap_swpm_update_etchosts
when:
- sap_swpm_run_sapinst
- sap_swpm_update_etchosts
- sap_swpm_virtual_hostname | type_debug != 'NoneType'
- sap_swpm_virtual_hostname | length > 0
tags: sap_swpm_update_etchosts

- name: SAP SWPM Pre Install - Update /etc/hosts
ansible.builtin.include_tasks:
file: pre_install/update_etchosts.yml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# SPDX-License-Identifier: Apache-2.0
---

# Assert HA settings

- name: SAP SWPM Pre Install - HA settings - Ensure the dig command is present
ansible.builtin.package:
name: bind-utils
state: present

- name: SAP SWPM Pre Install - HA settings - Try to resolve sap_swpm_virtual_hostname from DNS
ansible.builtin.command: dig +short +tries=1 +time=1 "{{ sap_swpm_virtual_hostname }}"
register: __sap_swpm_register_virtual_ip_dns
changed_when: false
failed_when: false

- name: SAP SWPM Pre Install - HA settings - Assign sap_swpm_virtual_ip from DNS
ansible.builtin.set_fact:
__sap_swpm_fact_virtual_ip: "{{ __sap_swpm_register_virtual_ip_dns.stdout_lines[-1] }}"
when: __sap_swpm_register_virtual_ip_dns.stdout_lines | length > 0

- name: SAP SWPM Pre Install - HA settings - Try using /etc/hosts for name resolution
when: __sap_swpm_register_virtual_ip_dns.stdout_lines | length == 0
block:

- 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
register: __sap_swpm_register_virtual_ip_etc_hosts
changed_when: false
failed_when: false

- name: SAP SWPM Pre Install - HA settings - Assign sap_swpm_virtual_ip from /etc/hosts
ansible.builtin.set_fact:
__sap_swpm_fact_virtual_ip: "{{ __sap_swpm_register_virtual_ip_etc_hosts.stdout_lines[-1] }}"
when: __sap_swpm_register_virtual_ip_etc_hosts.stdout_lines | length > 0

- 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 | length > 0
fail_msg: "FAIL: sap_swpm_virtual_hostname cannot be resolved!"
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
ansible.builtin.assert:
that: __sap_swpm_fact_virtual_ip in ansible_all_ipv4_addresses
fail_msg: "FAIL: __sap_swpm_fact_virtual_ip is not part of ansible_all_ipv4_addresses!"
success_msg: "PASS: __sap_swpm_fact_virtual_ip is part of ansible_all_ipv4_addresses."

0 comments on commit 54c4ed7

Please sign in to comment.