Patching an EPAS 18 / EFM Cluster with the RedHat Ansible Automation Platform (AAP)

The last post of this small series shows how to patch the EPAS 18 / EFM cluster which we installed with AAP without stopping the application for longer than a switchover. An AAP workflow runs pre-checks, takes a pgBackRest backup, patches the standby, waits for an approval, switches over with EFM, patches the old primary and the witness, switches back and finally runs the checks again.

Before that, we automate the pgBackRest setup from my manual pgBackRest post: the repository is on the witness lin6 (user pgbackrest), the stanza is called epas18, and the WAL files are pushed asynchronously from the primary.

The Patch Workflow

  1. Pre-checks: free disk space, EFM cluster status (standby in sync), replication lag, available updates
  2. pgBackRest backup (incremental by default)
  3. Patch the standby lin7: stop the EFM agent and EPAS, update the EDB packages, start EPAS, wait until it streams again, start the EFM agent
  4. Approval: an administrator confirms the switchover in the AAP GUI
  5. Switchover with efm promote -switchover: lin7 becomes the primary, lin8 the standby, the virtual IP moves to lin7
  6. Patch the old primary lin8 (now a standby) in the same way
  7. Patch the witness lin6 (EFM and pgBackRest)
  8. Switchover back, so that lin8 is the primary again (the inventory groups primary and standby stay correct)
  9. Post-checks (the same playbook as the pre-checks)

The patch playbook refuses to work on a primary: it checks pg_is_in_recovery() first. By default only the EDB packages and pgBackRest are updated. With the extra variable full_os_update: true all OS packages are updated, and the node is rebooted if needed.

Playbook: Setting up pgBackRest

pgBackRest comes from the PGDG repository. All PGDG repositories are disabled after the installation and only enabled for the pgBackRest package, so that a dnf update never replaces EDB packages with community builds. The SSH keys of enterprisedb (lin7, lin8) and pgbackrest (lin6) are generated with the user module and exchanged with authorized_key. Because the home directory of enterprisedb is /var/lib/edb, its .ssh directory gets the SELinux type ssh_home_t, but only if SELinux is enabled (in my lab it is disabled). Then the configuration files are written (pg1 is the primary, pg2 the standby, backup-standby=prefer takes the backup from the standby), the dummy archive_command from the installation post is replaced with archive-push (a reload is enough), the stanza is created, checked and a first full backup is taken. As the user aap on lin2:

cd ~/aap-demo
cat > playbooks/pgbackrest_setup.yml <<'EOF'
---
- name: Install pgBackRest from the PGDG repository on all nodes
  hosts: dbservers:witness
  gather_facts: false
  become: true
  tasks:
    - name: Install the PGDG repository
      ansible.builtin.dnf:
        name: https://download.postgresql.org/pub/repos/yum/reporpms/EL-10-x86_64/pgdg-redhat-repo-latest.noarch.rpm
        disable_gpg_check: true
        state: present

    - name: Disable all PGDG repositories (EPAS comes from the EDB repository)
      ansible.builtin.replace:
        path: /etc/yum.repos.d/pgdg-redhat-all.repo
        regexp: '^enabled=1'
        replace: 'enabled=0'

    - name: Install pgBackRest (only this package comes from PGDG)
      ansible.builtin.dnf:
        name: pgbackrest
        enablerepo: pgdg-common
        state: present

- name: Repository host - user pgbackrest
  hosts: witness
  gather_facts: false
  become: true
  tasks:
    - name: Create the user pgbackrest with an SSH key
      ansible.builtin.user:
        name: pgbackrest
        shell: /bin/bash
        generate_ssh_key: true
        ssh_key_type: ed25519
      register: pgbr_user

    - name: Create the repository and log directories
      ansible.builtin.file:
        path: "{{ item }}"
        state: directory
        owner: pgbackrest
        group: pgbackrest
        mode: "0750"
      loop: [/var/lib/pgbackrest, /var/log/pgbackrest]

- name: Database nodes - SSH key for enterprisedb
  hosts: dbservers
  gather_facts: false
  become: true
  tasks:
    - name: Create an SSH key for enterprisedb
      ansible.builtin.user:
        name: enterprisedb
        generate_ssh_key: true
        ssh_key_type: ed25519
      register: edb_user

    - name: Check whether SELinux is enabled
      ansible.builtin.command: selinuxenabled
      register: selinux
      changed_when: false
      failed_when: false

    - name: Set the SELinux type for ~enterprisedb/.ssh if SELinux is enabled (the home is /var/lib/edb)
      ansible.builtin.command: chcon -R -t ssh_home_t /var/lib/edb/.ssh
      changed_when: false
      when: selinux.rc == 0

    - name: Create the log and spool directories
      ansible.builtin.file:
        path: "{{ item }}"
        state: directory
        owner: enterprisedb
        group: enterprisedb
        mode: "0750"
      loop: [/var/log/pgbackrest, /var/spool/pgbackrest]

- name: Exchange the SSH keys and write the configuration
  hosts: dbservers:witness
  gather_facts: false
  become: true
  vars:
    pg_data: /var/lib/edb/as18/data
  tasks:
    - name: Allow enterprisedb from lin7 and lin8 to log in as pgbackrest on lin6
      ansible.posix.authorized_key:
        user: pgbackrest
        key: "{{ hostvars[item].edb_user.ssh_public_key }}"
      loop: "{{ groups['dbservers'] }}"
      when: inventory_hostname in groups['witness']

    - name: Allow pgbackrest from lin6 to log in as enterprisedb on lin7 and lin8
      ansible.posix.authorized_key:
        user: enterprisedb
        key: "{{ hostvars[groups['witness'][0]].pgbr_user.ssh_public_key }}"
      when: inventory_hostname in groups['dbservers']

    - name: Accept the host keys of the other nodes automatically
      ansible.builtin.copy:
        dest: "{{ os_home }}/.ssh/config"
        owner: "{{ os_user }}"
        mode: "0600"
        content: |
          Host *
            StrictHostKeyChecking accept-new
      vars:
        os_user: "{{ 'pgbackrest' if inventory_hostname in groups['witness'] else 'enterprisedb' }}"
        os_home: "{{ '/home/pgbackrest' if inventory_hostname in groups['witness'] else '/var/lib/edb' }}"

    - name: pgbackrest.conf on the repository host
      when: inventory_hostname in groups['witness']
      ansible.builtin.copy:
        dest: /etc/pgbackrest.conf
        owner: pgbackrest
        mode: "0640"
        content: |
          [global]
          repo1-path=/var/lib/pgbackrest
          repo1-retention-full=2
          repo1-bundle=y
          repo1-block=y
          compress-type=zst
          process-max=2
          start-fast=y
          backup-standby=prefer
          log-level-console=info
          log-level-file=detail

          [epas18]
          pg-version-force=18
          {% for h in groups['primary'] + groups['standby'] %}
          pg{{ loop.index }}-host={{ h.split('.')[0] }}
          pg{{ loop.index }}-host-user=enterprisedb
          pg{{ loop.index }}-path={{ pg_data }}
          pg{{ loop.index }}-port=5444
          pg{{ loop.index }}-socket-path=/tmp
          pg{{ loop.index }}-database=edb
          {% endfor %}

    - name: pgbackrest.conf on the database nodes
      when: inventory_hostname in groups['dbservers']
      ansible.builtin.copy:
        dest: /etc/pgbackrest.conf
        owner: enterprisedb
        mode: "0640"
        content: |
          [global]
          repo1-host={{ groups['witness'][0].split('.')[0] }}
          repo1-host-user=pgbackrest
          archive-async=y
          spool-path=/var/spool/pgbackrest
          process-max=2
          log-level-console=info
          log-level-file=detail

          [epas18]
          pg-version-force=18
          pg1-path={{ pg_data }}
          pg1-port=5444
          pg1-socket-path=/tmp
          pg1-database=edb

    - name: Replace the dummy archive_command with archive-push
      when: inventory_hostname in groups['dbservers']
      ansible.builtin.lineinfile:
        path: "{{ pg_data }}/postgresql.conf"
        regexp: "^#?archive_command ="
        line: "archive_command = 'pgbackrest --stanza=epas18 archive-push %p'"
      register: archive_command

    - name: Reload EPAS (no restart needed, archive_mode is already on)
      when: inventory_hostname in groups['dbservers'] and archive_command.changed
      ansible.builtin.systemd:
        name: edb-as-18
        state: reloaded

- name: Create the stanza and take the first full backup
  hosts: witness
  gather_facts: false
  become: true
  become_user: pgbackrest
  tasks:
    - name: Create the stanza epas18
      ansible.builtin.command:
        cmd: pgbackrest --stanza=epas18 stanza-create
        creates: /var/lib/pgbackrest/backup/epas18/backup.info

    - name: Check the archiving and the backup configuration
      ansible.builtin.command: pgbackrest --stanza=epas18 check
      changed_when: false

    - name: Take the first full backup
      ansible.builtin.command:
        cmd: pgbackrest --stanza=epas18 --type=full backup
        creates: /var/lib/pgbackrest/backup/epas18/latest
EOF

Playbook: Backup

cat > playbooks/pgbackrest_backup.yml <<'EOF'
---
- name: Take a pgBackRest backup before patching
  hosts: witness
  gather_facts: false
  become: true
  become_user: pgbackrest
  vars:
    backup_type: incr
  tasks:
    - name: Take the backup
      ansible.builtin.command: pgbackrest --stanza=epas18 --type={{ backup_type }} backup

    - name: Show the backups in the repository
      ansible.builtin.command: pgbackrest --stanza=epas18 info
      register: info
      changed_when: false

    - name: Print the backup list
      ansible.builtin.debug:
        var: info.stdout_lines
EOF

Playbook: Pre- and Post-Checks

The checks stop the workflow if the file system with /var has less than 20% free space, if EFM does not report the standby as in sync with the primary, or if the replication lag is larger than 16 MB. They also list the available EDB and pgBackRest updates:

cat > playbooks/epas_patch_precheck.yml <<'EOF'
---
- name: Checks before and after patching
  hosts: dbservers:witness
  gather_facts: true
  become: true
  vars:
    pg_bin: /usr/edb/as18/bin
    min_free_pct: 20
    max_lag_bytes: 16777216
  tasks:
    - name: Check the free space of the file system holding /var
      ansible.builtin.assert:
        that: (fs.size_available / fs.size_total * 100) >= min_free_pct
        fail_msg: "{{ fs.mount }} has less than {{ min_free_pct }}% free space"
        quiet: true
      vars:
        fs: "{{ ansible_facts.mounts | selectattr('mount', 'in', ['/var', '/']) | sort(attribute='mount', reverse=true) | first }}"

    - name: Get the EFM cluster status
      ansible.builtin.command: /usr/edb/efm-5.5/bin/efm cluster-status efm
      register: efm_status
      changed_when: false
      run_once: true
      delegate_to: "{{ groups['witness'][0] }}"

    - name: Check that the standby is in sync
      ansible.builtin.assert:
        that: "'in sync with primary' in efm_status.stdout"
        fail_msg: "{{ efm_status.stdout_lines }}"
        success_msg: "{{ efm_status.stdout_lines }}"
      run_once: true

    - name: Is the database a primary or a standby?
      when: inventory_hostname in groups['dbservers']
      ansible.builtin.command:
        argv: ["{{ pg_bin }}/psql", "-d", "edb", "-Atc", "select pg_is_in_recovery()"]
      become_user: enterprisedb
      register: recovery
      changed_when: false

    - name: Get the replication lag on the primary (in bytes)
      when: inventory_hostname in groups['dbservers'] and recovery.stdout == 'f'
      ansible.builtin.command:
        argv: ["{{ pg_bin }}/psql", "-d", "edb", "-Atc", "select coalesce(max(pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn)), -1)::bigint from pg_stat_replication"]
      become_user: enterprisedb
      register: lag
      changed_when: false
      failed_when: lag.stdout | int < 0 or lag.stdout | int > max_lag_bytes

    - name: List the available updates of the EDB packages and pgBackRest
      ansible.builtin.command: dnf -q check-update --enablerepo=pgdg-common 'edb-*' pgbackrest
      register: updates
      changed_when: false
      failed_when: updates.rc not in [0, 100]

    - name: Show the updates
      ansible.builtin.debug:
        msg: "{{ 'No updates available' if updates.rc == 0 else updates.stdout_lines }}"
EOF

Playbook: Patching one Node

cat > playbooks/epas_patch_node.yml <<'EOF'
---
- name: Patch a standby or the witness (never the primary)
  hosts: all
  gather_facts: false
  become: true
  serial: 1
  vars:
    pg_bin: /usr/edb/as18/bin
    pg_service: edb-as-18
    efm_service: edb-efm-5.5
    patch_packages: ["edb-as18*", "edb-efm55*", "pgbackrest"]
    full_os_update: false
  tasks:
    - name: Is this a database node?
      ansible.builtin.set_fact:
        is_db: "{{ inventory_hostname in groups['dbservers'] }}"

    - name: Make sure that the database is a standby
      when: is_db
      ansible.builtin.command:
        argv: ["{{ pg_bin }}/psql", "-d", "edb", "-Atc", "select pg_is_in_recovery()"]
      become_user: enterprisedb
      register: recovery
      changed_when: false
      failed_when: recovery.stdout != 't'

    - name: Stop the EFM agent
      ansible.builtin.systemd:
        name: "{{ efm_service }}"
        state: stopped

    - name: Stop EPAS
      when: is_db
      ansible.builtin.systemd:
        name: "{{ pg_service }}"
        state: stopped

    - name: Update the EDB packages and pgBackRest (installed packages only)
      ansible.builtin.dnf:
        name: "{{ patch_packages }}"
        state: latest
        update_only: true
        enablerepo: pgdg-common

    - name: Update all OS packages and reboot if needed
      when: full_os_update | bool
      block:
        - name: Update all packages
          ansible.builtin.dnf:
            name: "*"
            state: latest

        - name: Install dnf-plugins-core (for needs-restarting)
          ansible.builtin.dnf:
            name: dnf-plugins-core
            state: present

        - name: Check whether a reboot is needed
          ansible.builtin.command: dnf needs-restarting -r
          register: needs_reboot
          changed_when: false
          failed_when: needs_reboot.rc > 1

        - name: Reboot
          when: needs_reboot.rc == 1
          ansible.builtin.reboot:

    - name: Start EPAS
      when: is_db
      ansible.builtin.systemd:
        name: "{{ pg_service }}"
        state: started

    - name: Wait until the standby streams from the primary again
      when: is_db
      ansible.builtin.command:
        argv: ["{{ pg_bin }}/psql", "-d", "edb", "-Atc", "select status from pg_stat_wal_receiver"]
      become_user: enterprisedb
      register: walreceiver
      until: walreceiver.stdout == 'streaming'
      retries: 30
      delay: 10
      changed_when: false

    - name: Start the EFM agent
      ansible.builtin.systemd:
        name: "{{ efm_service }}"
        state: started

    - name: Show the installed versions
      ansible.builtin.command: rpm -q edb-as18-server edb-efm55 pgbackrest
      register: versions
      changed_when: false
      failed_when: false

    - name: Print the versions
      ansible.builtin.debug:
        var: versions.stdout_lines
EOF

Playbook: Switchover with EFM

The switchover playbook remembers the role of both databases, runs efm promote efm -switchover and waits until the roles have changed. The same playbook is used for the switchover and the switch back:

cat > playbooks/efm_switchover.yml <<'EOF'
---
- name: Switchover with EFM
  hosts: dbservers
  gather_facts: false
  become: true
  vars:
    pg_bin: /usr/edb/as18/bin
    efm: /usr/edb/efm-5.5/bin/efm
  tasks:
    - name: Get the role of the databases before the switchover
      ansible.builtin.command:
        argv: ["{{ pg_bin }}/psql", "-d", "edb", "-Atc", "select pg_is_in_recovery()"]
      become_user: enterprisedb
      register: before
      changed_when: false

    - name: Switchover (the standby becomes the primary)
      ansible.builtin.command: "{{ efm }} promote efm -switchover"
      register: switchover
      run_once: true

    - name: Show the output of the switchover
      ansible.builtin.debug:
        var: switchover.stdout_lines
      run_once: true

    - name: Wait until the roles have changed
      ansible.builtin.command:
        argv: ["{{ pg_bin }}/psql", "-d", "edb", "-Atc", "select pg_is_in_recovery()"]
      become_user: enterprisedb
      register: after
      until: after.rc == 0 and after.stdout == ('t' if before.stdout == 'f' else 'f')
      retries: 30
      delay: 10
      changed_when: false

    - name: Get the cluster status
      ansible.builtin.command: "{{ efm }} cluster-status efm"
      register: efm_status
      changed_when: false
      run_once: true

    - name: Show the cluster status
      ansible.builtin.debug:
        var: efm_status.stdout_lines
      run_once: true
EOF
git add playbooks
git commit -m "Add pgBackRest and patch playbooks"
git push

Configuring AAP

The playbook config/aap_patch.yml creates the job templates, runs the pgBackRest setup once and creates the workflow “EPAS – Patch Cluster”. The node “Patch Node” is used three times with different limits (standby, primary, witness), the switchover twice. The approval node waits at most one hour. A monthly schedule for the first Sunday of the month at 2:00 is created but disabled; in a real maintenance window the approval would be given by the person on duty. At the end the workflow is started without waiting, because it stops at the approval:

cat > config/aap_patch.yml <<'EOF'
---
- name: Configure pgBackRest and the patch workflow in AAP
  hosts: localhost
  connection: local
  gather_facts: false
  vars:
    org: JBITC
    templates:
      - {name: pgBackRest - Setup, playbook: playbooks/pgbackrest_setup.yml}
      - {name: pgBackRest - Backup, playbook: playbooks/pgbackrest_backup.yml}
      - {name: EPAS - Patch Checks, playbook: playbooks/epas_patch_precheck.yml}
      - {name: EPAS - Patch Node, playbook: playbooks/epas_patch_node.yml}
      - {name: EFM - Switchover, playbook: playbooks/efm_switchover.yml}
    jt: {type: job_template, organization: {name: JBITC}}
  tasks:
    - name: Synchronize the project (new playbooks in Git)
      ansible.controller.project_update:
        project: aap-demo
        wait: true

    - name: Create the job templates
      ansible.controller.job_template:
        name: "{{ item.name }}"
        organization: "{{ org }}"
        project: aap-demo
        playbook: "{{ item.playbook }}"
        inventory: Lab
        credentials: [Lab SSH]
        ask_limit_on_launch: true
        ask_variables_on_launch: true
      loop: "{{ templates }}"

    - name: Set up pgBackRest (once)
      ansible.controller.job_launch:
        job_template: pgBackRest - Setup
        wait: true
        timeout: 3600

    - name: Create the patch workflow
      ansible.controller.workflow_job_template:
        name: EPAS - Patch Cluster
        organization: "{{ org }}"
        inventory: Lab
        ask_variables_on_launch: true
        extra_vars:
          backup_type: incr
          full_os_update: false
        destroy_current_nodes: true
        workflow_nodes:
          - identifier: precheck
            unified_job_template: "{{ jt | combine({'name': 'EPAS - Patch Checks'}) }}"
            related: {success_nodes: [{identifier: backup}]}
          - identifier: backup
            unified_job_template: "{{ jt | combine({'name': 'pgBackRest - Backup'}) }}"
            related: {success_nodes: [{identifier: patch_standby}]}
          - identifier: patch_standby
            unified_job_template: "{{ jt | combine({'name': 'EPAS - Patch Node'}) }}"
            limit: standby
            related: {success_nodes: [{identifier: approve}]}
          - identifier: approve
            unified_job_template:
              name: Approve the switchover
              description: The standby is patched. Switch over to it?
              type: workflow_approval
              timeout: 3600
            related: {success_nodes: [{identifier: switchover}]}
          - identifier: switchover
            unified_job_template: "{{ jt | combine({'name': 'EFM - Switchover'}) }}"
            related: {success_nodes: [{identifier: patch_old_primary}]}
          - identifier: patch_old_primary
            unified_job_template: "{{ jt | combine({'name': 'EPAS - Patch Node'}) }}"
            limit: primary
            related: {success_nodes: [{identifier: patch_witness}]}
          - identifier: patch_witness
            unified_job_template: "{{ jt | combine({'name': 'EPAS - Patch Node'}) }}"
            limit: witness
            related: {success_nodes: [{identifier: switch_back}]}
          - identifier: switch_back
            unified_job_template: "{{ jt | combine({'name': 'EFM - Switchover'}) }}"
            related: {success_nodes: [{identifier: postcheck}]}
          - identifier: postcheck
            unified_job_template: "{{ jt | combine({'name': 'EPAS - Patch Checks'}) }}"

    - name: Monthly maintenance window (disabled)
      ansible.controller.schedule:
        name: EPAS - Monthly Patch Window
        unified_job_template: EPAS - Patch Cluster
        rrule: "DTSTART;TZID=Europe/Berlin:20270103T020000 RRULE:FREQ=MONTHLY;INTERVAL=1;BYDAY=SU;BYSETPOS=1"
        enabled: false

    - name: Start the patch workflow (it stops at the approval)
      ansible.controller.workflow_launch:
        workflow_template: EPAS - Patch Cluster
        wait: false
      register: patch_run

    - name: Show the workflow job ID
      ansible.builtin.debug:
        msg: "Workflow job {{ patch_run.id }} started, please approve the switchover in the GUI"
EOF
git add config
git commit -m "Add the patch workflow"
git push
# load the settings (needed in a new shell) and run it
source ~/aap_env.sh
aap_play config/aap_patch.yml
Sample Output (click to expand):
[aap@lin2 aap-demo]$ cat > config/aap_patch.yml <<'EOF'
---
- name: Configure pgBackRest and the patch workflow in AAP
  hosts: localhost
  connection: local
  gather_facts: false
  vars:
    org: JBITC
    templates:
      - {name: pgBackRest - Setup, playbook: playbooks/pgbackrest_setup.yml}
      - {name: pgBackRest - Backup, playbook: playbooks/pgbackrest_backup.yml}
      - {name: EPAS - Patch Checks, playbook: playbooks/epas_patch_precheck.yml}
      - {name: EPAS - Patch Node, playbook: playbooks/epas_patch_node.yml}
      - {name: EFM - Switchover, playbook: playbooks/efm_switchover.yml}
    jt: {type: job_template, organization: {name: JBITC}}
  tasks:
    - name: Synchronize the project (new playbooks in Git)
      ansible.controller.project_update:
        project: aap-demo
        wait: true

    - name: Create the job templates
      ansible.controller.job_template:
        name: "{{ item.name }}"
        organization: "{{ org }}"
        project: aap-demo
        playbook: "{{ item.playbook }}"
        inventory: Lab
        credentials: [Lab SSH]
        ask_limit_on_launch: true
        ask_variables_on_launch: true
      loop: "{{ templates }}"

    - name: Set up pgBackRest (once)
      ansible.controller.job_launch:
        job_template: pgBackRest - Setup
        wait: true
        timeout: 3600

    - name: Create the patch workflow
      ansible.controller.workflow_job_template:
        name: EPAS - Patch Cluster
        organization: "{{ org }}"
        inventory: Lab
        ask_variables_on_launch: true
        extra_vars:
          backup_type: incr
          full_os_update: false
        destroy_current_nodes: true
        workflow_nodes:
          - identifier: precheck
            unified_job_template: "{{ jt | combine({'name': 'EPAS - Patch Checks'}) }}"
            related: {success_nodes: [{identifier: backup}]}
          - identifier: backup
            unified_job_template: "{{ jt | combine({'name': 'pgBackRest - Backup'}) }}"
            related: {success_nodes: [{identifier: patch_standby}]}
          - identifier: patch_standby
            unified_job_template: "{{ jt | combine({'name': 'EPAS - Patch Node'}) }}"
            limit: standby
            related: {success_nodes: [{identifier: approve}]}
          - identifier: approve
            unified_job_template:
              name: Approve the switchover
              description: The standby is patched. Switch over to it?
              type: workflow_approval
              timeout: 3600
            related: {success_nodes: [{identifier: switchover}]}
          - identifier: switchover
            unified_job_template: "{{ jt | combine({'name': 'EFM - Switchover'}) }}"
            related: {success_nodes: [{identifier: patch_old_primary}]}
          - identifier: patch_old_primary
            unified_job_template: "{{ jt | combine({'name': 'EPAS - Patch Node'}) }}"
            limit: primary
            related: {success_nodes: [{identifier: patch_witness}]}
          - identifier: patch_witness
            unified_job_template: "{{ jt | combine({'name': 'EPAS - Patch Node'}) }}"
            limit: witness
            related: {success_nodes: [{identifier: switch_back}]}
          - identifier: switch_back
            unified_job_template: "{{ jt | combine({'name': 'EFM - Switchover'}) }}"
            related: {success_nodes: [{identifier: postcheck}]}
          - identifier: postcheck
            unified_job_template: "{{ jt | combine({'name': 'EPAS - Patch Checks'}) }}"

    - name: Monthly maintenance window (disabled)
      ansible.controller.schedule:
        name: EPAS - Monthly Patch Window
        unified_job_template: EPAS - Patch Cluster
        rrule: "DTSTART;TZID=Europe/Berlin:20270103T020000 RRULE:FREQ=MONTHLY;INTERVAL=1;BYDAY=SU;BYSETPOS=1"
        enabled: false

    - name: Start the patch workflow (it stops at the approval)
      ansible.controller.workflow_launch:
        workflow_template: EPAS - Patch Cluster
        wait: false
      register: patch_run

    - name: Show the workflow job ID
      ansible.builtin.debug:
        msg: "Workflow job {{ patch_run.id }} started, please approve the switchover in the GUI"
EOF
git add config
git commit -m "Add the patch workflow"
git push
# load the settings (needed in a new shell) and run it
source ~/aap_env.sh
aap_play config/aap_patch.yml
[main 792ac6a] Add the patch workflow
 1 file changed, 99 insertions(+)
 create mode 100644 config/aap_patch.yml
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 1.44 KiB | 1.44 MiB/s, done.
Total 4 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0)
To http://lin2.fritz.box:3000/gitadmin/aap-demo.git
   83b0781..792ac6a  main -> main
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'

PLAY [Configure pgBackRest and the patch workflow in AAP] **********************

TASK [Synchronize the project (new playbooks in Git)] **************************
changed: [localhost]

TASK [Create the job templates] ************************************************
changed: [localhost] => (item={'name': 'pgBackRest - Setup', 'playbook': 'playbooks/pgbackrest_setup.yml'})
changed: [localhost] => (item={'name': 'pgBackRest - Backup', 'playbook': 'playbooks/pgbackrest_backup.yml'})
changed: [localhost] => (item={'name': 'EPAS - Patch Checks', 'playbook': 'playbooks/epas_patch_precheck.yml'})
changed: [localhost] => (item={'name': 'EPAS - Patch Node', 'playbook': 'playbooks/epas_patch_node.yml'})
changed: [localhost] => (item={'name': 'EFM - Switchover', 'playbook': 'playbooks/efm_switchover.yml'})

TASK [Set up pgBackRest (once)] ************************************************
changed: [localhost]

TASK [Create the patch workflow] ***********************************************
changed: [localhost]

TASK [Monthly maintenance window (disabled)] ***********************************
changed: [localhost]

TASK [Start the patch workflow (it stops at the approval)] *********************
changed: [localhost]

TASK [Show the workflow job ID] ************************************************
ok: [localhost] => {
    "msg": "Workflow job 99 started, please approve the switchover in the GUI"
}

PLAY RECAP *********************************************************************
localhost                  : ok=7    changed=6    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

[aap@lin2 aap-demo]$

Approving the Switchover

When the standby is patched, the workflow waits at the approval node. In the GUI the pending approval is shown under Automation Execution, Administration, Workflow Approvals and in the workflow job itself. After a check of the standby (for example with efm cluster-status efm on lin6) we click Approve and the workflow continues with the switchover. If nobody approves within one hour, the approval times out and the workflow stops; the cluster then runs with a patched standby and an unpatched primary, which is a safe state.

AAP Workflow Approvals: the approval "Approve the switchover" of the patch workflow is waiting

AAP job list: the workflow job EPAS - Patch Cluster and all its jobs finished successfully

Checking the Result

After the workflow has finished, all nodes have the new package versions and lin8 is the primary again. On lin6 (as root):

/usr/edb/efm-5.5/bin/efm cluster-status efm
sudo -iu pgbackrest pgbackrest --stanza=epas18 info
for h in lin6 lin7 lin8; do ssh -o StrictHostKeyChecking=accept-new $h rpm -q edb-as18-server edb-efm55 pgbackrest; done
Sample Output (click to expand):
[root@lin6 ~]# /usr/edb/efm-5.5/bin/efm cluster-status efm
sudo -iu pgbackrest pgbackrest --stanza=epas18 info
for h in lin6 lin7 lin8; do ssh -o StrictHostKeyChecking=accept-new $h rpm -q edb-as18-server edb-efm55 pgbackrest; done
Cluster Status: efm

        Agent Type  Address              DB       VIP
        ----------------------------------------------------------------
        Witness     11.1.1.186           N/A      11.1.1.200
        Standby     11.1.1.195           UP       11.1.1.200
        Primary     11.1.1.196           UP       11.1.1.200*

Allowed node host list:
        11.1.1.195 11.1.1.196 11.1.1.186

Membership coordinator: 11.1.1.195

Standby priority host list:
        11.1.1.195

Promote Status:

        DB Type     Address              WAL Received LSN   WAL Replayed LSN   Info
        ---------------------------------------------------------------------------
        Primary     11.1.1.196                              0/E002080
        Standby     11.1.1.195           0/E002080          0/E002080

        Standby database(s) in sync with primary. It is safe to promote.
stanza: epas18
    status: ok
    cipher: none

    db (current)
        wal archive min/max (18): 000000010000000000000006/00000002000000000000000D

        full backup: 20261206-091735F
            timestamp start/stop: 2026-12-06 09:17:35+01 / 2026-12-06 09:17:39+01
            wal start/stop: 000000010000000000000007 / 000000010000000000000008
            database size: 57.9MB, database backup size: 57.9MB
            repo1: backup size: 8.3MB

        incr backup: 20261206-091735F_20261206-092309I
            timestamp start/stop: 2026-12-06 09:23:09+01 / 2026-12-06 09:23:12+01
            wal start/stop: 00000001000000000000000B / 00000001000000000000000B
            database size: 58MB, database backup size: 15.3KB
            repo1: backup size: 1.9KB
            backup reference total: 1 full
Warning: Permanently added 'lin6' (ED25519) to the list of known hosts.
root@lin6's password:
package edb-as18-server is not installed
edb-efm55-5.5-1.el10.x86_64
pgbackrest-2.60.1-1PGDG.rhel10.3.x86_64
Warning: Permanently added 'lin7' (ED25519) to the list of known hosts.
root@lin7's password:
edb-as18-server-18.7.0-1.el10.x86_64
edb-efm55-5.5-1.el10.x86_64
pgbackrest-2.60.1-1PGDG.rhel10.3.x86_64
Warning: Permanently added 'lin8' (ED25519) to the list of known hosts.
root@lin8's password:
edb-as18-server-18.7.0-1.el10.x86_64
edb-efm55-5.5-1.el10.x86_64
pgbackrest-2.60.1-1PGDG.rhel10.2.x86_64
[root@lin6 ~]#

This post concludes the series. With the playbooks in Gitea, the secrets in Vault and the templates in AAP, the whole EPAS cluster can be installed, backed up and patched with a few clicks, and every run is logged in AAP.

0