Skip to content

Commit ebdcd28

Browse files
committed
Improve pgbackrest group handling in Ansible tasks
Updated the usage of groups.get('pgbackrest') and related defaults in stanza_create.yml, pgbackrest_host.yml, and post_upgrade.yml to use the 'default' filter with 'true' and ensure proper type handling. This change improves robustness when the 'pgbackrest' group is missing or empty.
1 parent 670d306 commit ebdcd28

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

automation/roles/pgbackrest/tasks/stanza_create.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
- stanza_create_result.rc == 0
6565
- stanza_create_result.stdout is not search("already exists")
6666
vars:
67-
pgbackrest_delegate: "{{ (groups.get('pgbackrest') | default([]) | first) | default(inventory_hostname) }}"
67+
pgbackrest_delegate: "{{ (groups.get('pgbackrest') | default([], true) | list | first) | default(inventory_hostname, true) }}"
6868
when:
69-
- pgbackrest_repo_host | default('') | length > 0
70-
- groups.get('pgbackrest', []) | length > 0
69+
- (pgbackrest_repo_host | default('')) | length > 0
70+
- (groups.get('pgbackrest') | default([], true) | length) > 0
7171
tags: pgbackrest, pgbackrest_stanza_create

automation/roles/update/tasks/pgbackrest_host.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
become: true
4141
become_user: root
4242
vars:
43-
pgbackrest_delegate: "{{ (groups.get('pgbackrest') | default([]) | first) | default(inventory_hostname) }}"
43+
pgbackrest_delegate: "{{ (groups.get('pgbackrest') | default([], true) | list | first) | default(inventory_hostname, true) }}"
4444
when:
4545
- pgbackrest_install | bool
46-
- pgbackrest_repo_host | default('') | length > 0
47-
- groups.get('pgbackrest', []) | length > 0
46+
- (pgbackrest_repo_host | default('')) | length > 0
47+
- (groups.get('pgbackrest') | default([], true) | length) > 0

automation/roles/upgrade/tasks/post_upgrade.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@
152152
become_user: "{{ pgbackrest_repo_user }}"
153153
ignore_errors: true # show the error and continue the playbook execution
154154
vars:
155-
pgbackrest_delegate: "{{ (groups.get('pgbackrest') | default([]) | first) | default(inventory_hostname) }}"
155+
pgbackrest_delegate: "{{ (groups.get('pgbackrest') | default([], true) | list | first) | default(inventory_hostname, true) }}"
156156
when:
157157
- pgbackrest_install | bool
158-
- pgbackrest_repo_host | default('') | length > 0
159-
- groups.get('pgbackrest', []) | length > 0
158+
- (pgbackrest_repo_host | default('')) | length > 0
159+
- (groups.get('pgbackrest') | default([], true) | length) > 0
160160

161161
# WAL-G
162162
- block:

0 commit comments

Comments
 (0)