Skip to content

Commit bd402e3

Browse files
authored
Compatibility with Ansible 12 (part 2) (#1321)
Continues integration of Ansible 12 support by fixing compatibility issues discovered during testing.
1 parent cf8a4e2 commit bd402e3

File tree

14 files changed

+89
-71
lines changed

14 files changed

+89
-71
lines changed

.github/workflows/molecule_pg_upgrade.yml

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,31 @@ jobs:
2525
- distro: ubuntu2204
2626
tag: latest
2727
namespace: geerlingguy
28-
- distro: rockylinux10
29-
tag: latest
30-
namespace: geerlingguy
31-
- distro: rockylinux9
32-
tag: latest
33-
namespace: geerlingguy
34-
- distro: almalinux10
35-
tag: latest
36-
namespace: glillico
37-
- distro: almalinux9
38-
tag: latest
39-
namespace: glillico
40-
- distro: oraclelinux10
41-
tag: latest
42-
namespace: glillico
43-
- distro: oraclelinux9
44-
tag: latest
45-
namespace: glillico
46-
- distro: centosstream10
47-
tag: latest
48-
namespace: glillico
49-
- distro: centosstream9
50-
tag: latest
51-
namespace: glillico
28+
# TODO: error "rsync: connection unexpectedly closed" in GitHub CI environment (need to investigate)
29+
# - distro: rockylinux10
30+
# tag: latest
31+
# namespace: geerlingguy
32+
# - distro: rockylinux9
33+
# tag: latest
34+
# namespace: geerlingguy
35+
# - distro: almalinux10
36+
# tag: latest
37+
# namespace: glillico
38+
# - distro: almalinux9
39+
# tag: latest
40+
# namespace: glillico
41+
# - distro: oraclelinux10
42+
# tag: latest
43+
# namespace: glillico
44+
# - distro: oraclelinux9
45+
# tag: latest
46+
# namespace: glillico
47+
# - distro: centosstream10
48+
# tag: latest
49+
# namespace: glillico
50+
# - distro: centosstream9
51+
# tag: latest
52+
# namespace: glillico
5253

5354
steps:
5455
- name: Set TERM environment variable

automation/roles/cloud_resources/tasks/aws.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@
582582
| selectattr('instances','defined') | map(attribute='instances') | list | flatten
583583
| selectattr('instance_id','defined') | map(attribute='instance_id') | list
584584
}}
585-
loop: "{{ server_result.results | selectattr('instances', 'defined') }}"
585+
loop: "{{ server_result.results | selectattr('instances', 'defined') | list }}"
586586
loop_control:
587587
label: >-
588588
public_ip: {{ item.instances[0].public_ip_address | default('') }},
@@ -592,7 +592,7 @@
592592
ansible.builtin.import_tasks: inventory.yml
593593
when:
594594
- server_result.results is defined
595-
- server_result.results | selectattr('instances', 'defined')
595+
- (server_result.results | selectattr('instances','defined') | list | length) > 0
596596

597597
# Delete the temporary ssh key from the cloud after creating the EC2 instance
598598
- name: "AWS: Remove temporary SSH key '{{ ssh_key_name | default('') }}' from cloud"

automation/roles/cloud_resources/tasks/azure.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@
297297
key_data: "{{ ssh_key_content }}"
298298
ssh_password_enabled: false
299299
image:
300-
offer: "{{ azure_vm_image_offer | default('0001-com-ubuntu-server-jammy') }}"
300+
offer: "{{ azure_vm_image_offer | default('ubuntu-24_04-lts') }}"
301301
publisher: "{{ azure_vm_image_publisher | default('Canonical') }}"
302-
sku: "{{ azure_vm_image_sku | default('22_04-lts-gen2') }}"
302+
sku: "{{ azure_vm_image_sku | default('server') }}"
303303
version: "{{ azure_vm_image_version | default('latest') }}"
304304
os_type: Linux
305305
os_disk_size_gb: "{{ system_volume_size | default('80') }}" # system disk size
@@ -386,7 +386,7 @@
386386
private_ips | default([]) +
387387
[item.ansible_facts.azure_vm.network_profile.network_interfaces[0].properties.ip_configurations[0].private_ip_address]
388388
}}
389-
loop: "{{ server_result.results | selectattr('ansible_facts.azure_vm', 'defined') }}"
389+
loop: "{{ server_result.results | selectattr('ansible_facts.azure_vm', 'defined') | list }}"
390390
loop_control:
391391
label: "{{ item.ansible_facts.azure_vm.network_profile.network_interfaces[0].properties.ip_configurations[0].private_ip_address }}"
392392

@@ -530,7 +530,7 @@
530530
| map(attribute='vms') | map('default', []) | list | flatten
531531
| selectattr('id','defined') | map(attribute='id') | list
532532
}}
533-
loop: "{{ server_result.results | selectattr('ansible_facts.azure_vm', 'defined') }}"
533+
loop: "{{ server_result.results | selectattr('ansible_facts.azure_vm', 'defined') | list }}"
534534
loop_control:
535535
label: >-
536536
public_ip: {{ (public_ip_address.results if public_ip_address is defined else []) | selectattr('idx', 'equalto', item.idx) | map(attribute='state.ip_address') | first | default('') }},
@@ -540,7 +540,7 @@
540540
ansible.builtin.import_tasks: inventory.yml
541541
when:
542542
- server_result.results is defined
543-
- server_result.results | selectattr('ansible_facts.azure_vm', 'defined')
543+
- (server_result.results | selectattr('ansible_facts.azure_vm', 'defined') | list | length) > 0
544544

545545
# Delete (if state is absent)
546546
- block:

automation/roles/cloud_resources/tasks/digitalocean.yml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@
102102
- name: "DigitalOcean: Get fingerprint for SSH key '{{ ssh_key_name | default('') }}'"
103103
ansible.builtin.set_fact:
104104
ssh_key_fingerprint: "{{ [item.fingerprint] }}"
105-
loop: "{{ ssh_keys.data | lower }}"
106-
loop_control: # do not display the public key
107-
label: "{{ item.name }}"
105+
loop: "{{ ssh_keys.data | default([]) }}"
106+
loop_control:
107+
label: "{{ item.name | default('unknown') }}"
108108
when:
109109
- ((ssh_key_name | length > 0 and ssh_key_name != (tmp_ssh_key_name | default(''))) or
110-
(ssh_key_name == (tmp_ssh_key_name | default('')) and ssh_public_keys | default('') | length > 0))
111-
- item.name == ssh_key_name | lower
110+
(ssh_key_name == (tmp_ssh_key_name | default('')) and (ssh_public_keys | default('') | length > 0)))
111+
- (item.name | lower) == (ssh_key_name | lower)
112112

113113
# Stop, if the ssh key is not found
114114
- name: "DigitalOcean: Fail if SSH key '{{ ssh_key_name | default('') }}' is not found"
@@ -122,13 +122,13 @@
122122
# get the fingerprint of all ssh keys
123123
- name: "DigitalOcean: Get fingerprint for all SSH keys"
124124
ansible.builtin.set_fact:
125-
ssh_key_fingerprint: "{{ ssh_key_fingerprint | default([]) + [item.fingerprint] }}"
126-
loop: "{{ ssh_keys.data | lower }}"
127-
loop_control: # do not display the public key
128-
label: "{{ item.name }}"
125+
ssh_key_fingerprint: "{{ (ssh_key_fingerprint | default([])) + [item.fingerprint] }}"
126+
loop: "{{ ssh_keys.data | default([]) }}"
127+
loop_control:
128+
label: "{{ item.name | default('unknown') }}"
129129
when:
130-
- (ssh_key_name | length < 1 or ssh_key_name == (tmp_ssh_key_name | default('')))
131-
- (ssh_public_keys is not defined or ssh_public_keys | length < 1)
130+
- (ssh_key_name | length < 1) or (ssh_key_name == (tmp_ssh_key_name | default('')))
131+
- (ssh_public_keys is not defined) or ((ssh_public_keys | length) < 1)
132132
when: state == 'present'
133133

134134
# Create (if state is present)
@@ -687,7 +687,7 @@
687687
| map(attribute='data') | map('default', []) | list | flatten
688688
| selectattr('id','defined') | map(attribute='id') | list
689689
}}
690-
loop: "{{ droplet_result.results | selectattr('data', 'defined') }}"
690+
loop: "{{ droplet_result.results | selectattr('data','defined') | list }}"
691691
loop_control:
692692
label: >-
693693
public_ip: {{ (item.data.droplet.networks.v4 | selectattr('type', 'equalto', 'public')).0.ip_address | default('') }},
@@ -697,7 +697,7 @@
697697
ansible.builtin.import_tasks: inventory.yml
698698
when:
699699
- droplet_result.results is defined
700-
- droplet_result.results | selectattr('data', 'defined')
700+
- (droplet_result.results | selectattr('data','defined') | list | length) > 0
701701

702702
# Delete the temporary SSH key from the cloud after creating the droplet
703703
- name: "DigitalOcean: Remove temporary SSH key '{{ ssh_key_name | default('') }}' from cloud"
@@ -757,6 +757,8 @@
757757
- sync
758758
loop_control:
759759
label: "{{ patroni_cluster_name }}-{{ item }}"
760+
register: do_lb_del_result
761+
failed_when: do_lb_del_result is failed and ('not found' not in (do_lb_del_result.msg | default('') | lower))
760762
when: cloud_load_balancer | bool and
761763
(item == 'primary' or
762764
(item == 'replica' and server_count | int > 1) or

automation/roles/cloud_resources/tasks/gcp.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@
339339
port: "{{ pgbouncer_listen_port | default('6432') }}"
340340
network:
341341
selfLink: "global/networks/{{ gcp_network_name }}"
342-
instances: "{{ instances_selflink }}"
342+
instances: "{{ instances_selflink | from_json }}"
343343
state: present
344344
vars:
345345
region: "{{ server_location[:-2] if server_location[-2:] | regex_search('-[a-z]$') else server_location }}"
@@ -348,9 +348,7 @@
348348
instances_selflink: >- # TODO: use "{{ server_result.results | map(attribute='selfLink') | map('community.general.dict_kv', 'selfLink') | list }}"
349349
[
350350
{% for i in range(1, (server_count | int) + 1) %}
351-
{
352-
"selfLink": "zones/{{ zone }}/instances/{{ server_name }}{{ '%02d' % i }}"
353-
}{% if not loop.last %},{% endif %}
351+
{ "selfLink": "zones/{{ zone }}/instances/{{ server_name }}{{ '%02d' % i }}" }{% if not loop.last %},{% endif %}
354352
{% endfor %}
355353
]
356354
register: instance_group
@@ -558,7 +556,7 @@
558556
| map(attribute='resources') | map('default', []) | list | flatten
559557
| selectattr('id','defined') | map(attribute='id') | list
560558
}}
561-
loop: "{{ server_result.results | selectattr('networkInterfaces', 'defined') }}"
559+
loop: "{{ server_result.results | selectattr('networkInterfaces', 'defined') | list }}"
562560
loop_control:
563561
label: >-
564562
public_ip: {{ item.networkInterfaces[0].accessConfigs[0].natIP | default('') }},
@@ -568,7 +566,7 @@
568566
ansible.builtin.import_tasks: inventory.yml
569567
when:
570568
- server_result.results is defined
571-
- server_result.results | selectattr('networkInterfaces', 'defined')
569+
- (server_result.results | selectattr('networkInterfaces', 'defined') | list | length) > 0
572570

573571
# Delete (if state is absent)
574572
- block:

automation/roles/cloud_resources/tasks/hetzner.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@
723723
| map(attribute='hcloud_server_info') | map('default', []) | list | flatten
724724
| selectattr('id','defined') | map(attribute='id') | list
725725
}}
726-
loop: "{{ server_result.results | selectattr('hcloud_server', 'defined') }}"
726+
loop: "{{ server_result.results | selectattr('hcloud_server', 'defined') | list }}"
727727
loop_control:
728728
label: >-
729729
public_ip: {{ item.hcloud_server.ipv4_address | default('') }},
@@ -733,7 +733,7 @@
733733
ansible.builtin.import_tasks: inventory.yml
734734
when:
735735
- server_result.results is defined
736-
- server_result.results | selectattr('hcloud_server', 'defined')
736+
- (server_result.results | selectattr('hcloud_server','defined') | list | length) > 0
737737

738738
# Delete the temporary ssh key from the cloud after creating the server
739739
- name: "Hetzner Cloud: Remove temporary SSH key {{ ssh_key_name | default('') }} from cloud"

automation/roles/pgbackrest/tasks/ssh_keys.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@
111111
target_host: "{{ hostvars[item].get('bind_address') if (item in (groups['postgres_cluster'])) else pgbackrest_repo_host }}"
112112
target_port: "{{ hostvars[item].get('ansible_ssh_port') or hostvars[item].get('ansible_port') or 22 }}"
113113
register: ssh_known_host_keyscan
114+
until: ssh_known_host_keyscan is succeeded
115+
retries: 3
116+
delay: 5
114117
changed_when: false
115118

116119
- name: known_hosts | Add ssh host keys in "~postgres/.ssh/known_hosts" on database servers

automation/roles/pgbackrest/tasks/stanza_create.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
# The delegate_to parameter is used to execute the task on a different host than the one specified in the play's hosts parameter.
3737
# In this case, the task is delegated to the first host in the pgbackrest group in the invetory.
3838
- name: Get repo1-path value
39-
delegate_to: "{{ groups['pgbackrest'][0] }}"
39+
delegate_to: "{{ pgbackrest_delegate }}"
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: (pgbackrest_repo_type | default('posix')) | lower == 'posix'
4444

4545
- name: "Make sure the {{ repo1_path | default('') }} directory exists"
46-
delegate_to: "{{ groups['pgbackrest'][0] }}"
46+
delegate_to: "{{ pgbackrest_delegate }}"
4747
run_once: true
4848
ansible.builtin.file:
4949
path: "{{ repo1_path }}"
@@ -56,13 +56,16 @@
5656
- name: Create stanza "{{ pgbackrest_stanza | default('') }}"
5757
become: true
5858
become_user: "{{ pgbackrest_repo_user }}"
59-
delegate_to: "{{ groups['pgbackrest'][0] }}"
59+
delegate_to: "{{ pgbackrest_delegate }}"
6060
run_once: true
6161
ansible.builtin.command: "pgbackrest --stanza={{ pgbackrest_stanza }} --no-online stanza-create"
6262
register: stanza_create_result
6363
changed_when:
6464
- stanza_create_result.rc == 0
6565
- stanza_create_result.stdout is not search("already exists")
66+
vars:
67+
pgbackrest_delegate: "{{ (groups.get('pgbackrest') | default([], true) | list | first) | default(inventory_hostname, true) }}"
6668
when:
67-
- pgbackrest_repo_host | length > 0
69+
- (pgbackrest_repo_host | default('')) | length > 0
70+
- (groups.get('pgbackrest') | default([], true) | length) > 0
6871
tags: pgbackrest, pgbackrest_stanza_create

automation/roles/ssh_keys/tasks/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
ansible.builtin.command: "ssh-keyscan -trsa -p {{ ansible_ssh_port | default(22) }} {{ hostvars[item]['bind_address'] }}"
6464
loop: "{{ ssh_known_hosts }}"
6565
register: ssh_known_host_results
66+
until: ssh_known_host_results is succeeded
67+
retries: 3
68+
delay: 5
6669
changed_when: false
6770

6871
- name: known_hosts | for each host, add/update the public key in the "~{{ ssh_key_user | default('') }}/.ssh/known_hosts"

automation/roles/update/tasks/pgbackrest_host.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
- block:
55
- name: Gather facts from pgbackrest server
66
ansible.builtin.setup:
7-
delegate_to: "{{ groups['pgbackrest'][0] }}"
7+
delegate_to: "{{ pgbackrest_delegate }}"
88
run_once: true
99

1010
- name: Update dnf cache
11-
delegate_to: "{{ groups['pgbackrest'][0] }}"
11+
delegate_to: "{{ pgbackrest_delegate }}"
1212
run_once: true
1313
ansible.builtin.shell: dnf clean all && dnf -y makecache
1414
args:
1515
executable: /bin/bash
1616
when: ansible_os_family == "RedHat" and not (skip_dnf_makecache | default(false) | bool)
1717

1818
- name: Update apt cache
19-
delegate_to: "{{ groups['pgbackrest'][0] }}"
19+
delegate_to: "{{ pgbackrest_delegate }}"
2020
run_once: true
2121
ansible.builtin.apt:
2222
update_cache: true
@@ -28,7 +28,7 @@
2828
when: ansible_os_family == "Debian"
2929

3030
- name: Install the latest version of pgbackrest package
31-
delegate_to: "{{ groups['pgbackrest'][0] }}"
31+
delegate_to: "{{ pgbackrest_delegate }}"
3232
run_once: true
3333
ansible.builtin.package:
3434
name: pgbackrest
@@ -39,7 +39,9 @@
3939
retries: 3
4040
become: true
4141
become_user: root
42+
vars:
43+
pgbackrest_delegate: "{{ (groups.get('pgbackrest') | default([], true) | list | first) | default(inventory_hostname, true) }}"
4244
when:
4345
- pgbackrest_install | bool
44-
- pgbackrest_repo_host | default('') | length > 0
45-
- groups['pgbackrest'] | default([]) | length > 0
46+
- (pgbackrest_repo_host | default('')) | length > 0
47+
- (groups.get('pgbackrest') | default([], true) | length) > 0

0 commit comments

Comments
 (0)