|
96 | 96 | # pgBackRest (local)
|
97 | 97 | - block:
|
98 | 98 | - 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 }}" |
100 | 100 | register: pg_path_count
|
101 | 101 | changed_when: false
|
102 | 102 |
|
103 | 103 | - name: pgbackrest | Update pg-path in pgbackrest.conf
|
104 |
| - ansible.builtin.lineinfile: |
| 104 | + ansible.builtin.replace: |
105 | 105 | 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 }}' |
108 | 108 | loop: "{{ range(0, pg_path_count.stdout | int) | list }}"
|
109 | 109 | loop_control:
|
110 | 110 | index_var: idx
|
111 | 111 | label: "pg{{ idx + 1 }}-path={{ pg_new_datadir }}"
|
112 |
| - when: pg_path_count.stdout | length > 0 |
| 112 | + when: pg_path_count.stdout | int > 0 |
113 | 113 |
|
114 | 114 | - name: pgbackrest | Upgrade stanza "{{ pgbackrest_stanza }}"
|
115 | 115 | 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 |
117 | 117 | become: true
|
118 | 118 | become_user: postgres
|
119 | 119 | ignore_errors: true # show the error and continue the playbook execution
|
120 | 120 | when:
|
121 | 121 | - pgbackrest_install | bool
|
122 |
| - - pgbackrest_repo_host | length < 1 |
123 | 122 |
|
124 | 123 | # pgBackRest (dedicated)
|
125 | 124 | - block:
|
126 | 125 | - name: pgbackrest | Check pg-path option
|
127 | 126 | delegate_to: "{{ groups['pgbackrest'][0] }}"
|
128 | 127 | 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" |
130 | 129 | register: pg_path_count
|
131 | 130 | changed_when: false
|
132 | 131 |
|
133 | 132 | - name: pgbackrest | Update pg-path in pgbackrest.conf
|
134 | 133 | delegate_to: "{{ groups['pgbackrest'][0] }}"
|
135 | 134 | run_once: true
|
136 |
| - ansible.builtin.lineinfile: |
| 135 | + ansible.builtin.replace: |
137 | 136 | 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 }}' |
140 | 139 | loop: "{{ range(0, pg_path_count.stdout | int) | list }}"
|
141 | 140 | loop_control:
|
142 | 141 | index_var: idx
|
143 | 142 | label: "pg{{ idx + 1 }}-path={{ pg_new_datadir }}"
|
144 |
| - when: pg_path_count.stdout | length > 0 |
| 143 | + when: pg_path_count.stdout | int > 0 |
145 | 144 |
|
146 | 145 | - name: pgbackrest | Upgrade stanza "{{ pgbackrest_stanza }}"
|
147 | 146 | delegate_to: "{{ groups['pgbackrest'][0] }}"
|
148 | 147 | run_once: true
|
149 | 148 | 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 |
151 | 150 | become: true
|
152 | 151 | become_user: "{{ pgbackrest_repo_user }}"
|
153 | 152 | ignore_errors: true # show the error and continue the playbook execution
|
|
0 commit comments