Skip to content

Commit 636abaf

Browse files
committed
Improve pgbackrest stanza creation task checks
Refines conditional logic in stanza_create.yml to ensure tasks only run when pgbackrest_delegate is defined. Updates delegate variable assignment to handle missing group gracefully, improving robustness in environments where the pgbackrest group may be absent.
1 parent 9512c20 commit 636abaf

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

automation/roles/pgbackrest/tasks/stanza_create.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
run_once: true
4141
ansible.builtin.set_fact:
4242
repo1_path: "{{ pgbackrest_server_conf['global'] | selectattr('option', 'equalto', 'repo1-path') | map(attribute='value') | list | first }}"
43-
when: pgbackrest_repo_type | lower == 'posix'
43+
when:
44+
- (pgbackrest_repo_type | default('posix')) | lower == 'posix'
45+
- pgbackrest_delegate is not none
4446

4547
- name: "Make sure the {{ repo1_path | default('') }} directory exists"
4648
delegate_to: "{{ pgbackrest_delegate }}"
@@ -51,7 +53,9 @@
5153
owner: "{{ pgbackrest_repo_user }}"
5254
group: "{{ pgbackrest_repo_user }}"
5355
mode: "0750"
54-
when: repo1_path | default('') | length > 0
56+
when:
57+
- pgbackrest_delegate is not none
58+
- repo1_path | default('') | length > 0
5559

5660
- name: Create stanza "{{ pgbackrest_stanza | default('') }}"
5761
become: true
@@ -63,8 +67,9 @@
6367
changed_when:
6468
- stanza_create_result.rc == 0
6569
- stanza_create_result.stdout is not search("already exists")
70+
when: pgbackrest_delegate is not none
6671
vars:
67-
pgbackrest_delegate: "{{ groups.get('pgbackrest', []) | first }}"
72+
pgbackrest_delegate: "{{ (groups.get('pgbackrest') or [None])[0] }}"
6873
when:
6974
- pgbackrest_repo_host | default('') | length > 0
7075
- groups.get('pgbackrest', []) | length > 0

0 commit comments

Comments
 (0)