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

postgresql_ping: add patch, full, and raw fields to server_version return value #70

Merged
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
2 changes: 2 additions & 0 deletions changelogs/fragments/70-postgresql_ping_add_ret_values.yml
Original file line number Diff line number Diff line change
@@ -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).
33 changes: 25 additions & 8 deletions plugins/modules/postgresql_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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


# ===========================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down