Add supports_check_mode=True to mysql_db module

The most important cases are state=present and state=absent.

Future work: import and dump could be simulated and hence checked.
This commit is contained in:
Tobias Wolf 2016-01-26 15:05:49 +01:00 committed by Matt Clay
parent a2a3d2fc06
commit 75e8b365b4

View file

@ -225,7 +225,8 @@ def main():
ssl_key=dict(default=None),
ssl_ca=dict(default=None),
config_file=dict(default="~/.my.cnf"),
)
),
supports_check_mode=True
)
if not mysqldb_found:
@ -277,11 +278,17 @@ def main():
config_file = None
if db_exists(cursor, db):
if state == "absent":
if module.check_mode:
changed = True
else:
try:
changed = db_delete(cursor, db)
except Exception, e:
module.fail_json(msg="error deleting database: " + str(e))
elif state == "dump":
if module.check_mode:
module.exit_json(changed=True, db=db)
else:
rc, stdout, stderr = db_dump(module, login_host, login_user,
login_password, db, target, all_databases,
login_port, config_file, socket, ssl_cert, ssl_key, ssl_ca)
@ -290,6 +297,9 @@ def main():
else:
module.exit_json(changed=True, db=db, msg=stdout)
elif state == "import":
if module.check_mode:
module.exit_json(changed=True, db=db)
else:
rc, stdout, stderr = db_import(module, login_host, login_user,
login_password, db, target, all_databases,
login_port, config_file, socket, ssl_cert, ssl_key, ssl_ca)
@ -299,6 +309,9 @@ def main():
module.exit_json(changed=True, db=db, msg=stdout)
else:
if state == "present":
if module.check_mode:
changed = True
else:
try:
changed = db_create(cursor, db, encoding, collation)
except Exception, e: