From 946732eb74c232c9c0e26360e2ea7be8f505f2a6 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Tue, 15 Sep 2015 12:57:37 +0200 Subject: [PATCH] Add more modes to the mysql_replication module Fixes #979 --- .../database/mysql/mysql_replication.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/ansible/modules/extras/database/mysql/mysql_replication.py b/lib/ansible/modules/extras/database/mysql/mysql_replication.py index f3c0238868..91532aaef7 100644 --- a/lib/ansible/modules/extras/database/mysql/mysql_replication.py +++ b/lib/ansible/modules/extras/database/mysql/mysql_replication.py @@ -42,6 +42,8 @@ options: - changemaster - stopslave - startslave + - resetslave + - resetslaveall default: getslave login_user: description: @@ -162,6 +164,24 @@ def stop_slave(cursor): return stopped +def reset_slave(cursor): + try: + cursor.execute("RESET SLAVE") + reset = True + except: + reset = False + return reset + + +def reset_slave_all(cursor): + try: + cursor.execute("RESET SLAVE ALL") + reset = True + except: + reset = False + return reset + + def start_slave(cursor): try: cursor.execute("START SLAVE") @@ -397,6 +417,18 @@ def main(): module.exit_json(msg="Slave stopped", changed=True) else: module.exit_json(msg="Slave already stopped", changed=False) + elif mode in "resetslave": + reset = reset_slave(cursor) + if reset is True: + module.exit_json(msg="Slave reset", changed=True) + else: + module.exit_json(msg="Slave already reset", changed=False) + elif mode in "resetslaveall": + reset = reset_slave_all(cursor) + if reset is True: + module.exit_json(msg="Slave reset", changed=True) + else: + module.exit_json(msg="Slave already reset", changed=False) # import module snippets from ansible.module_utils.basic import *