Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sap_ha_install_anydb_ibmdb2: experimental new role #545

Merged
merged 12 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions roles/sap_ha_install_anydb_ibmdb2/.ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
enable_list:
- yaml
skip_list:
- ignore-errors # We use ignore_errors for all the assert tasks, which should be acceptable
sean-freeman marked this conversation as resolved.
Show resolved Hide resolved
- schema # We want to allow single digit version numbers in a role's meta/main.yml file. This is allowed as per https://galaxy.ansible.com/docs/contributing/creating_role.html and https://galaxy.ansible.com/api/v1/platforms/?page=6.
- name[template] # Allow templating inside name. During dev and qa, it should be possible to identify cases where it doesn't work
21 changes: 21 additions & 0 deletions roles/sap_ha_install_anydb_ibmdb2/.yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
# Based on ansible-lint config
extends: default

rules:
braces: {max-spaces-inside: 1, level: error}
brackets: {max-spaces-inside: 1, level: error}
# colons: {max-spaces-after: -1, level: error}
# commas: {max-spaces-after: -1, level: error}
comments: disable
comments-indentation: disable
# document-start: disable
# empty-lines: {max: 3, level: error}
# hyphens: {level: error}
# indentation: disable
# key-duplicates: enable
line-length: disable
# new-line-at-end-of-file: disable
# new-lines: {type: unix}
# trailing-spaces: disable
truthy: disable
65 changes: 65 additions & 0 deletions roles/sap_ha_install_anydb_ibmdb2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
`EXPERIMENTAL`

# sap_ha_install_anydb_ibmdb2 Ansible Role

Ansible Role for instantiation of IBM Db2 “Integrated Linux Pacemaker” HADR cluster
sean-freeman marked this conversation as resolved.
Show resolved Hide resolved
sean-freeman marked this conversation as resolved.
Show resolved Hide resolved

Note: IBM Db2 with “Integrated Linux Pacemaker” can use two deployment models:
sean-freeman marked this conversation as resolved.
Show resolved Hide resolved
- Mutual Failover option, not covered by this Ansible Role
- High Availability and Disaster Recovery (HADR) option for Idle Standby, initialised by this Ansible Role


## Prerequisites

### Software Installation files

Download IBM Db2 installation media from SAP Download Center on host, and set Ansible Variable `sap_ha_install_anydb_ibmdb2_software_directory` to this path.

### Variables

- `sap_ha_install_anydb_ibmdb2_hostname_primary` with the IBM Db2 Primary node hostname
- `sap_ha_install_anydb_ibmdb2_hostname_secondary` with the IBM Db2 Secondary node hostname
- `sap_ha_install_anydb_ibmdb2_sid` with the IBM Db2 System ID
- `sap_ha_install_anydb_ibmdb2_software_directory` with the IBM Db2 installation media path

These are listed in the default variables file, but commented-out to enforce the required variables:
- [**sap_ha_install_anydb_ibmdb2** default parameters](defaults/main.yml)

## Execution

Sample Ansible Playbook Execution:

- Local Host Installation
- `ansible-playbook --connection=local --limit localhost -i "localhost," sap-ha-anydb-ibmdb2-init.yml -e "@inputs/ibmdb2_vars.yml`

- Target Host Installation
- `ansible-playbook -i "<target-host>" sap-ha-anydb-ibmdb2-init.yml -e "@inputs/ibmdb2_vars.yml"`

## Sample Ansible Playbook

```yaml
---
- hosts: all
become: true
sean-freeman marked this conversation as resolved.
Show resolved Hide resolved

collections:
- community.sap_install

vars:
sap_ha_install_anydb_ibmdb2_hostname_primary: anydb-primary
sap_ha_install_anydb_ibmdb2_hostname_secondary: anydb-second
sap_ha_install_anydb_ibmdb2_sid: DB2
sap_ha_install_anydb_ibmdb2_software_directory: /software/ibmdb2_extracted

- name: Execute Ansible Role sap_ha_install_anydb_ibmdb2
include_role:
name: { role: community.sap_install.sap_ha_install_anydb_ibmdb2 }
sean-freeman marked this conversation as resolved.
Show resolved Hide resolved
```

## License

Apache license 2.0

## Author Information

Sean Freeman
6 changes: 6 additions & 0 deletions roles/sap_ha_install_anydb_ibmdb2/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
sean-freeman marked this conversation as resolved.
Show resolved Hide resolved

# sap_ha_install_anydb_ibmdb2_hostname_primary:
# sap_ha_install_anydb_ibmdb2_hostname_secondary:
# sap_ha_install_anydb_ibmdb2_sid:
# sap_ha_install_anydb_ibmdb2_software_directory:
13 changes: 13 additions & 0 deletions roles/sap_ha_install_anydb_ibmdb2/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
galaxy_info:
namespace: community
author: Sean Freeman
description: HA for SAP AnyDB - IBM Db2
company: Red Hat, Inc.
sean-freeman marked this conversation as resolved.
Show resolved Hide resolved
license: Apache-2.0
min_ansible_version: 2.9
sean-freeman marked this conversation as resolved.
Show resolved Hide resolved
platforms:
- name: EL
sean-freeman marked this conversation as resolved.
Show resolved Hide resolved
versions: [ 8, 9 ]
galaxy_tags: [ 'sap', 'anydb', 'ibmdb2', 'ibm', 'db2', 'rhel', 'redhat', 'sles', 'suse' ]
dependencies: []
2 changes: 2 additions & 0 deletions roles/sap_ha_install_anydb_ibmdb2/meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
requires_ansible: '>=2.12.0'
165 changes: 165 additions & 0 deletions roles/sap_ha_install_anydb_ibmdb2/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
---

# IBM Db2 with an Integrated Cluster Manager have various options. See IBM Db2 Supported cluster management software - https://www.ibm.com/docs/en/db2/11.5?topic=clustering-supported-cluster-management-software
# IBM Db2 with “Integrated Linux Pacemaker” can use two deployment models, either High Availability and Disaster Recovery (HADR) option for Idle Standby or Mutual Failover option

# Execute IBM Db2 with “Integrated Linux Pacemaker” using Resource Agents db2ethmon, db2inst (HADR), db2hadr (HADR), db2partition and db2fs
# HA Deployment Model: High Availability and Disaster Recovery (HADR) for Idle Standby
# Configurations performed for: root OS user, IBM Db2 Database Administrator OS user (e.g. db2<db2_sid>)
# Configurations executed on: AnyDB Primary Node, AnyDB Secondary Node

# See SAP Note 1555903 - DB6: Supported IBM Db2 Database Features
# See SAP Note 3100330 - DB6: Using Db2 HADR with Pacemaker Cluster Software
# See SAP Note 3100287 - DB6: Db2 Support for Pacemaker Cluster Software
# See IBM Db2 for SAP HADR reference document referred from sap.com - https://ibm.github.io/db2-hadr-wiki/
# See Admin documentation for IBM Db2 with Integrated Cluster Manager (Linux Pacemaker) - https://www.ibm.com/docs/en/db2/11.5?topic=feature-integrated-solution-using-pacemaker
# See Installation documentation for IBM Db2 with Integrated Cluster Manager (Linux Pacemaker) - https://www.ibm.com/docs/en/db2/11.5?topic=manager-installing-pacemaker-cluster
sean-freeman marked this conversation as resolved.
Show resolved Hide resolved


- name: SAP HA AnyDB - IBM Db2 HADR - Confirm IBM Db2 installation media is available
ansible.builtin.find:
paths: "{{ sap_ha_install_anydb_ibmdb2_software_directory }}"
recurse: true
file_type: file
patterns: db2installPCMK
excludes: bin
register: __sap_ha_install_anydb_ibmdb2_check_install_media

- name: SAP HA AnyDB - IBM Db2 HADR - Fail if IBM Db2 installation media is not available
ansible.builtin.fail:
msg: IBM Db2 installation media is not available, cannot find file db2installPCMK
when: not (__sap_ha_install_anydb_ibmdb2_check_install_media.files | length > 0)

# Determine if we are on a cloud platform.
- name: SAP HA AnyDB - IBM Db2 HADR - Include tasks for platform detection
ansible.builtin.import_tasks: platform/ascertain_platform_type.yml

# See IBM Db2 documentation 'HADR and network address translation (NAT) support' - https://www.ibm.com/docs/en/db2/11.5?topic=support-hadr-nat
- name: SAP HA AnyDB - IBM Db2 HADR - Append IBM Db2 HA Ports to /etc/services
ansible.builtin.lineinfile:
path: /etc/services
line: "{{ item }}"
state: present
loop:
- "{{ sap_ha_install_anydb_ibmdb2_sid }}_HADR_1\t55001/tcp\t# DB2 HA Port 1" # DB2 HADR local service (env var db2hadrlocalsvc / HADR_LOCAL_SVC)
- "{{ sap_ha_install_anydb_ibmdb2_sid }}_HADR_2\t55002/tcp\t# DB2 HA Port 2" # DB2 HADR remote service (env var db2hadrremotesvc / HADR_REMOTE_SVC)
when: (sap_ha_install_anydb_ibmdb2_hostname_primary == inventory_hostname_short) or (sap_ha_install_anydb_ibmdb2_hostname_secondary == inventory_hostname_short)

- name: SAP HA AnyDB - IBM Db2 HADR - Include tasks for Passwordless SSH
ansible.builtin.import_tasks: passwordless_ssh.yml


- name: SAP HA AnyDB - IBM Db2 HADR - Ansible Task Block for IBM Db2 “Integrated Linux Pacemaker” configuration
when: (sap_ha_install_anydb_ibmdb2_hostname_primary == inventory_hostname_short) or (sap_ha_install_anydb_ibmdb2_hostname_secondary == inventory_hostname_short)
block:

# IBM Db2 LUW for SAP installation media includes already extracted Db2_*_Pacemaker_*_<<RHEL/SLES>><<pcmk_version>>_<<cpu_arch>>.tar.gz
# Default install file is /install_media/LINUXX86_64/ESE/disk1/db2/linuxamd64/pcmk/db2installPCMK
# Default RPM directory is /install_media/LINUXX86_64/ESE/disk1/db2/linuxamd64/pcmk/Linux
# Default SRPM (Source) directory is /install_media/LINUXX86_64/ESE/disk1/db2/linuxamd64/pcmk/Linux/SRPMS
- name: SAP HA AnyDB - IBM Db2 HADR - Identify IBM Db2 installation media with 'Integrated Linux Pacemaker' RPMs subdirectory
ansible.builtin.find:
paths: "{{ sap_ha_install_anydb_ibmdb2_software_directory }}"
recurse: true
file_type: file
patterns: db2installPCMK
excludes: bin
register: __sap_ha_install_anydb_ibmdb2_pcmk

- name: SAP HA AnyDB - IBM Db2 HADR - List all IBM Db2 'Integrated Linux Pacemaker' RPMs in subdirectory
ansible.builtin.find:
paths: "{{ (__sap_ha_install_anydb_ibmdb2_pcmk.files[0].path | dirname) + '/Linux/' + ('rhel' if ansible_os_family == 'RedHat' else 'suse' if ansible_os_family == 'Suse') }}"
recurse: true
file_type: file
patterns: "*.rpm"
register: __sap_ha_install_anydb_ibmdb2_pcmk_rpm_files

- name: SAP HA AnyDB - IBM Db2 HADR - Install all IBM Db2 'Integrated Linux Pacemaker' RPMs for RHEL
ansible.builtin.dnf:
name: "{{ __sap_ha_install_anydb_ibmdb2_pcmk_rpm_files.files | map(attribute='path') | list }}"
state: present
disable_gpg_check: true
when: ansible_os_family == 'RedHat'

- name: SAP HA AnyDB - IBM Db2 HADR - Install all IBM Db2 'Integrated Linux Pacemaker' RPMs for SLES
community.general.zypper:
name: "{{ __sap_ha_install_anydb_ibmdb2_pcmk_rpm_files.files | map(attribute='path') | list }}"
state: present
disable_gpg_check: true
when: ansible_os_family == 'Suse'

# SAP Note 3100287 - DB6: Db2 Support for Pacemaker Cluster Software
- name: SAP HA AnyDB - IBM Db2 HADR - Verify IBM Db2 'Integrated Linux Pacemaker' is installed
sean-freeman marked this conversation as resolved.
Show resolved Hide resolved
register: __sap_ha_install_anydb_ibmdb2_pcmk_version_check
ansible.builtin.shell: |
rpm -q corosync | grep -I db2pcmk
rpm -q pacemaker | grep -I db2pcmk
rpm -q crmsh | grep -I db2pcmk

- name: SAP HA AnyDB - IBM Db2 HADR - Display IBM Db2 'Integrated Linux Pacemaker' installation details
ansible.builtin.debug:
msg: "{{ __sap_ha_install_anydb_ibmdb2_pcmk_version_check.stdout_lines }}"

- name: SAP HA AnyDB - IBM Db2 HADR - Identify IBM Db2 cluster manager (db2cm) utility
ansible.builtin.find:
paths: /db2
recurse: true
file_type: file
patterns: db2cm
register: __sap_anydb_ibmdb2_db2cm

- name: SAP HA AnyDB - IBM Db2 HADR - Ensure directory for db2cm binary
ansible.builtin.file:
path: /db2/db2{{ sap_ha_install_anydb_ibmdb2_sid | lower }}/sqllib/bin
mode: "0755"
sean-freeman marked this conversation as resolved.
Show resolved Hide resolved
state: directory

- name: SAP HA AnyDB - IBM Db2 HADR - Copy db2cm binary to binary path
ansible.builtin.copy:
src: "{{ __sap_anydb_ibmdb2_db2cm.files[0].path }}"
sean-freeman marked this conversation as resolved.
Show resolved Hide resolved
remote_src: true
dest: /db2/db2{{ sap_ha_install_anydb_ibmdb2_sid | lower }}/sqllib/bin
mode: '0755'

# - name: SAP HA AnyDB - IBM Db2 HADR - Verify /usr/lib/ocf/resource.d/heartbeat contains Db2agents (db2hadr, db2inst, db2ethmon)

- name: SAP HA AnyDB - IBM Db2 HADR - Execute db2installPCMK shell script
ansible.builtin.shell: |
sean-freeman marked this conversation as resolved.
Show resolved Hide resolved
{{ __sap_ha_install_anydb_ibmdb2_pcmk.files[0].path }} -i


- name: SAP HA AnyDB - IBM Db2 HADR - Ansible Task Block to create Linux Pacemaker cluster from AnyDB Primary node
when: sap_ha_install_anydb_ibmdb2_hostname_primary == inventory_hostname_short
block:

# db2cm script must run as root
sean-freeman marked this conversation as resolved.
Show resolved Hide resolved
- name: SAP HA AnyDB - IBM Db2 HADR - Create Linux Pacemaker cluster using db2cm
register: __sap_ha_install_anydb_ibmdb2_config
ansible.builtin.shell: |
export ibmdb2_sid="{{ sap_ha_install_anydb_ibmdb2_sid }}"
export ibmdb2_instance="db2{{ sap_ha_install_anydb_ibmdb2_sid | lower }}"
export anydb_primary="{{ sap_ha_install_anydb_ibmdb2_hostname_primary }}"
export anydb_secondary="{{ sap_ha_install_anydb_ibmdb2_hostname_secondary }}"
# Assume 1 OS Network Interface until improvements can be made
export anydb_primary_nic="{{ hostvars[sap_ha_install_anydb_ibmdb2_hostname_primary].ansible_default_ipv4.interface }}"
sean-freeman marked this conversation as resolved.
Show resolved Hide resolved
export anydb_secondary_nic="{{ hostvars[sap_ha_install_anydb_ibmdb2_hostname_secondary].ansible_default_ipv4.interface }}"
/db2/$ibmdb2_instance/sqllib/bin/db2cm -create -cluster -domain db2pcmkcluster -host $anydb_primary -publicEthernet $anydb_primary_nic -host $anydb_secondary -publicEthernet $anydb_secondary_nic -remote_cmd "ssh -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
sleep 90
/db2/$ibmdb2_instance/sqllib/bin/db2cm -create -instance $ibmdb2_instance -host $anydb_primary
/db2/$ibmdb2_instance/sqllib/bin/db2cm -create -instance $ibmdb2_instance -host $anydb_secondary
/db2/$ibmdb2_instance/sqllib/bin/db2cm -create -db $ibmdb2_sid -instance $ibmdb2_instance

# - name: SAP HA AnyDB - IBM Db2 HADR - Configure Linux Pacemaker infrastructure platform resources using db2cm
# ansible.builtin.include_tasks: "platform/execute_db2cm_{{ __sap_ha_install_anydb_ibmdb2_platform }}.yml"


# db2cm script must run as root
- name: SAP HA AnyDB - IBM Db2 HADR - Verify AnyDB HA Linux Pacemaker initialisation
register: __sap_ha_install_anydb_ibmdb2_init_check
ansible.builtin.shell: |
export ibmdb2_instance="db2{{ sap_ha_install_anydb_ibmdb2_sid | lower }}"
/db2/$ibmdb2_instance/sqllib/bin/db2cm -list

- name: SAP HA AnyDB - IBM Db2 HADR - Display AnyDB HA config
ansible.builtin.debug:
msg: "{{ __sap_ha_install_anydb_ibmdb2_init_check.stdout_lines }}"
Loading