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

Automate in place major upgrade for PostgreSQL #301

Merged
merged 195 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
195 commits
Select commit Hold shift + click to select a range
c0d6efc
add upgrade role
vitabaks Apr 12, 2023
1501115
upgrade_secondary: update task name
vitabaks Apr 13, 2023
97ed3a3
fix no-jinja-when
vitabaks Apr 13, 2023
d22fce4
Update upgrade.yml
vitabaks Apr 13, 2023
9861fbe
Update upgrade_postgres.yml
vitabaks Apr 13, 2023
71e3a92
Update vars
vitabaks Apr 13, 2023
a6dd6e9
Update update_config.yml
vitabaks Apr 13, 2023
8aecbdf
Update update_config.yml
vitabaks Apr 13, 2023
5d4ca13
Update extensions in each database
vitabaks Apr 13, 2023
3783bcf
Update statistics.yml
vitabaks Apr 13, 2023
7c31dee
Update upgrade_postgres.yml
vitabaks Apr 13, 2023
0f62894
Configure SSH Key-Based Authentication between cluster nodes
vitabaks Apr 13, 2023
8ecd3ad
Update ssh-keys.yml
vitabaks Apr 13, 2023
3d6df52
Update ssh-keys.yml
vitabaks Apr 13, 2023
e8e9e45
Update upgrade_postgres.yml
vitabaks Apr 14, 2023
250135d
pre_checks: fix typo
vitabaks Apr 14, 2023
e15bed5
Make sure that the openssh-client package is installed
vitabaks Apr 14, 2023
ad28077
Update upgrade_postgres.yml
vitabaks Apr 14, 2023
fa1d45a
ssh-keys: add become_user
vitabaks Apr 14, 2023
df7ee0d
Update ssh-keys.yml
vitabaks Apr 14, 2023
21a56a5
molecule: setup ssh service
vitabaks Apr 14, 2023
690e497
Update converge.yml
vitabaks Apr 14, 2023
20e3b9c
Update converge.yml
vitabaks Apr 14, 2023
368ca47
Update schema_compatibility.yml
vitabaks Apr 14, 2023
2aae0b6
Update pre_checks.yml
vitabaks Apr 14, 2023
2ec51c3
Update upgrade_check.yml
vitabaks Apr 14, 2023
16586fc
Update pre_checks.yml
vitabaks Apr 17, 2023
ea47923
Update initdb.yml
vitabaks Apr 17, 2023
2cf38c7
Update initdb.yml
vitabaks Apr 17, 2023
706de7e
Update upgrade_postgres.yml
vitabaks Apr 18, 2023
a1bd8fe
Update upgrade_postgres.yml
vitabaks Apr 18, 2023
34030d6
initdb: Make sure new PostgreSQL data directory is not initialized
vitabaks Apr 18, 2023
89223f2
Update schema_compatibility.yml
vitabaks Apr 18, 2023
42d3cf5
Update initdb.yml
vitabaks Apr 18, 2023
536ab70
Update schema_compatibility.yml
vitabaks Apr 18, 2023
72ab857
Make sure that the new data directory are empty on the Replica
vitabaks Apr 18, 2023
391f841
Add args.chdir for pg_upgrade tasks
vitabaks Apr 18, 2023
b520af3
Update update_config.yml
vitabaks Apr 18, 2023
cc99e0b
Update upgrade_secondary.yml
vitabaks Apr 18, 2023
3405ca3
Update post_checks.yml
vitabaks Apr 19, 2023
703b976
Update update_config.yml
vitabaks Apr 19, 2023
1168a6c
Update upgrade_secondary.yml
vitabaks Apr 19, 2023
3a2917a
Update post_checks.yml
vitabaks Apr 19, 2023
08432dc
Update schema_compatibility.yml
vitabaks Apr 19, 2023
676e180
Update upgrade_check.yml
vitabaks Apr 19, 2023
b660ff1
Update post_checks.yml
vitabaks Apr 19, 2023
3d5c465
Update update_extensions.yml
vitabaks Apr 19, 2023
b99db9f
use patroni_config_file variable
vitabaks Apr 19, 2023
5e4604d
upgrade_postgres: update tags
vitabaks Apr 19, 2023
a16ff6d
initdb: Get the current encodig and data_checksums settings on the pr…
vitabaks Apr 19, 2023
b1513c0
update_extensions: Get list of installed PostgreSQL extensions
vitabaks Apr 19, 2023
cf14bed
Update schema_compatibility.yml
vitabaks Apr 24, 2023
3edf149
post_checks: move task "Drop a table test_replication"
vitabaks Apr 24, 2023
51d0b1b
Revert "Update schema_compatibility.yml"
vitabaks Apr 24, 2023
96d7f7f
upgrade: set "become: false" for task "Remove public SSH keys from lo…
vitabaks Apr 25, 2023
ba837ae
schema_compatibility: use postgresql_unix_socket_dir
vitabaks Apr 25, 2023
a6b7e92
Update initdb.yml
vitabaks Apr 26, 2023
c3e0a82
Update upgrade_postgres.yml
vitabaks Apr 27, 2023
ebf9c5f
Update pre_checks.yml
vitabaks May 1, 2023
5ab95cd
pre_checks: Make sure the ansible required Python library is installed
vitabaks May 2, 2023
3668246
Update dcs_remove_cluster.yml
vitabaks May 2, 2023
a27f6ad
Merge branch 'master' into pg-upgrade
vitabaks May 2, 2023
ce47380
update_extensions: add the database name to the tasks name
vitabaks May 2, 2023
77cc29d
Merge branch 'pg-upgrade' of https://github.com/vitabaks/postgresql_c…
vitabaks May 2, 2023
87d6801
Add variable "vacuumdb_analyze_timeout"
vitabaks May 2, 2023
d2b4c71
Merge branch 'master' into pg-upgrade
vitabaks May 3, 2023
a4ede3f
pre_checks: Update task name
vitabaks May 3, 2023
6d64fd5
pre_checks: Test PostgreSQL database access using a unix socket
vitabaks May 3, 2023
8cece0e
Add Post-Upgrade tasks
vitabaks May 3, 2023
094136e
post_upgrade: fix yamllint warning
vitabaks May 3, 2023
ff02556
Merge branch 'master' into pg-upgrade
vitabaks May 4, 2023
e12fe4b
Update upgrade.yml
vitabaks May 11, 2023
f41942c
Ad pg_new_packages variable
vitabaks May 11, 2023
5bd3577
Update upgrade.yml
vitabaks May 11, 2023
c058114
molecule: Add PostgreSQL upgrade tests
vitabaks May 11, 2023
a8fc7bc
Merge branch 'master' into pg-upgrade
vitabaks May 12, 2023
6ff228d
molecule: Delete "/run/nologin" file (if exists)
vitabaks May 12, 2023
7e4fe31
Merge branch 'master' into pg-upgrade
vitabaks May 20, 2023
e692e2f
Install TimescaleDB package for new PostgreSQL version
vitabaks May 20, 2023
3504430
Merge branch 'master' into pg-upgrade
vitabaks May 25, 2023
6a6f8ee
pg_upgrade: Add timescaledb.restoring='on' for timescaledb
vitabaks May 25, 2023
a925f1a
fix yamllint warning: [trailing-spaces]
vitabaks May 25, 2023
da0be23
support for Timescale packages 1.x
vitabaks May 25, 2023
954b139
Update upgrade_check.yml
vitabaks May 25, 2023
5ff1026
Update upgrade_primary.yml
vitabaks May 25, 2023
56eaef6
fix yamllint warning: [trailing-spaces]
vitabaks May 25, 2023
726de42
Add become_user for task "Make sure new PostgreSQL data directory "{{…
vitabaks May 30, 2023
a416d7b
schema_compatibility: Get the current cron.database_name settings
vitabaks May 30, 2023
cf26744
The trailing slash, if present, is removed to ensure path consistency.
vitabaks May 30, 2023
632b104
Update upgrade_postgres.yml
vitabaks Jun 1, 2023
9439420
ansible-lint: Add run-once[task] to skip_list
vitabaks Jun 2, 2023
3fd4aa4
Merge branch 'master' into pg-upgrade
vitabaks Jun 2, 2023
b77750f
Merge branch 'master' into pg-upgrade
vitabaks Jun 7, 2023
9c42889
Merge branch 'master' into pg-upgrade
vitabaks Jun 9, 2023
99617b6
Merge branch 'master' into pg-upgrade
vitabaks Jun 9, 2023
b0b1e94
Update postgres.yml
vitabaks Jun 9, 2023
61c1d8d
Update replication.yml
vitabaks Jun 9, 2023
e8b2713
Merge branch 'master' into pg-upgrade
vitabaks Jun 12, 2023
a0a9c62
Merge branch 'master' into pg-upgrade
vitabaks Jun 12, 2023
f9bd92d
Update converge.yml
vitabaks Jun 12, 2023
fc0c41b
Update molecule.yml
vitabaks Jun 12, 2023
0c83b36
fix yamllint warning [empty-lines]
vitabaks Jun 12, 2023
d4460f8
fix ansible-lint warning run-once[task]
vitabaks Jun 13, 2023
2bcd5cb
fix ansible-lint warning yaml[octal-values]
vitabaks Jun 13, 2023
53d22dc
fix ansible-lint warning fqcn[action]
vitabaks Jun 13, 2023
fe7acc0
Parallelize PostgreSQL upgrade on replicas using RSync
vitabaks Jun 13, 2023
f9c3860
specify become_user at the block level
vitabaks Jun 13, 2023
f5ef2cd
Merge branch 'master' into pg-upgrade
vitabaks Jun 16, 2023
cdd6fe2
add compatibility to upgrade from PostgresSQL 9.x
vitabaks Jun 18, 2023
3646f55
Update upgrade_postgres.yml
vitabaks Jun 18, 2023
3ac6165
Merge branch 'master' into pg-upgrade
vitabaks Jun 18, 2023
e43d855
Update statistics.yml
vitabaks Jun 19, 2023
ddcdeec
Update update_config.yml
vitabaks Jun 19, 2023
b1425f8
elete the old PostgreSQL data directory after the upgrade
vitabaks Jun 19, 2023
a146a27
Remove old PostgreSQL packages
vitabaks Jun 19, 2023
aea6e7f
Upgrade pgbackrest stanza
vitabaks Jun 20, 2023
9e76371
Merge branch 'master' into pg-upgrade
vitabaks Jun 23, 2023
969b3d0
Merge branch 'master' into pg-upgrade
vitabaks Jul 8, 2023
ae386b3
Remove compatibility with Ansible versions older than 2.11.0
vitabaks Jul 8, 2023
8bb25c5
Update upgrade_postgres.yml
vitabaks Jul 8, 2023
b3bea93
Merge branch 'master' into pg-upgrade
vitabaks Jul 8, 2023
0fc59df
Ensure ‘Latest checkpoint location’ matches on all cluster nodes befo…
vitabaks Jul 11, 2023
e4c8ef8
Add environment PATH for patronictl
vitabaks Jul 11, 2023
d61f8fa
Update comment
vitabaks Jul 11, 2023
a367e75
Update schema_compatibility.yml
vitabaks Jul 12, 2023
b4ae3d1
Update stop_services.yml
vitabaks Jul 12, 2023
88dfb06
Merge branch 'master' into pg-upgrade
vitabaks Jul 13, 2023
ad1ac4a
Use FQCN for builtin module actions
vitabaks Jul 13, 2023
636c833
Update ssh-keys.yml
vitabaks Jul 13, 2023
57646f2
Add rollback.yml
vitabaks Jul 14, 2023
620cc59
Merge branch 'master' into pg-upgrade
vitabaks Jul 15, 2023
3783405
Fix jinja[spacing]
vitabaks Jul 16, 2023
d41229f
Rename upgrade_postgres.yml playbool to pg_upgrade.yml
vitabaks Jul 17, 2023
e61a26f
Update rollback.yml
vitabaks Jul 17, 2023
2a38184
Add pg_upgrade_rollback.yml
vitabaks Jul 17, 2023
34a2626
Get the current install user
vitabaks Jul 18, 2023
a8a61b9
schema_compatibility.yml: fix typo
vitabaks Jul 18, 2023
247545e
Merge branch 'master' into pg-upgrade
vitabaks Jul 18, 2023
db1266f
fix yamllint warning (yaml[line-length])
vitabaks Jul 19, 2023
fbd0027
Update rollback.yml
vitabaks Jul 19, 2023
916c4e1
rollback: Add default for cluster_members variable
vitabaks Jul 19, 2023
6f94842
Rollback: exclude 'stopped' cluster members
vitabaks Jul 19, 2023
46763a1
Add an error message if patroni is unavailable
vitabaks Jul 19, 2023
fdc0b45
Merge branch 'master' into pg-upgrade
vitabaks Jul 20, 2023
88ea118
Update converge.yml
vitabaks Jul 20, 2023
346496b
custom WAL dir symlink (if pg_new_wal_dir is defined)
vitabaks Jul 25, 2023
cca38b8
Update converge.yml
vitabaks Jul 25, 2023
a3d0781
Update post_upgrade.yml
vitabaks Jul 25, 2023
b516f35
Update custom_wal_dir.yml
vitabaks Jul 25, 2023
4fffbb5
Pre-Check: Ensure new WAL directory is different from the current one
vitabaks Jul 25, 2023
dc30653
debian.yml: Delete an unused variable
vitabaks Jul 25, 2023
da4c758
Create WAL dir symlink after upgrade
vitabaks Jul 25, 2023
679bc09
Update task name "Delete the old PostgreSQL WAL directory"
vitabaks Jul 25, 2023
0d1c3cb
Merge branch 'master' into pg-upgrade
vitabaks Jul 26, 2023
23e92bf
Update query for task: Wait until replication lag is 0 bytes
vitabaks Jul 28, 2023
777fb07
Update pg_upgrade.yml
vitabaks Jul 28, 2023
327ff99
Upgrade the PostgreSQL tablespaces
vitabaks Jul 28, 2023
a9eecb0
update PGDATA in WAL-G conf file and cron job after upgrade
vitabaks Aug 1, 2023
34f014a
Copy any files located in the "files" directory to all servers
vitabaks Aug 2, 2023
b0dbe75
PAUSE PgBouncer pools
vitabaks Aug 4, 2023
c42ed03
Merge branch 'master' into pg-upgrade
vitabaks Aug 4, 2023
1fff23c
Rollback: Perform RESUME PgBouncer pools (if paused)
vitabaks Aug 4, 2023
d76e6a4
HAProxy maintenance mode
vitabaks Aug 7, 2023
fe273e8
Update stop_services.yml
vitabaks Aug 7, 2023
697f577
Update upgrade.yml
vitabaks Aug 7, 2023
c8801ae
update variable name "pg_slow_active_query_treshold"
vitabaks Aug 7, 2023
4e91a4f
Update pgbouncer_pause.yml
vitabaks Aug 8, 2023
8a99970
Update pgbouncer_pause.yml
vitabaks Aug 9, 2023
081896e
Enable maintenance mode for vip-manager
vitabaks Aug 10, 2023
804fee6
pgbouncer_pause: more info about terminated queries
vitabaks Aug 11, 2023
2b91495
Enhance playbook compatibility with multiple PostgreSQL versions
vitabaks Aug 11, 2023
566dde9
maintenance: Update haproxy task name
vitabaks Aug 11, 2023
d42b11c
Update rollback tasks name
vitabaks Aug 11, 2023
47b6f16
Add run_once for task "Long-running transactions detected"
vitabaks Aug 11, 2023
32c8776
Install latest PostgreSQL version
vitabaks Aug 12, 2023
121ee9d
Add schema_compatibility_check_port variable
vitabaks Aug 14, 2023
6e30953
Update upgrade.yml
vitabaks Aug 14, 2023
b50826b
Create README.md
vitabaks Aug 14, 2023
d744a24
Update README.md
vitabaks Aug 14, 2023
57121bc
README: Add step 5
vitabaks Aug 15, 2023
b0a4861
README: Add step 6 and 7
vitabaks Aug 15, 2023
679c353
Update README.md
vitabaks Aug 15, 2023
ae9b280
Add 'vacuumdb_parallel_jobs' variable
vitabaks Aug 15, 2023
eb4b030
README: describe vacuumdb_parallel_jobs variable
vitabaks Aug 15, 2023
013bb7f
Update pre_checks.yml
vitabaks Aug 16, 2023
9107750
Update pg_upgrade.yml
vitabaks Aug 16, 2023
6611035
Update README and tasks names
vitabaks Aug 16, 2023
3d80ce2
pre-checks: Make sure that the cluster ip address (VIP) is running
vitabaks Aug 16, 2023
cba97d3
README: Add recommendations
vitabaks Aug 17, 2023
ae10d01
Add pg_terminator script to monitor locks and terminate the 'ANALYZE'…
vitabaks Aug 17, 2023
351a735
Update pg_terminator script query
vitabaks Aug 17, 2023
ae8f9b1
update the project's README
vitabaks Aug 17, 2023
3991206
Describe Rollback
vitabaks Aug 17, 2023
f4865fb
Move pg_upgrade test to a separate molecule scenario
vitabaks Aug 17, 2023
4f41a7d
fix [empty-lines]
vitabaks Aug 17, 2023
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
81 changes: 81 additions & 0 deletions .github/workflows/molecule_pg_upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
name: Molecule pg_upgrade

on:
schedule:
- cron: "0 0 * * 6"

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
config:
- distro: debian12
tag: latest
namespace: geerlingguy
- distro: debian11
tag: latest
namespace: geerlingguy
- distro: debian10
tag: latest
namespace: geerlingguy
- distro: ubuntu2204
tag: latest
namespace: geerlingguy
- distro: ubuntu2004
tag: latest
namespace: geerlingguy
- distro: ubuntu1804
tag: latest
namespace: geerlingguy
- distro: rockylinux8
tag: latest
namespace: geerlingguy
- distro: rockylinux9
tag: latest
namespace: geerlingguy
- distro: almalinux8
tag: latest
namespace: glillico
- distro: almalinux9
tag: latest
namespace: glillico
- distro: oraclelinux8
tag: latest
namespace: glillico
- distro: oraclelinux9
tag: latest
namespace: glillico
- distro: centosstream9
tag: latest
namespace: glillico
- distro: centosstream8
tag: latest
namespace: glillico

steps:
- name: Set TERM environment variable
run: echo "TERM=xterm" >> $GITHUB_ENV

- name: Checkout
uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap-dev

- name: Run Molecule tests for pg_upgrade
run: make molecule-test-scenario
env:
PY_COLORS: "1"
ANSIBLE_FORCE_COLOR: "1"
IMAGE_DISTRO: ${{ matrix.config.distro }}
IMAGE_TAG: ${{ matrix.config.tag }}
IMAGE_NAMESPACE: ${{ matrix.config.namespace }}
MOLECULE_SCENARIO: "pg_upgrade"
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ In addition to deploying new clusters, this playbook also support the deployment
- [Point-In-Time-Recovery:](#point-in-time-recovery)
- [Maintenance](#maintenance)
- [Update the PostgreSQL HA Cluster](#update-the-postgresql-ha-cluster)
- [PostgreSQL major upgrade](#postgresql-major-upgrade)
- [Using Git for cluster configuration management](#using-git-for-cluster-configuration-management-iacgitops)
- [Disaster Recovery](#disaster-recovery)
- [etcd](#etcd)
Expand Down Expand Up @@ -490,7 +491,7 @@ I recommend that you study the following materials for further maintenance of th
- [Patroni documentation](https://patroni.readthedocs.io/en/latest/)
- [etcd operations guide](https://etcd.io/docs/v3.5/op-guide/)

#### Update the PostgreSQL HA Cluster
### Update the PostgreSQL HA Cluster

Use the `update_pgcluster.yml` playbook for update the PostgreSQL HA Cluster to a new minor version (for example 15.1->15.2, and etc).

Expand Down Expand Up @@ -523,7 +524,22 @@ ansible-playbook update_pgcluster.yml -e target=system

More details [here](roles/update/README.md)

#### Using Git for cluster configuration management (IaC/GitOps)
### PostgreSQL major upgrade

Use the `pg_upgrade.yml` playbook to upgrade the PostgreSQL to a new major version (for example 14->15, and etc).

<details><summary>Upgrade PostgreSQL</summary>

```
ansible-playbook pg_upgrade.yml -e "pg_old_version=14 pg_new_version=15"
```

</details>

More details [here](roles/upgrade/README.md)


### Using Git for cluster configuration management (IaC/GitOps)

Infrastructure as Code (IaC) is the managing and provisioning of infrastructure through code instead of through manual processes. \
GitOps automates infrastructure updates using a Git workflow with continuous integration (CI) and continuous delivery (CI/CD). When new code is merged, the CI/CD pipeline enacts the change in the environment. Any configuration drift, such as manual changes or errors, is overwritten by GitOps automation so the environment converges on the desired state defined in Git.
Expand Down
6 changes: 3 additions & 3 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
with_haproxy_load_balancing: true
consul_node_role: server # if dcs_type: "consul"
consul_bootstrap_expect: true # if dcs_type: "consul"
postgresql_version: "15"
postgresql_version: "15" # to test custom WAL dir
cacheable: true

- name: Set variables for custom PostgreSQL data and WAL directory test
ansible.builtin.set_fact:
postgresql_data_dir: "/data/{{ postgresql_version }}/main"
postgresql_wal_dir: "/wal/{{ postgresql_version }}/pg_wal"
postgresql_data_dir: "/pgdata/{{ postgresql_version }}/main"
postgresql_wal_dir: "/pgwal/{{ postgresql_version }}/pg_wal"

- name: Set variables for TimescaleDB cluster deployment test
ansible.builtin.set_fact:
Expand Down
83 changes: 83 additions & 0 deletions molecule/pg_upgrade/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
- name: Converge
hosts: all
gather_facts: true

tasks:
- name: Set variables for Patroni cluster deployment test
ansible.builtin.set_fact:
firewall_enabled_at_boot: false
firewall_enable_ipv6: false # Added to prevent test failures in CI.
swap_file_create: false # Added to prevent test failures in CI.
sysctl_set: false # Added to prevent test failures in CI.
nameservers: ["8.8.8.8", "9.9.9.9"]
timezone: "Etc/UTC"
with_haproxy_load_balancing: true
consul_node_role: server # if dcs_type: "consul"
consul_bootstrap_expect: true # if dcs_type: "consul"
postgresql_version: "12" # redefine the version to install for the upgrade test
cacheable: true

- name: Set variables for custom PostgreSQL data and WAL directory test
ansible.builtin.set_fact:
postgresql_data_dir: "/pgdata/{{ postgresql_version }}/main"
postgresql_wal_dir: "/pgwal/{{ postgresql_version }}/pg_wal"

- name: Set variables for TimescaleDB cluster deployment test
ansible.builtin.set_fact:
enable_timescale: true
when:
- not (ansible_distribution == 'Ubuntu' and ansible_distribution_version is version('20.04', '<'))
- not (ansible_distribution == 'Debian' and ansible_distribution_version is version('11', '>')) # TODO Debian 12

- name: Set variables for PostgreSQL upgrade test
ansible.builtin.set_fact:
pg_old_version: "12"
pg_new_version: "15"

- name: Clean yum cache (molecule containers)
ansible.builtin.command: yum clean all
when:
- ansible_os_family == "RedHat"
- ansible_distribution_major_version == '7'

- name: Clean dnf cache (molecule containers)
ansible.builtin.command: dnf clean all
when:
- ansible_os_family == "RedHat"
- ansible_distribution_major_version is version('8', '>=')

- name: Update apt cache (molecule containers)
ansible.builtin.apt:
update_cache: true
cache_valid_time: 3600
register: apt_status
until: apt_status is success
delay: 5
retries: 3
when: ansible_os_family == "Debian"

- name: Install openssh-server package (molecule containers)
become: true
ansible.builtin.package:
name: openssh-server
state: present

- name: Start ssh service (molecule containers)
become: true
ansible.builtin.systemd:
name: "{{ 'ssh' if ansible_os_family == 'Debian' else 'sshd' }}"
state: started
enabled: true

- name: Delete "/run/nologin" file (if exists)
become: true
ansible.builtin.file:
path: /run/nologin
state: absent

- name: Deploy PostgreSQL Cluster
ansible.builtin.import_playbook: ../../deploy_pgcluster.yml

- name: PostgreSQL upgrade test
ansible.builtin.import_playbook: ../../pg_upgrade.yml
94 changes: 94 additions & 0 deletions molecule/pg_upgrade/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
platforms:
- name: 10.172.2.20
hostname: pgnode01
image: "${IMAGE_NAMESPACE:-geerlingguy}/docker-${IMAGE_DISTRO:-ubuntu2204}-ansible:${IMAGE_TAG:-latest}"
networks:
- name: upgrade_test_docker_network
ipv4_address: 10.172.2.20
exposed_ports:
- 22/tcp
- 2379/tcp # if dcs_type: "etcd"
- 2380/tcp # if dcs_type: "etcd"
- 8300/tcp # if dcs_type: "consul"
- 8301/tcp # if dcs_type: "consul"
- 8302/tcp # if dcs_type: "consul"
- 8500/tcp # if dcs_type: "consul"
- 8600/tcp # if dcs_type: "consul"
- 8008/tcp
- 5432/tcp
- 6432/tcp
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
groups:
- etcd_cluster # if dcs_type: "etcd"
- consul_instances # if dcs_type: "consul"
- master
- postgres_cluster
- balancers

- name: 10.172.2.21
hostname: pgnode02
image: "${IMAGE_NAMESPACE:-geerlingguy}/docker-${IMAGE_DISTRO:-ubuntu2204}-ansible:${IMAGE_TAG:-latest}"
networks:
- name: upgrade_test_docker_network
ipv4_address: 10.172.2.21
exposed_ports:
- 22/tcp
- 2379/tcp
- 2380/tcp
- 8300/tcp
- 8301/tcp
- 8302/tcp
- 8500/tcp
- 8600/tcp
- 8008/tcp
- 5432/tcp
- 6432/tcp
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
groups:
- etcd_cluster
- consul_instances
- replica
- postgres_cluster
- balancers

- name: 10.172.2.22
hostname: pgnode03
image: "${IMAGE_NAMESPACE:-geerlingguy}/docker-${IMAGE_DISTRO:-ubuntu2204}-ansible:${IMAGE_TAG:-latest}"
networks:
- name: upgrade_test_docker_network
ipv4_address: 10.172.2.22
exposed_ports:
- 22/tcp
- 2379/tcp
- 2380/tcp
- 8300/tcp
- 8301/tcp
- 8302/tcp
- 8500/tcp
- 8600/tcp
- 8008/tcp
- 5432/tcp
- 6432/tcp
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
groups:
- etcd_cluster
- consul_instances
- replica
- postgres_cluster
- balancers
28 changes: 28 additions & 0 deletions molecule/pg_upgrade/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
- name: "Update docker network(s)"
hosts: localhost
gather_facts: false
become: false
tasks:
- name: "Create docker network: upgrade_test_docker_network"
community.docker.docker_network:
name: upgrade_test_docker_network
driver: bridge
driver_options:
com.docker.network.driver.mtu: 1440
enable_ipv6: false
internal: false
ipam_config:
- subnet: 10.172.2.0/24
gateway: 10.172.2.1
force: true
state: present
labels:
owner: molecule

- name: "Install netaddr dependency on controlling host"
ansible.builtin.pip:
name: netaddr
become: false

...
2 changes: 1 addition & 1 deletion molecule/tests/etcd/etcd.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Check etcd health
uri:
ansible.builtin.uri:
url: "http://{{ inventory_hostname }}:2379/health"
return_content: true
register: etcd_health_status
Expand Down
2 changes: 1 addition & 1 deletion molecule/tests/patroni/patroni.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Check Patroni status
uri:
ansible.builtin.uri:
url: "http://{{ inventory_hostname }}:8008/patroni"
return_content: true
register: patroni_status
Expand Down
6 changes: 4 additions & 2 deletions molecule/tests/postgres/postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
failed_when: result.rc != 0

- name: Check if PostgreSQL is listening on the default port
wait_for:
ansible.builtin.wait_for:
port: 5432
timeout: 5
register: is_listening
failed_when: not is_listening

- name: Try to connect to PostgreSQL
postgresql_ping:
login_host: "127.0.0.1"
login_port: "{{ postgresql_port }}"
login_user: "{{ patroni_superuser_username }}"
login_password: "{{ patroni_superuser_password }}"
db: template1
login_db: template1
6 changes: 4 additions & 2 deletions molecule/tests/postgres/replication.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
---
- name: Check PostgreSQL replication status
postgresql_query:
db: postgres
query: "SELECT * FROM pg_stat_wal_receiver;"
login_host: "127.0.0.1"
login_port: "{{ postgresql_port }}"
login_user: "{{ patroni_superuser_username }}"
login_password: "{{ patroni_superuser_password }}"
query: "SELECT * FROM pg_stat_wal_receiver;"
login_db: template1
register: pg_replication_status
failed_when: "pg_replication_status.rowcount == 0"
when: "'replica' in group_names"
Loading