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_info: add full, raw, and patch ret version values #68

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/68-postgresql_info_add_ret_values.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- postgresql_info - add the ``patch``, ``full``, and ``raw`` values of the ``version`` return value (https://github.com/ansible-collections/community.postgresql/pull/68).
37 changes: 34 additions & 3 deletions plugins/modules/postgresql_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@
returned: always
type: int
sample: 1
patch:
description: Patch server version.
returned: if supported
type: int
sample: 5
version_added: '1.2.0'
full:
description: Full server version.
returned: always
type: str
sample: '13.2'
version_added: '1.2.0'
raw:
description: Full output returned by ``SELECT version()``.
returned: always
type: str
sample: 'PostgreSQL 13.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9), 64-bit'
version_added: '1.2.0'
in_recovery:
description: Indicates if the service is in recovery mode or not.
returned: always
Expand Down Expand Up @@ -925,12 +943,25 @@ def get_pg_version(self):
"""Get major and minor PostgreSQL server version."""
query = "SELECT version()"
raw = self.__exec_sql(query)[0][0]
raw = raw.split()[1].split('.')
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.pg_info["version"] = dict(
major=int(raw[0]),
minor=int(raw[1].rstrip(',')),
major=major,
minor=minor,
full=full,
raw=raw,
)

if patch is not None:
self.pg_info["version"]["patch"] = patch

def get_recovery_state(self):
"""Get if the service is in recovery mode."""
self.pg_info["in_recovery"] = self.__exec_sql("SELECT pg_is_in_recovery()")[0][0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
- assert:
that:
- result.version != {}
- result.version.raw is search('PostgreSQL')
- result.in_recovery == false
- result.databases.{{ db_default }}.collate
- result.databases.{{ db_default }}.languages
Expand All @@ -74,6 +75,17 @@
- result.tablespaces
- result.roles

- assert:
that:
- result.version.patch != {}
- result.version.full == '{{ result.version.major }}.{{ result.version.minor }}.{{ result.version.patch }}'
when: result.version.major == 9

- assert:
that:
- result.version.full == '{{ result.version.major }}.{{ result.version.minor }}'
when: result.version.major >= 10

- name: postgresql_info - check filter param passed by list
<<: *task_parameters
postgresql_info:
Expand Down