diff --git a/defaults/main/package.yml b/defaults/main/package.yml index b5d4680..ba94bad 100644 --- a/defaults/main/package.yml +++ b/defaults/main/package.yml @@ -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: diff --git a/molecule/hold/converge.yml b/molecule/hold/converge.yml index 30b71f8..5f573d7 100644 --- a/molecule/hold/converge.yml +++ b/molecule/hold/converge.yml @@ -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: @@ -45,11 +64,12 @@ - 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 }}" @@ -57,12 +77,12 @@ _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 }}" @@ -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" diff --git a/molecule/hold/verify.yml b/molecule/hold/verify.yml index f74ccc4..a68e912 100644 --- a/molecule/hold/verify.yml +++ b/molecule/hold/verify.yml @@ -7,30 +7,49 @@ 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: @@ -38,16 +57,27 @@ _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 }}" @@ -55,12 +85,41 @@ _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 }}" @@ -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 @@ -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 @@ -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 diff --git a/tasks/install.yml b/tasks/install.yml index cd28fae..c36248c 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -43,9 +43,10 @@ name: "{{ _packages }}" state: "{{ postgresql_package_state }}" vars: - _server: "{{ [_postgresql_package_name] | flatten }}" + _client: "{{ [_postgresql_package_client] | flatten }}" + _server: "{{ [_postgresql_package_server] | flatten }}" _extra: "{{ [_postgresql_package_extra] | flatten }}" - _packages: "{{ _server + _extra }}" + _packages: "{{ _server + _client + _extra }}" when: ansible_os_family == 'Debian' - name: Install PostgreSQL yum server packages @@ -53,9 +54,10 @@ name: "{{ _packages | regex_replace('=', '-') }}" state: "{{ postgresql_package_state }}" vars: - _server: "{{ [_postgresql_package_name] | flatten }}" + _client: "{{ [_postgresql_package_client] | flatten }}" + _server: "{{ [_postgresql_package_server] | flatten }}" _extra: "{{ [_postgresql_package_extra] | flatten }}" - _packages: "{{ _server + _extra }}" + _packages: "{{ _server + _client + _extra }}" when: ansible_os_family == 'RedHat' always: diff --git a/tasks/lock.yml b/tasks/lock.yml index 37d8fed..9f414e9 100644 --- a/tasks/lock.yml +++ b/tasks/lock.yml @@ -8,7 +8,7 @@ selection: "{{ _lock_state }}" vars: _version_regex: ".*=.*" - _packages: "{{ ([_postgresql_package_name] | flatten) }}" + _packages: "{{ ([_postgresql_package_server + _postgresql_package_client] | flatten) }}" _package_versions: "{{ _packages | map('regex_search', _version_regex) }}" _package_holds: "{{ _package_versions | select('string') }}" _package_target: "{{ item.split('=') | first }}" @@ -24,7 +24,7 @@ state: "{{ 'absent' if _lock_state == 'install' else 'present' }}" vars: _version_regex: ".*=.*" - _packages: "{{ ([_postgresql_package_name] | flatten) }}" + _packages: "{{ ([_postgresql_package_server + _postgresql_package_client] | flatten) }}" _package_versions: "{{ _packages | map('regex_search', _version_regex) }}" _package_holds: "{{ _package_versions | select('string') }}" _package_target: "{{ item.split('=') | first }}" diff --git a/tasks/vars.yml b/tasks/vars.yml index aafa7f1..8a65581 100644 --- a/tasks/vars.yml +++ b/tasks/vars.yml @@ -4,7 +4,8 @@ - name: Set global facts ansible.builtin.set_fact: - _postgresql_package_name: "{{ postgresql_package_name | default(_default_package_name) }}" + _postgresql_package_server: "{{ postgresql_package_server | default(_default_package_server) }}" + _postgresql_package_client: "{{ postgresql_package_client | default(_default_package_server) }}" _postgresql_package_extra: "{{ postgresql_package_extra | default(_default_package_extra) }}" _postgresql_service_name: "{{ postgresql_service_name | default(_default_service) }}" _postgresql_user: "{{ postgresql_user }}" @@ -32,7 +33,8 @@ _postgresql_conf_exclude: "{{ __postgresql_conf_exclude }}" _postgresql_conf_search: "{{ _conf_search }}" vars: - _default_package_name: "{{ __postgresql_package_name | nephelaiio.plugins.sorted_get(_conf_search) }}" + _default_package_server: "{{ __postgresql_package_server | nephelaiio.plugins.sorted_get(_conf_search) }}" + _default_package_client: "{{ __postgresql_package_client | nephelaiio.plugins.sorted_get(_conf_search) }}" _default_package_extra: "{{ __postgresql_package_extra | nephelaiio.plugins.sorted_get(_conf_search) }}" _default_service: "{{ __postgresql_service_name | nephelaiio.plugins.sorted_get(_conf_search) }}" _conf_confdir: "{{ __postgresql_conf_dir }}"