Skip to content

Commit

Permalink
postgresql_info: add full, raw, and patch ret version values (#68)
Browse files Browse the repository at this point in the history
* postgresql_info: add full, raw, and patch ret version values

* Add a changelog fragment

* Fix sanity

* Update plugins/modules/postgresql_info.py

Co-authored-by: Felix Fontein <[email protected]>

Co-authored-by: Felix Fontein <[email protected]>
  • Loading branch information
Andersson007 and felixfontein authored Mar 22, 2021
1 parent 5b87db2 commit 2149692
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
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

0 comments on commit 2149692

Please sign in to comment.