Skip to content

Commit 5d5a185

Browse files
authored
Fix (Upgrade): Update pg-path in local pgbackrest.conf (vitabaks#700)
1 parent 3b24f6e commit 5d5a185

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

roles/upgrade/tasks/post_upgrade.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,58 +96,57 @@
9696
# pgBackRest (local)
9797
- block:
9898
- name: pgbackrest | Check pg-path option
99-
ansible.builtin.command: "grep -c '^pg.*-path=' {{ pgbackrest_conf_file }}"
99+
ansible.builtin.command: "grep -c '^pg[0-9]*-path=' {{ pgbackrest_conf_file }}"
100100
register: pg_path_count
101101
changed_when: false
102102

103103
- name: pgbackrest | Update pg-path in pgbackrest.conf
104-
ansible.builtin.lineinfile:
104+
ansible.builtin.replace:
105105
path: "{{ pgbackrest_conf_file }}"
106-
regexp: '^pg{{ idx + 1 }}-path='
107-
line: 'pg{{ idx + 1 }}-path={{ pg_new_datadir }}'
106+
regexp: '^pg{{ idx + 1 }}-path=.*$'
107+
replace: 'pg{{ idx + 1 }}-path={{ pg_new_datadir }}'
108108
loop: "{{ range(0, pg_path_count.stdout | int) | list }}"
109109
loop_control:
110110
index_var: idx
111111
label: "pg{{ idx + 1 }}-path={{ pg_new_datadir }}"
112-
when: pg_path_count.stdout | length > 0
112+
when: pg_path_count.stdout | int > 0
113113

114114
- name: pgbackrest | Upgrade stanza "{{ pgbackrest_stanza }}"
115115
ansible.builtin.command: "pgbackrest --stanza={{ pgbackrest_stanza }} --no-online stanza-upgrade"
116-
when: pg_path_count.stdout | length > 0 and pgbackrest_stanza_upgrade | bool
116+
when: pg_path_count.stdout | int > 0 and pgbackrest_stanza_upgrade | bool and pgbackrest_repo_host | length < 1
117117
become: true
118118
become_user: postgres
119119
ignore_errors: true # show the error and continue the playbook execution
120120
when:
121121
- pgbackrest_install | bool
122-
- pgbackrest_repo_host | length < 1
123122

124123
# pgBackRest (dedicated)
125124
- block:
126125
- name: pgbackrest | Check pg-path option
127126
delegate_to: "{{ groups['pgbackrest'][0] }}"
128127
run_once: true
129-
ansible.builtin.command: "grep -c '^pg.*-path=' {{ pgbackrest_conf_file | dirname }}/conf.d/{{ pgbackrest_stanza }}.conf"
128+
ansible.builtin.command: "grep -c '^pg[0-9]*-path=' {{ pgbackrest_conf_file | dirname }}/conf.d/{{ pgbackrest_stanza }}.conf"
130129
register: pg_path_count
131130
changed_when: false
132131

133132
- name: pgbackrest | Update pg-path in pgbackrest.conf
134133
delegate_to: "{{ groups['pgbackrest'][0] }}"
135134
run_once: true
136-
ansible.builtin.lineinfile:
135+
ansible.builtin.replace:
137136
path: "{{ pgbackrest_conf_file | dirname }}/conf.d/{{ pgbackrest_stanza }}.conf"
138-
regexp: '^pg{{ idx + 1 }}-path='
139-
line: 'pg{{ idx + 1 }}-path={{ pg_new_datadir }}'
137+
regexp: '^pg{{ idx + 1 }}-path=.*$'
138+
replace: 'pg{{ idx + 1 }}-path={{ pg_new_datadir }}'
140139
loop: "{{ range(0, pg_path_count.stdout | int) | list }}"
141140
loop_control:
142141
index_var: idx
143142
label: "pg{{ idx + 1 }}-path={{ pg_new_datadir }}"
144-
when: pg_path_count.stdout | length > 0
143+
when: pg_path_count.stdout | int > 0
145144

146145
- name: pgbackrest | Upgrade stanza "{{ pgbackrest_stanza }}"
147146
delegate_to: "{{ groups['pgbackrest'][0] }}"
148147
run_once: true
149148
ansible.builtin.command: "pgbackrest --stanza={{ pgbackrest_stanza }} --no-online stanza-upgrade"
150-
when: pg_path_count.stdout | length > 0 and pgbackrest_stanza_upgrade | bool
149+
when: pg_path_count.stdout | int > 0 and pgbackrest_stanza_upgrade | bool
151150
become: true
152151
become_user: "{{ pgbackrest_repo_user }}"
153152
ignore_errors: true # show the error and continue the playbook execution

0 commit comments

Comments
 (0)