Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split sever and client package params #28

Merged
merged 6 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions defaults/main/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ __postgresql_package_extra:
debian:
- "postgresql-{{ postgresql_release }}-pgaudit"
- "postgresql-{{ postgresql_release }}-cron"
__postgresql_package_name:
__postgresql_package_server:
redhat:
- "postgresql{{ postgresql_release }}-server"
- "postgresql{{ postgresql_release }}-contrib"
- "postgresql{{ postgresql_release }}"
debian:
- "postgresql-{{ postgresql_release }}"
__postgresql_package_client:
redhat:
- "postgresql{{ postgresql_release }}"
debian:
- "postgresql-client-{{ postgresql_release }}"

__postgresql_bindir:
Expand Down
96 changes: 78 additions & 18 deletions molecule/hold/converge.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- name: Deploy PostgreSQL servers

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / lint

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (hold, debian12, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (initdb, debian12, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (stop, debian11, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (initdb, rockylinux9, /usr/lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (hold, debian11, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (initdb, debian11, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (stop, debian12, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (hold, ubuntu2004, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (hold, ubuntu2204, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (mask, debian12, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (stop, rockylinux9, /usr/lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (stop, ubuntu2204, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (initdb, ubuntu2204, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (stop, ubuntu2004, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (mask, rockylinux9, /usr/lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (mask, ubuntu2204, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (configure, debian11, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (mask, ubuntu2004, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (configure, debian12, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (deploy, ubuntu2004, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (deploy, debian12, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (initdb, ubuntu2004, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (databases, debian11, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (hold, rockylinux9, /usr/lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (deploy, debian11, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (databases, rockylinux9, /usr/lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (mask, debian11, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (configure, ubuntu2004, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (configure, rockylinux9, /usr/lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (deploy, rockylinux9, /usr/lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (deploy, ubuntu2204, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (configure, ubuntu2204, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (databases, ubuntu2004, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (databases, ubuntu2204, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/converge.yml

View workflow job for this annotation

GitHub Actions / molecule (databases, debian12, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"
hosts: all
become: true
roles:
Expand All @@ -9,60 +9,120 @@
name: nephelaiio.postgresql
tasks_from: vars.yml

- name: Query Debian package versions
- name: Query Debian server package versions
ansible.builtin.shell:
cmd: "apt-cache madison {{ item }} | awk -F'|' '{ print $2 }'"
loop: "{{ _postgresql_package_name }}"
register: _debian_package_query
loop: "{{ _postgresql_package_server }}"
register: _debian_package_server
when: ansible_os_family == "Debian"
changed_when: false

- name: Query RedHat package versions
- name: Query Debian client package versions
ansible.builtin.shell:
cmd: "apt-cache madison {{ item }} | awk -F'|' '{ print $2 }'"
loop: "{{ _postgresql_package_client }}"
register: _debian_package_client
when: ansible_os_family == "Debian"
changed_when: false

- name: Query RedHat server package versions
ansible.builtin.shell:
cmd: "yum list {{ item }} --showduplicates | grep '^{{ item }}' | awk '{ print $1,$2 }' | sort -r"
loop: "{{ _postgresql_package_name }}"
register: _redhat_package_query
loop: "{{ _postgresql_package_server }}"
register: _redhat_package_server
when: ansible_os_family == "RedHat"
changed_when: false

- name: Query RedHat client package versions
ansible.builtin.shell:
cmd: "yum list {{ item }} --showduplicates | grep '^{{ item }}' | awk '{ print $1,$2 }' | sort -r"
loop: "{{ _postgresql_package_client }}"
register: _redhat_package_client
when: ansible_os_family == "RedHat"
changed_when: false

- name: Set package version facts
ansible.builtin.set_fact:
_postgresql_package_query: "{{ _redhat_packages + _debian_packages }}"
_postgresql_package_server_query: "{{ _redhat_server + _debian_server }}"
_postgresql_package_client_query: "{{ _redhat_client + _debian_client }}"
vars:
_redhat_packages: "{{ [] if _redhat_package_query.skipped else _redhat_package_query.results }}"
_debian_packages: "{{ [] if _debian_package_query.skipped else _debian_package_query.results }}"
_redhat_server: "{{ [] if (_redhat_package_server.skipped | default(True)) else _redhat_package_server.results }}"
_debian_server: "{{ [] if (_debian_package_server.skipped | default(True)) else _debian_package_server.results }}"
_redhat_client: "{{ [] if (_redhat_package_client.skipped | default(True)) else _redhat_package_client.results }}"
_debian_client: "{{ [] if (_debian_package_client.skipped | default(True)) else _debian_package_client.results }}"

- name: Verify target package versions
- name: Verify target server package versions
ansible.builtin.fail:
msg: "{{ _package }} has no installation candidate: {{ item }}"
vars:
_stdout: "{{ item.stdout_lines }}"
_package: "{{ item.item }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _postgresql_package_query }}"
loop: "{{ _postgresql_package_server_query }}"
when: _stdout | length == 0

- name: Verify target client package versions
ansible.builtin.fail:
msg: "{{ _package }} has no installation candidate: {{ item }}"
vars:
_stdout: "{{ item.stdout_lines }}"
_package: "{{ item.item }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _postgresql_package_client_query }}"
when: _stdout | length == 0

- name: Initialize package versions
ansible.builtin.set_fact:
postgresql_package_name: []
postgresql_package_server: []
postgresql_package_client: []

- name: Set target Debian server package versions
ansible.builtin.set_fact:
postgresql_package_server: "{{ postgresql_package_server + [_package] }}"
vars:
_stdout: "{{ item.stdout_lines }}"
_multiple: "{{ _stdout | length > 1 }}"
_version: "{{ _stdout[0] if not _multiple else _stdout[1] }}"
_package: "{{ item.item }}={{ _version | trim }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _postgresql_package_server_query }}"
when: ansible_os_family == "Debian"

- name: Set target RedHat server package versions
ansible.builtin.set_fact:
postgresql_package_server: "{{ postgresql_package_server + [_package] }}"
vars:
_stdout: "{{ item.stdout_lines }}"
_multiple: "{{ _stdout | length > 1 }}"
_target: "{{ (_stdout[0] if not _multiple else _stdout[1]).split(' ') }}"
_arch: "{{ _target[0].split('.')[1] }}"
_name: "{{ _target[0].split('.')[0] }}"
_version: "{{ _target[1] }}"
_package: "{{ _name }}={{ _version }}.{{ _arch }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _postgresql_package_server_query }}"
when: ansible_os_family == "RedHat"

- name: Set target Debian package versions
- name: Set target Debian client package versions
ansible.builtin.set_fact:
postgresql_package_name: "{{ postgresql_package_name + [_package] }}"
postgresql_package_client: "{{ postgresql_package_client + [_package] }}"
vars:
_stdout: "{{ item.stdout_lines }}"
_multiple: "{{ _stdout | length > 1 }}"
_version: "{{ _stdout[0] if not _multiple else _stdout[1] }}"
_package: "{{ item.item }}={{ _version | trim }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _postgresql_package_query }}"
loop: "{{ _postgresql_package_client_query }}"
when: ansible_os_family == "Debian"

- name: Set target RedHat package versions
- name: Set target RedHat client package versions
ansible.builtin.set_fact:
postgresql_package_name: "{{ postgresql_package_name + [_package] }}"
postgresql_package_client: "{{ postgresql_package_client + [_package] }}"
vars:
_stdout: "{{ item.stdout_lines }}"
_multiple: "{{ _stdout | length > 1 }}"
Expand All @@ -73,5 +133,5 @@
_package: "{{ _name }}={{ _version }}.{{ _arch }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _postgresql_package_query }}"
loop: "{{ _postgresql_package_client_query }}"
when: ansible_os_family == "RedHat"
156 changes: 130 additions & 26 deletions molecule/hold/verify.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- name: Verify PostgreSQL deployment

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / lint

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (hold, debian12, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (initdb, debian12, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (stop, debian11, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (initdb, rockylinux9, /usr/lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (hold, debian11, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (initdb, debian11, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (stop, debian12, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (hold, ubuntu2004, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (hold, ubuntu2204, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (mask, debian12, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (stop, rockylinux9, /usr/lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (stop, ubuntu2204, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (initdb, ubuntu2204, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (stop, ubuntu2004, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (mask, rockylinux9, /usr/lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (mask, ubuntu2204, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (configure, debian11, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (mask, ubuntu2004, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (configure, debian12, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (deploy, ubuntu2004, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (deploy, debian12, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (initdb, ubuntu2004, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (databases, debian11, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (hold, rockylinux9, /usr/lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (deploy, debian11, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (databases, rockylinux9, /usr/lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (mask, debian11, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (configure, ubuntu2004, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (configure, rockylinux9, /usr/lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (deploy, rockylinux9, /usr/lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (deploy, ubuntu2204, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (configure, ubuntu2204, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (databases, ubuntu2004, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (databases, ubuntu2204, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"

Check warning on line 1 in molecule/hold/verify.yml

View workflow job for this annotation

GitHub Actions / molecule (databases, debian12, /lib/systemd/systemd)

1:1 [document-start] missing document start "---"
hosts: all
become: true
tasks:
Expand All @@ -7,60 +7,120 @@
name: nephelaiio.postgresql
tasks_from: vars.yml

- name: Query Debian package versions
- name: Query Debian server package versions
ansible.builtin.shell:
cmd: "apt-cache madison {{ item }} | awk -F'|' '{ print $2 }'"
loop: "{{ _postgresql_package_name }}"
register: _debian_package_query
loop: "{{ _postgresql_package_server }}"
register: _debian_package_server
when: ansible_os_family == "Debian"
changed_when: false

- name: Query RedHat package versions
- name: Query Debian client package versions
ansible.builtin.shell:
cmd: "apt-cache madison {{ item }} | awk -F'|' '{ print $2 }'"
loop: "{{ _postgresql_package_client }}"
register: _debian_package_client
when: ansible_os_family == "Debian"
changed_when: false

- name: Query RedHat server package versions
ansible.builtin.shell:
cmd: "yum list {{ item }} --showduplicates | grep '^{{ item }}' | awk '{ print $1,$2 }' | sort -r"
loop: "{{ _postgresql_package_server }}"
register: _redhat_package_server
when: ansible_os_family == "RedHat"
changed_when: false

- name: Query RedHat client package versions
ansible.builtin.shell:
cmd: "yum list {{ item }} --showduplicates | grep '^{{ item }}' | awk '{ print $1,$2 }' | sort -r"
loop: "{{ _postgresql_package_name }}"
register: _redhat_package_query
loop: "{{ _postgresql_package_client }}"
register: _redhat_package_client
when: ansible_os_family == "RedHat"
changed_when: false

- name: Set package version facts
ansible.builtin.set_fact:
_postgresql_package_query: "{{ _redhat_packages + _debian_packages }}"
_postgresql_package_server_query: "{{ _redhat_server + _debian_server }}"
_postgresql_package_client_query: "{{ _redhat_client + _debian_client }}"
vars:
_redhat_packages: "{{ [] if _redhat_package_query.skipped else _redhat_package_query.results }}"
_debian_packages: "{{ [] if _debian_package_query.skipped else _debian_package_query.results }}"
_redhat_server: "{{ [] if (_redhat_package_server.skipped | default(True)) else _redhat_package_server.results }}"
_debian_server: "{{ [] if (_debian_package_server.skipped | default(True)) else _debian_package_server.results }}"
_redhat_client: "{{ [] if (_redhat_package_client.skipped | default(True)) else _redhat_package_client.results }}"
_debian_client: "{{ [] if (_debian_package_client.skipped | default(True)) else _debian_package_client.results }}"

- name: Verify target package versions
- name: Verify target server package versions
ansible.builtin.fail:
msg: "{{ _package }} has no installation candidate: {{ item }}"
vars:
_stdout: "{{ item.stdout_lines }}"
_package: "{{ item.item }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _postgresql_package_query }}"
loop: "{{ _postgresql_package_server_query }}"
when: _stdout | length == 0

- name: Verify target client package versions
ansible.builtin.fail:
msg: "{{ _package }} has no installation candidate: {{ item }}"
vars:
_stdout: "{{ item.stdout_lines }}"
_package: "{{ item.item }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _postgresql_package_client_query }}"
when: _stdout | length == 0

- name: Initialize package versions
ansible.builtin.set_fact:
postgresql_package_list: []
postgresql_package_server_list: []
postgresql_package_client_list: []

- name: Set target Debian package versions
- name: Set target Debian server package versions
ansible.builtin.set_fact:
postgresql_package_list: "{{ postgresql_package_list + [_package] }}"
postgresql_package_server_list: "{{ postgresql_package_server_list + [_package] }}"
vars:
_stdout: "{{ item.stdout_lines }}"
_multiple: "{{ _stdout | length > 1 }}"
_version: "{{ _stdout[0] if not _multiple else _stdout[1] }}"
_package: "{{ item.item }}={{ _version | trim }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _postgresql_package_query }}"
loop: "{{ _postgresql_package_server_query }}"
when: ansible_os_family == "Debian"

- name: Set target RedHat package versions
- name: Set target Debian client package versions
ansible.builtin.set_fact:
postgresql_package_client_list: "{{ postgresql_package_client_list + [_package] }}"
vars:
_stdout: "{{ item.stdout_lines }}"
_multiple: "{{ _stdout | length > 1 }}"
_version: "{{ _stdout[0] if not _multiple else _stdout[1] }}"
_package: "{{ item.item }}={{ _version | trim }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _postgresql_package_client_query }}"
when: ansible_os_family == "Debian"

- name: Set target RedHat server package versions
ansible.builtin.set_fact:
postgresql_package_server_list: "{{ postgresql_package_server_list + [_package] }}"
vars:
_stdout: "{{ item.stdout_lines }}"
_multiple: "{{ _stdout | length > 1 }}"
_target: "{{ (_stdout[0] if not _multiple else _stdout[1]).split(' ') }}"
_arch: "{{ _target[0].split('.')[1] }}"
_name: "{{ _target[0].split('.')[0] }}"
_version: "{{ _target[1] }}"
_package: "{{ _name }}-{{ _version }}.{{ _arch }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _postgresql_package_server_query }}"
when: ansible_os_family == "RedHat"

- name: Set target RedHat client package versions
ansible.builtin.set_fact:
postgresql_package_list: "{{ postgresql_package_list + [_package] }}"
postgresql_package_client_list: "{{ postgresql_package_client_list + [_package] }}"
vars:
_stdout: "{{ item.stdout_lines }}"
_multiple: "{{ _stdout | length > 1 }}"
Expand All @@ -71,13 +131,27 @@
_package: "{{ _name }}-{{ _version }}.{{ _arch }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _postgresql_package_query }}"
loop: "{{ _postgresql_package_client_query }}"
when: ansible_os_family == "RedHat"

- name: Gather package facts
ansible.builtin.package_facts:

- name: Verify package versions
- name: Verify Debian server package versions
ansible.builtin.assert:
that:
- _package in packages
- _version == _installed
fail_msg: "Expected {{ _package }}={{ _version }}, found {{ _package }}={{ _installed }}"
success_msg: "Found {{ _package }}={{ _version }}"
vars:
_package: "{{ item.split('=') | first }}"
_version: "{{ item.split('=') | last }}"
_installed: "{{ (packages[_package] | default([{'version': 'None'}]))[0].version }}"
loop: "{{ postgresql_package_server_list }}"
when: ansible_os_family == "Debian"

- name: Verify Debian client package versions
ansible.builtin.assert:
that:
- _package in packages
Expand All @@ -88,10 +162,10 @@
_package: "{{ item.split('=') | first }}"
_version: "{{ item.split('=') | last }}"
_installed: "{{ (packages[_package] | default([{'version': 'None'}]))[0].version }}"
loop: "{{ postgresql_package_list }}"
loop: "{{ postgresql_package_client_list }}"
when: ansible_os_family == "Debian"

- name: Verify package versions
- name: Verify RedHat server package versions
ansible.builtin.assert:
that:
- _package in packages
Expand All @@ -104,19 +178,49 @@
_package: "{{ item.0 }}"
_version: "{{ item.1 | regex_replace(_prefix, '') | regex_replace(_suffix, '') }}"
_installed: "{{ (packages[_package] | default([{'version': 'None'}]))[0].version }}"
loop: "{{ _postgresql_package_name | zip(postgresql_package_list) }}"
loop: "{{ _postgresql_package_server | zip(postgresql_package_server_list) }}"
when: ansible_os_family == "RedHat"

- name: Verify apt package locks
- name: Verify RedHat client package versions
ansible.builtin.assert:
that:
- _package in packages
- _version == _installed
fail_msg: "Expected {{ _package }}={{ _version }}, found {{ _package }}={{ _installed }}"
success_msg: "Found {{ _package }}={{ _version }}"
vars:
_prefix: "^{{ _package }}-"
_suffix: "-.*$"
_package: "{{ item.0 }}"
_version: "{{ item.1 | regex_replace(_prefix, '') | regex_replace(_suffix, '') }}"
_installed: "{{ (packages[_package] | default([{'version': 'None'}]))[0].version }}"
loop: "{{ _postgresql_package_client | zip(postgresql_package_client_list) }}"
when: ansible_os_family == "RedHat"

- name: Verify apt server package locks
ansible.builtin.command:
cmd: "apt-mark showhold | grep {{ item }}"
loop: "{{ _postgresql_package_name }}"
loop: "{{ _postgresql_package_server }}"
when: ansible_os_family == "Debian"
changed_when: false

- name: Verify yum package locks
- name: Verify apt client package locks
ansible.builtin.command:
cmd: "apt-mark showhold | grep {{ item }}"
loop: "{{ _postgresql_package_client }}"
when: ansible_os_family == "Debian"
changed_when: false

- name: Verify yum server package locks
ansible.builtin.command:
cmd: "grep {{ item }} /etc/yum/pluginconf.d/versionlock.list"
loop: "{{ _postgresql_package_server }}"
when: ansible_os_family == "RedHat"
changed_when: false

- name: Verify yum client package locks
ansible.builtin.command:
cmd: "grep {{ item }} /etc/yum/pluginconf.d/versionlock.list"
loop: "{{ _postgresql_package_name }}"
loop: "{{ _postgresql_package_client }}"
when: ansible_os_family == "RedHat"
changed_when: false
Loading