1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

postgresql_info: add in_recovery return value to show if a service in recovery mode or not (#1091) (#1093)

* postgresql_info: add in_recovery return value to show if a service is in recovery mode or not

* add changelog fragment

* fix sanity

(cherry picked from commit da7f9ffc3f)

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
This commit is contained in:
patchback[bot] 2020-10-14 14:59:21 +03:00 committed by GitHub
parent ee8f87412a
commit efa884b64a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- postgresql_info - add ``in_recovery`` return value to show if a service in recovery mode or not (https://github.com/ansible-collections/community.general/issues/1068).

View file

@ -18,7 +18,7 @@ options:
description: description:
- Limit the collected information by comma separated string or YAML list. - Limit the collected information by comma separated string or YAML list.
- Allowable values are C(version), - Allowable values are C(version),
C(databases), C(settings), C(tablespaces), C(roles), C(databases), C(in_recovery), C(settings), C(tablespaces), C(roles),
C(replications), C(repl_slots). C(replications), C(repl_slots).
- By default, collects all subsets. - By default, collects all subsets.
- You can use shell-style (fnmatch) wildcard to pass groups of values (see Examples). - You can use shell-style (fnmatch) wildcard to pass groups of values (see Examples).
@ -117,6 +117,11 @@ version:
returned: always returned: always
type: int type: int
sample: 1 sample: 1
in_recovery:
description: Indicates if the service is in recovery mode or not.
returned: always
type: bool
sample: false
databases: databases:
description: Information about databases. description: Information about databases.
returned: always returned: always
@ -550,6 +555,7 @@ class PgClusterInfo(object):
self.cursor = db_conn_obj.connect() self.cursor = db_conn_obj.connect()
self.pg_info = { self.pg_info = {
"version": {}, "version": {},
"in_recovery": None,
"tablespaces": {}, "tablespaces": {},
"databases": {}, "databases": {},
"replications": {}, "replications": {},
@ -563,6 +569,7 @@ class PgClusterInfo(object):
"""Collect information based on 'filter' option.""" """Collect information based on 'filter' option."""
subset_map = { subset_map = {
"version": self.get_pg_version, "version": self.get_pg_version,
"in_recovery": self.get_recovery_state,
"tablespaces": self.get_tablespaces, "tablespaces": self.get_tablespaces,
"databases": self.get_db_info, "databases": self.get_db_info,
"replications": self.get_repl_info, "replications": self.get_repl_info,
@ -922,6 +929,10 @@ class PgClusterInfo(object):
minor=int(raw[1]), minor=int(raw[1]),
) )
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]
def get_db_info(self): def get_db_info(self):
"""Get information about the current database.""" """Get information about the current database."""
# Following query returns: # Following query returns:

View file

@ -63,6 +63,7 @@
- assert: - assert:
that: that:
- result.version != {} - result.version != {}
- result.in_recovery == false
- result.databases.{{ db_default }}.collate - result.databases.{{ db_default }}.collate
- result.databases.{{ db_default }}.languages - result.databases.{{ db_default }}.languages
- result.databases.{{ db_default }}.namespaces - result.databases.{{ db_default }}.namespaces
@ -81,11 +82,13 @@
filter: filter:
- ver* - ver*
- rol* - rol*
- in_recov*
- assert: - assert:
that: that:
- result.version != {} - result.version != {}
- result.roles - result.roles
- result.in_recovery == false
- result.databases == {} - result.databases == {}
- result.repl_slots == {} - result.repl_slots == {}
- result.replications == {} - result.replications == {}
@ -126,10 +129,12 @@
filter: filter:
- "!ver*" - "!ver*"
- "!rol*" - "!rol*"
- "!in_rec*"
- assert: - assert:
that: that:
- result.version == {} - result.version == {}
- result.in_recovery == None
- result.roles == {} - result.roles == {}
- result.databases - result.databases
@ -144,6 +149,7 @@
- assert: - assert:
that: that:
- result.version != {} - result.version != {}
- result.in_recovery == false
- result.databases.{{ db_default }}.collate - result.databases.{{ db_default }}.collate
- result.databases.{{ db_default }}.languages - result.databases.{{ db_default }}.languages
- result.databases.{{ db_default }}.namespaces - result.databases.{{ db_default }}.namespaces