From eca33b80f02473d548095b9449eb907573c5770d Mon Sep 17 00:00:00 2001 From: Yap Sok Ann Date: Thu, 10 Oct 2019 17:14:49 +0700 Subject: [PATCH] mysql_info: add support for global status (#63189) Signed-off-by: Yap Sok Ann --- .../modules/database/mysql/mysql_info.py | 20 +++++++++++++++++-- .../targets/mysql_info/tasks/main.yml | 3 +++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/database/mysql/mysql_info.py b/lib/ansible/modules/database/mysql/mysql_info.py index cb28a7df35..0c3ccd6fb6 100644 --- a/lib/ansible/modules/database/mysql/mysql_info.py +++ b/lib/ansible/modules/database/mysql/mysql_info.py @@ -25,8 +25,8 @@ options: filter: description: - Limit the collected information by comma separated string or YAML list. - - Allowable values are C(version), C(databases), C(settings), C(users), - C(slave_status), C(slave_hosts), C(master_status), C(engines). + - Allowable values are C(version), C(databases), C(settings), C(global_status), + C(users), C(engines), C(master_status), C(slave_status), C(slave_hosts). - By default, collects all subsets. - You can use '!' before value (for example, C(!settings)) to exclude it from the information. - If you pass including and excluding values to the filter, for example, I(filter=!settings,version), @@ -129,6 +129,12 @@ settings: type: dict sample: - { "innodb_open_files": 300, innodb_page_size": 16384 } +global_status: + description: Global status information. + returned: if not excluded by filter + type: dict + sample: + - { "Innodb_buffer_pool_read_requests": 123, "Innodb_buffer_pool_reads": 32 } users: description: Users information. returned: if not excluded by filter @@ -203,6 +209,7 @@ class MySQL_Info(object): 'version': {}, 'databases': {}, 'settings': {}, + 'global_status': {}, 'engines': {}, 'users': {}, 'master_status': {}, @@ -255,6 +262,7 @@ class MySQL_Info(object): """Collect all possible subsets.""" self.__get_databases() self.__get_global_variables() + self.__get_global_status() self.__get_engines() self.__get_users() self.__get_master_status() @@ -307,6 +315,14 @@ class MySQL_Info(object): release=int(release), ) + def __get_global_status(self): + """Get global status.""" + res = self.__exec_sql('SHOW GLOBAL STATUS') + + if res: + for var in res: + self.info['global_status'][var['Variable_name']] = self.__convert(var['Value']) + def __get_master_status(self): """Get master status if the instance is a master.""" res = self.__exec_sql('SHOW MASTER STATUS') diff --git a/test/integration/targets/mysql_info/tasks/main.yml b/test/integration/targets/mysql_info/tasks/main.yml index e4c1be92ad..03f5f4d6aa 100644 --- a/test/integration/targets/mysql_info/tasks/main.yml +++ b/test/integration/targets/mysql_info/tasks/main.yml @@ -43,6 +43,7 @@ - result.changed == false - result.version != {} - result.settings != {} + - result.global_status != {} - result.databases != {} - result.engines != {} - result.users != {} @@ -92,6 +93,7 @@ that: - result.changed == false - result.version != {} + - result.global_status != {} - result.databases != {} - result.engines != {} - result.settings is not defined @@ -114,4 +116,5 @@ - result.databases != {} - result.engines is not defined - result.settings is not defined + - result.global_status is not defined - result.users is not defined