openstack-ansible/playbooks/library/mysql_status_facts
git-harry 4a860f715c Restart mysql when config changed
Currently mysql is only (re)started when creating a cluster, adding a
node or the service isn't running. This means changes to configuration
files are not used.

This commit moves the restart functionality to a handler and sets
notifies on the the appropriate tasks so that when the config is changes
mysql is restarted.

This commit modifies the galera play to run in serial so that only one
instance of mysql can be restarted at a time. This is to prevent the
possibility of them all being restarted in one go. An additional play
'Check galera cluster status' has been added, this makes an attempt to
check that the cluster is healthy before proceeding with any possible
config changes. The checks can be overridden by setting
'galera_ignore_cluster_state=true' when running the playbook.

A facts module has been added to gather information about the status of
the cluster for use by the galera-install playbook.

DocImpact
Closes-bug: #1449958

Change-Id: Id83ba642c114d1f5cac04cc219be151a82a1023f
2015-07-12 18:04:10 +01:00

67 lines
1.9 KiB
Python

#!/usr/bin/env python
# Copyright 2015, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
DOCUMENTATION = """
---
module: mysql_status_facts
short_description:
- A module for gathering mysql status facts.
description:
- A module for gathering mysql status facts.
author: Rcbops
"""
EXAMPLES = """
- name: Gather mysql status facts
mysql_status_facts:
"""
import subprocess
class MysqlStatusFacts(object):
def __init__(self, module):
self.state_change = False
self.module = module
def gather_facts(self):
"""Get information about mysql status."""
try:
output = subprocess.check_output(["mysql", "-e", "show status"],
stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
message = 'Mysql fact collection failed: "%s".' % e.output.strip()
self.module.fail_json(msg=message)
else:
lines = output.split('\n')
facts = dict(l.split('\t') for l in lines if l)
self.module.exit_json(
changed=self.state_change,
ansible_facts={'mysql_status': facts})
def main():
module = AnsibleModule(
argument_spec=dict(
),
supports_check_mode=False
)
mysql_facts = MysqlStatusFacts(module)
mysql_facts.gather_facts()
from ansible.module_utils.basic import *
if __name__ == '__main__':
main()