Skip to content

Commit

Permalink
Add support for the RESET MASTER command
Browse files Browse the repository at this point in the history
  • Loading branch information
tersmitten committed May 17, 2019
1 parent 27aca73 commit 99a543b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/ansible/modules/database/mysql/mysql_replication.py
Expand Up @@ -27,7 +27,7 @@
mode:
description:
- module operating mode. Could be getslave (SHOW SLAVE STATUS), getmaster (SHOW MASTER STATUS), changemaster (CHANGE MASTER TO), startslave
(START SLAVE), stopslave (STOP SLAVE), resetslave (RESET SLAVE), resetslaveall (RESET SLAVE ALL)
(START SLAVE), stopslave (STOP SLAVE), resetslave (RESET SLAVE), resetmaster (RESET MASTER), resetslaveall (RESET SLAVE ALL)
type: str
choices:
- getslave
Expand All @@ -36,6 +36,7 @@
- stopslave
- startslave
- resetslave
- resetmaster
- resetslaveall
default: getslave
master_host:
Expand Down Expand Up @@ -168,6 +169,15 @@ def reset_slave(cursor):
return reset


def reset_master(cursor):
try:
cursor.execute("RESET MASTER")
reset = True
except Exception:
reset = False
return reset


def reset_slave_all(cursor):
try:
cursor.execute("RESET SLAVE ALL")
Expand Down Expand Up @@ -358,6 +368,12 @@ def main():
module.exit_json(msg="Slave reset", changed=True)
else:
module.exit_json(msg="Slave already reset", changed=False)
elif mode in "resetmaster":
reset = reset_master(cursor)
if reset is True:
module.exit_json(msg="Master reset", changed=True)
else:
module.exit_json(msg="Master already reset", changed=False)
elif mode in "resetslaveall":
reset = reset_slave_all(cursor)
if reset is True:
Expand Down

0 comments on commit 99a543b

Please sign in to comment.