diff options
author | René Moser <mail@renemoser.net> | 2016-03-23 11:26:10 +0100 |
---|---|---|
committer | René Moser <mail@renemoser.net> | 2016-03-23 11:26:10 +0100 |
commit | b8d0f058f420cb4d5e508cedcc02a506e6e25f8b (patch) | |
tree | dde3fcb5082842dc6fb6d43ddbee977f2a04892f /database/mysql/mysql_db.py | |
parent | 6a7dac5bdc0a6d8152032ac3218ef9ca6bce8e29 (diff) | |
parent | 3d606dd2b447b0ed425a248825c615fc2f6d17cd (diff) | |
download | ansible-modules-core-b8d0f058f420cb4d5e508cedcc02a506e6e25f8b.tar.gz |
Merge pull request #2889 from towolf/add_check_mode_to_mysql_db
Add supports_check_mode=True to mysql_db module
Diffstat (limited to 'database/mysql/mysql_db.py')
-rw-r--r-- | database/mysql/mysql_db.py | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/database/mysql/mysql_db.py b/database/mysql/mysql_db.py index 4c32d406..37cccba1 100644 --- a/database/mysql/mysql_db.py +++ b/database/mysql/mysql_db.py @@ -226,7 +226,8 @@ def main(): ssl_ca=dict(default=None), connect_timeout=dict(default=30, type='int'), config_file=dict(default="~/.my.cnf"), - ) + ), + supports_check_mode=True ) if not mysqldb_found: @@ -280,32 +281,44 @@ def main(): config_file = None if db_exists(cursor, db): if state == "absent": - try: - changed = db_delete(cursor, db) - except Exception, e: - module.fail_json(msg="error deleting database: " + str(e)) + 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": - 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) - if rc != 0: - module.fail_json(msg="%s" % stderr) + if module.check_mode: + module.exit_json(changed=True, db=db) else: - module.exit_json(changed=True, db=db, msg=stdout) + 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) + if rc != 0: + module.fail_json(msg="%s" % stderr) + else: + module.exit_json(changed=True, db=db, msg=stdout) elif state == "import": - 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) - if rc != 0: - module.fail_json(msg="%s" % stderr) + if module.check_mode: + module.exit_json(changed=True, db=db) else: - module.exit_json(changed=True, db=db, msg=stdout) + 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) + if rc != 0: + module.fail_json(msg="%s" % stderr) + else: + module.exit_json(changed=True, db=db, msg=stdout) else: if state == "present": - try: - changed = db_create(cursor, db, encoding, collation) - except Exception, e: - module.fail_json(msg="error creating database: " + str(e)) + if module.check_mode: + changed = True + else: + try: + changed = db_create(cursor, db, encoding, collation) + except Exception, e: + module.fail_json(msg="error creating database: " + str(e)) module.exit_json(changed=changed, db=db) |