Skip to content

Commit

Permalink
Split sever and client package params
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyphreak committed Apr 5, 2024
1 parent 076008c commit 297b40d
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 52 deletions.
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
81 changes: 65 additions & 16 deletions molecule/hold/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,47 @@
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 else _redhat_server_package.results }}"
_debian_server: "{{ [] if _debian_package_server.skipped else _debian_server_package.results }}"
_redhat_client: "{{ [] if _redhat_package_client.skipped else _redhat_client_package.results }}"
_debian_client: "{{ [] if _debian_package_client.skipped else _debian_client_package.results }}"

- name: Verify target package versions
ansible.builtin.fail:
Expand All @@ -45,24 +64,25 @@

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

- name: Set target Debian package versions
- name: Set target Debian server package versions
ansible.builtin.set_fact:
postgresql_package_name: "{{ postgresql_package_name + [_package] }}"
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_query }}"
loop: "{{ _postgresql_package_server_query }}"
when: ansible_os_family == "Debian"

- name: Set target RedHat package versions
- name: Set target RedHat server package versions
ansible.builtin.set_fact:
postgresql_package_name: "{{ postgresql_package_name + [_package] }}"
postgresql_package_server: "{{ postgresql_package_server + [_package] }}"
vars:
_stdout: "{{ item.stdout_lines }}"
_multiple: "{{ _stdout | length > 1 }}"
Expand All @@ -73,5 +93,34 @@
_package: "{{ _name }}={{ _version }}.{{ _arch }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _postgresql_package_query }}"
loop: "{{ _postgresql_package_server_query }}"
when: ansible_os_family == "RedHat"

- name: Set target Debian client package versions
ansible.builtin.set_fact:
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_client_query }}"
when: ansible_os_family == "Debian"

- name: Set target RedHat client package versions
ansible.builtin.set_fact:
postgresql_package_client: "{{ postgresql_package_client + [_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_client_query }}"
when: ansible_os_family == "RedHat"
155 changes: 129 additions & 26 deletions molecule/hold/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,119 @@
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 else _redhat_server_package.results }}"
_debian_server: "{{ [] if _debian_package_server.skipped else _debian_server_package.results }}"
_redhat_client: "{{ [] if _redhat_package_client.skipped else _redhat_client_package.results }}"
_debian_client: "{{ [] if _debian_package_client.skipped else _debian_client_package.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: []

- 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 +130,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 +161,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 +177,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

0 comments on commit 297b40d

Please sign in to comment.