Merge pull request #981 from tersmitten/add-more-modes-to-the-mysql-replication-module

Add more modes to the mysql_replication module
reviewable/pr18780/r1
James Cammarata 9 years ago
commit 840ce26093

@ -34,7 +34,7 @@ author: "Balazs Pocze (@banyek)"
options: options:
mode: mode:
description: description:
- module operating mode. Could be getslave (SHOW SLAVE STATUS), getmaster (SHOW MASTER STATUS), changemaster (CHANGE MASTER TO), startslave (START SLAVE), stopslave (STOP SLAVE) - 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)
required: False required: False
choices: choices:
- getslave - getslave
@ -42,6 +42,8 @@ options:
- changemaster - changemaster
- stopslave - stopslave
- startslave - startslave
- resetslave
- resetslaveall
default: getslave default: getslave
login_user: login_user:
description: description:
@ -165,6 +167,24 @@ def stop_slave(cursor):
return stopped 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): def start_slave(cursor):
try: try:
cursor.execute("START SLAVE") cursor.execute("START SLAVE")
@ -400,6 +420,18 @@ def main():
module.exit_json(msg="Slave stopped", changed=True) module.exit_json(msg="Slave stopped", changed=True)
else: else:
module.exit_json(msg="Slave already stopped", changed=False) 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 # import module snippets
from ansible.module_utils.basic import * from ansible.module_utils.basic import *

Loading…
Cancel
Save