From 3208f496cc584d2f6c83f3bb9f3325e3eeb94737 Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Tue, 23 Mar 2021 07:30:56 +0100 Subject: [PATCH 1/2] postgresql_ping: add full and raw fields to server_version return value --- plugins/modules/postgresql_ping.py | 33 ++++++++++++++----- .../tasks/postgresql_ping_initial.yml | 12 +++++++ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/plugins/modules/postgresql_ping.py b/plugins/modules/postgresql_ping.py index 5424fd9f7..8affd0199 100644 --- a/plugins/modules/postgresql_ping.py +++ b/plugins/modules/postgresql_ping.py @@ -71,7 +71,7 @@ description: PostgreSQL server version. returned: always type: dict - sample: { major: 10, minor: 1 } + sample: { major: 13, minor: 2, full: '13.2', raw: 'PostgreSQL 13.2 on x86_64-pc-linux-gnu' } ''' try: @@ -112,13 +112,30 @@ def do(self): def get_pg_version(self): query = "SELECT version()" raw = exec_sql(self, query, add_to_executed=False)[0][0] - if raw: - self.is_available = True - raw = raw.split()[1].split('.') - self.version = dict( - major=int(raw[0]), - minor=int(raw[1].rstrip(',')), - ) + + if not raw: + return + + self.is_available = True + + full = raw.split()[1] + tmp = full.split('.') + + major = int(tmp[0]) + minor = int(tmp[1].rstrip(',')) + patch = None + if len(tmp) >= 3: + patch = int(tmp[2].rstrip(',')) + + self.version = dict( + major=major, + minor=minor, + full=full, + raw=raw, + ) + + if patch is not None: + self.version['patch'] = patch # =========================================== diff --git a/tests/integration/targets/postgresql_ping/tasks/postgresql_ping_initial.yml b/tests/integration/targets/postgresql_ping/tasks/postgresql_ping_initial.yml index 9d35d91c1..5c9735bb6 100644 --- a/tests/integration/targets/postgresql_ping/tasks/postgresql_ping_initial.yml +++ b/tests/integration/targets/postgresql_ping/tasks/postgresql_ping_initial.yml @@ -15,10 +15,22 @@ that: - result.is_available == true - result.server_version != {} + - result.server_version.raw is search('PostgreSQL') - result.server_version.major != false - result.server_version.minor != false - result is not changed +- assert: + that: + - result.server_version.patch != {} + - result.server_version.full == '{{ result.server_version.major }}.{{ result.server_version.minor }}.{{ result.server_version.patch }}' + when: result.server_version.major == 9 + +- assert: + that: + - result.server_version.full == '{{ result.server_version.major }}.{{ result.server_version.minor }}' + when: result.server_version.major >= 10 + - name: postgresql_ping - check ping of non-existing database doesn't return anything become_user: "{{ pg_user }}" become: yes From 5cae1d245df3f92f6360c8c3ae9221012cff3ef5 Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Tue, 23 Mar 2021 07:34:16 +0100 Subject: [PATCH 2/2] Add a changelog fragment --- changelogs/fragments/70-postgresql_ping_add_ret_values.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/70-postgresql_ping_add_ret_values.yml diff --git a/changelogs/fragments/70-postgresql_ping_add_ret_values.yml b/changelogs/fragments/70-postgresql_ping_add_ret_values.yml new file mode 100644 index 000000000..50bb43c7b --- /dev/null +++ b/changelogs/fragments/70-postgresql_ping_add_ret_values.yml @@ -0,0 +1,2 @@ +minor_changes: +- postgresql_ping - add the ``patch``, ``full``, and ``raw`` values of the ``server_version`` return value (https://github.com/ansible-collections/community.postgresql/pull/70).