Skip to content

Commit 9ce1754

Browse files
authored
pg_upgrade.yml: Add ‘string’ filter for postgresql version variables (#777)
1 parent 65939d6 commit 9ce1754

File tree

12 files changed

+48
-48
lines changed

12 files changed

+48
-48
lines changed

automation/molecule/default/converge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
dcs_type: "{{ ['etcd', 'consul'] | random }}" # Set 'dcs_type' to either 'etcd' or 'consul' randomly
1717
consul_node_role: server # if dcs_type: "consul"
1818
consul_bootstrap_expect: true # if dcs_type: "consul"
19-
postgresql_version: "16" # to test custom WAL dir
19+
postgresql_version: 16 # to test custom WAL dir
2020
pgbouncer_processes: 2 # Test multiple pgbouncer processes (so_reuseport)
2121
patroni_tags: "datacenter=dc1,key1=value1"
2222
balancer_tags: "datacenter=dc1"

automation/molecule/pg_upgrade/converge.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
dcs_type: "{{ ['etcd', 'consul'] | random }}" # Set 'dcs_type' to either 'etcd' or 'consul' randomly
1717
consul_node_role: server # if dcs_type: "consul"
1818
consul_bootstrap_expect: true # if dcs_type: "consul"
19-
postgresql_version: "14" # redefine the version to install for the upgrade test
19+
postgresql_version: 14 # redefine the version to install for the upgrade test
2020
pgbouncer_processes: 4 # Test multiple pgbouncer processes (so_reuseport)
2121
cacheable: true
2222
delegate_to: localhost
@@ -43,8 +43,8 @@
4343

4444
- name: Set variables for PostgreSQL upgrade test
4545
ansible.builtin.set_fact:
46-
pg_old_version: "14"
47-
pg_new_version: "16"
46+
pg_old_version: 14
47+
pg_new_version: 16
4848

4949
- name: Add repository GPG key
5050
ansible.builtin.command: "rpm --import https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux-{{ ansible_distribution_major_version }}"

automation/roles/add-repository/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
- ansible_distribution == "OracleLinux"
9898
- ansible_distribution_major_version is version('8', '>=')
9999
vars:
100-
pg_devel_package: "postgresql{{ postgresql_version | replace('.', '') }}-devel"
100+
pg_devel_package: "postgresql{{ postgresql_version | string | replace('.', '') }}-devel"
101101
when:
102102
- pg_devel_package in postgresql_packages
103103

automation/roles/upgrade/tasks/pgbouncer_pause.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
where pid <> pg_backend_pid()
4040
and state <> 'idle'
4141
and query_start < clock_timestamp() - interval '{{ pg_slow_active_query_treshold }} ms'
42-
{{ "and backend_type = 'client backend'" if pg_old_version is version('10', '>=') else '' }}
42+
{{ "and backend_type = 'client backend'" if pg_old_version | string is version('10', '>=') else '' }}
4343
pg_slow_active_terminate_query: >-
4444
select
4545
clock_timestamp(),
@@ -50,7 +50,7 @@
5050
where pid <> pg_backend_pid()
5151
and state <> 'idle'
5252
and query_start < clock_timestamp() - interval '{{ pg_slow_active_query_treshold_to_terminate }} ms'
53-
{{ "and backend_type = 'client backend'" if pg_old_version is version('10', '>=') else '' }}
53+
{{ "and backend_type = 'client backend'" if pg_old_version | string is version('10', '>=') else '' }}
5454
pgb_unix_socket_dirs: >-
5555
{% set unix_socket_dir = ['/var/run/pgbouncer'] %}
5656
{%- for idx in range(1, pgbouncer_processes | default(1) | int) -%}

automation/roles/upgrade/tasks/post_upgrade.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# if pg_new_wal_dir is defined
3535
- name: Delete the old PostgreSQL WAL directory
3636
ansible.builtin.file:
37-
path: "{{ postgresql_wal_dir | regex_replace('(/$)', '') | regex_replace(postgresql_version, pg_old_version) }}"
37+
path: "{{ postgresql_wal_dir | regex_replace('(/$)', '') | replace(postgresql_version | string, pg_old_version | string) }}"
3838
state: absent
3939
when:
4040
- pg_current_datadir is success
@@ -48,14 +48,14 @@
4848
ansible.builtin.package:
4949
name: "{{ item }}"
5050
state: absent
51-
loop: "{{ postgresql_packages | regex_replace(postgresql_version, pg_old_version) }}"
51+
loop: "{{ postgresql_packages | replace(postgresql_version | string, pg_old_version | string) }}"
5252
register: package_remove
5353
until: package_remove is success
5454
delay: 5
5555
retries: 3
5656
ignore_errors: true # show the error and continue the playbook execution
5757
when:
58-
- item is search(pg_old_version)
58+
- item | string is search(pg_old_version | string)
5959
- pg_old_packages_remove | bool
6060
- ansible_os_family == "RedHat"
6161

@@ -67,14 +67,14 @@
6767
name: "{{ item }}"
6868
state: absent
6969
purge: true
70-
loop: "{{ postgresql_packages | regex_replace(postgresql_version, pg_old_version) }}"
70+
loop: "{{ postgresql_packages | replace(postgresql_version | string, pg_old_version | string) }}"
7171
register: apt_remove
7272
until: apt_remove is success
7373
delay: 5
7474
retries: 3
7575
ignore_errors: true # show the error and continue the playbook execution
7676
when:
77-
- item is search(pg_old_version)
77+
- item | string is search(pg_old_version | string)
7878
- pg_old_packages_remove | bool
7979
- ansible_os_family == "Debian"
8080

@@ -159,14 +159,14 @@
159159
- name: "WAL-G | Update PostgreSQL data directory path in .walg.json"
160160
ansible.builtin.replace:
161161
path: "{{ postgresql_home_dir }}/.walg.json"
162-
regexp: "{{ postgresql_data_dir | regex_replace(postgresql_version, pg_old_version) }}"
163-
replace: "{{ postgresql_data_dir | regex_replace(postgresql_version, pg_new_version) }}"
162+
regexp: "{{ postgresql_data_dir | replace(postgresql_version | string, pg_old_version | string) }}"
163+
replace: "{{ postgresql_data_dir | replace(postgresql_version | string, pg_new_version | string) }}"
164164

165165
- name: "WAL-G | Update PostgreSQL data directory path in cron jobs"
166166
ansible.builtin.replace:
167167
path: "{{ wal_g_cron_jobs[0].file | default('/etc/cron.d/walg') }}"
168-
regexp: "{{ postgresql_data_dir | regex_replace(postgresql_version, pg_old_version) }}"
169-
replace: "{{ postgresql_data_dir | regex_replace(postgresql_version, pg_new_version) }}"
168+
regexp: "{{ postgresql_data_dir | replace(postgresql_version | string, pg_old_version | string) }}"
169+
replace: "{{ postgresql_data_dir | replace(postgresql_version | string, pg_new_version | string) }}"
170170
become: true
171171
become_user: root
172172
ignore_errors: true # show the error and continue the playbook execution

automation/roles/upgrade/tasks/pre_checks.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
msg:
88
- "One or more required variables have empty values."
99
- "Please specify a value for the variables: pg_old_version, pg_new_version"
10-
failed_when: pg_old_version | length < 1 or pg_new_version | length < 1
11-
when: pg_old_version | length < 1 or pg_new_version | length < 1
10+
failed_when: pg_old_version | string | length < 1 or pg_new_version | string | length < 1
11+
when: pg_old_version | string | length < 1 or pg_new_version | string | length < 1
1212

1313
# Stop, if the directories of the old and new versions are the same
1414
- name: "Make sure that the old and new data and config directories do not match"
@@ -66,7 +66,7 @@
6666
changed_when: false
6767
when:
6868
- inventory_hostname in groups['primary']
69-
- pg_old_version is version('10', '>=')
69+
- pg_old_version | string is version('10', '>=')
7070

7171
# for compatibility with Postgres 9.x
7272
- name: '[Pre-Check] Check the current version of PostgreSQL'
@@ -77,11 +77,11 @@
7777
changed_when: false
7878
when:
7979
- inventory_hostname in groups['primary']
80-
- pg_old_version is version('10', '<')
80+
- pg_old_version | string is version('10', '<')
8181

8282
- name: "Set variable 'current_pg_version'"
8383
ansible.builtin.set_fact:
84-
current_pg_version: "{{ pg_current_version.stdout if pg_old_version is version('10', '>=') else pg_current_version_9x.stdout }}"
84+
current_pg_version: "{{ pg_current_version.stdout if pg_old_version | string is version('10', '>=') else pg_current_version_9x.stdout }}"
8585
when:
8686
- inventory_hostname in groups['primary']
8787

@@ -168,7 +168,7 @@
168168
delay: 5
169169
when:
170170
- inventory_hostname in groups['primary']
171-
- pg_old_version is version('10', '>=')
171+
- pg_old_version | string is version('10', '>=')
172172

173173
# Stop, if replication lag is high
174174
- name: "Pre-Check error. High replication lag"
@@ -195,7 +195,7 @@
195195
delay: 5
196196
when:
197197
- inventory_hostname in groups['primary']
198-
- pg_old_version is version('10', '<')
198+
- pg_old_version | string is version('10', '<')
199199

200200
# Stop, if replication lag is high (for 9x)
201201
- name: "Pre-Check error. High replication lag"
@@ -223,7 +223,7 @@
223223
until: pg_long_transactions.stdout | length < 1
224224
retries: 30 # 1 minute
225225
delay: 2
226-
when: pg_old_version is version('10', '>=')
226+
when: pg_old_version | string is version('10', '>=')
227227

228228
# Stop, if long-running transactions detected
229229
- block:
@@ -254,7 +254,7 @@
254254
until: pg_long_transactions_9x.stdout | length < 1
255255
retries: 30 # 1 minute
256256
delay: 2
257-
when: pg_old_version is version('10', '<')
257+
when: pg_old_version | string is version('10', '<')
258258

259259
# Stop, if long-running transactions detected (for 9x)
260260
- block:

automation/roles/upgrade/tasks/rollback.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
- "The old cluster will need to be restored from backup."
8484
when:
8585
- inventory_hostname in groups['primary']
86-
- pg_control_version.stdout == pg_new_version | replace('.', '')
86+
- pg_control_version.stdout == pg_new_version | string | replace('.', '')
8787

8888
# Restore the old Patroni configuration
8989
- name: '[Rollback] Restore the old patroni.yml configuration file'

automation/roles/upgrade/tasks/statistics.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
poll: 0
4040
register: pg_terminator_analyze
4141
ignore_errors: true # ignore errors if the task runs for over an 'vacuumdb_analyze_timeout'.
42-
when: pg_new_version is version('9.6', '>=')
42+
when: pg_new_version | string is version('9.6', '>=')
4343

4444
# Monitor long-running transactions and terminate them (for more than 'vacuumdb_analyze_terminate_treshold')
4545
- name: "pg_terminator: Monitor and terminate the long-running transactions (more than {{ max_tx_sec }} seconds) during collecting statistics"
@@ -68,7 +68,7 @@
6868
ignore_errors: true # ignore errors if the task runs for over an 'vacuumdb_analyze_timeout'.
6969
vars:
7070
max_tx_sec: "{{ vacuumdb_analyze_terminate_treshold }}"
71-
when: pg_new_version is version('10', '>=') and vacuumdb_analyze_terminate_treshold | int > 0
71+
when: pg_new_version | string is version('10', '>=') and vacuumdb_analyze_terminate_treshold | int > 0
7272

7373
# ANALYZE
7474
- name: "Run vacuumdb to analyze the PostgreSQL databases"

automation/roles/upgrade/tasks/stop_services.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
failed_when: false
3030
when:
3131
- inventory_hostname in groups['primary']
32-
- pg_old_version is version('10', '>=')
32+
- pg_old_version | string is version('10', '>=')
3333

3434
# Stop, if replication lag is high
3535
- block:
@@ -62,7 +62,7 @@
6262
failed_when: false
6363
when:
6464
- inventory_hostname in groups['primary']
65-
- pg_old_version is version('10', '<')
65+
- pg_old_version | string is version('10', '<')
6666

6767
# Stop, if replication lag is high (for 9x)
6868
- block:

automation/roles/upgrade/tasks/upgrade_secondary.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
become_user: postgres
5050
when:
5151
- inventory_hostname in groups['primary']
52-
- pg_old_datadir|dirname == pg_upper_datadir + '/' + pg_old_version
53-
- pg_new_datadir|dirname == pg_upper_datadir + '/' + pg_new_version
52+
- pg_old_datadir|dirname == pg_upper_datadir + '/' + (pg_old_version | string)
53+
- pg_new_datadir|dirname == pg_upper_datadir + '/' + (pg_new_version | string)
5454

5555
# If the source and target directories are non-versioned directories
5656
# (example: /pgdata/main -> /pgdata/main<pg_new_version>)
@@ -81,8 +81,8 @@
8181
become_user: postgres
8282
when:
8383
- inventory_hostname in groups['primary']
84-
- pg_old_datadir|dirname != pg_upper_datadir + '/' + pg_old_version
85-
- pg_new_datadir|dirname != pg_upper_datadir + '/' + pg_new_version
84+
- pg_old_datadir|dirname != pg_upper_datadir + '/' + (pg_old_version | string)
85+
- pg_new_datadir|dirname != pg_upper_datadir + '/' + (pg_new_version | string)
8686

8787
# Tablespaces (if exists)
8888
- block:

0 commit comments

Comments
 (0)