Merge pull request #2889 from towolf/add_check_mode_to_mysql_db
Add supports_check_mode=True to mysql_db module
This commit is contained in:
commit
b8d0f058f4
1 changed files with 34 additions and 21 deletions
|
@ -226,7 +226,8 @@ def main():
|
||||||
ssl_ca=dict(default=None),
|
ssl_ca=dict(default=None),
|
||||||
connect_timeout=dict(default=30, type='int'),
|
connect_timeout=dict(default=30, type='int'),
|
||||||
config_file=dict(default="~/.my.cnf"),
|
config_file=dict(default="~/.my.cnf"),
|
||||||
)
|
),
|
||||||
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
|
||||||
if not mysqldb_found:
|
if not mysqldb_found:
|
||||||
|
@ -280,32 +281,44 @@ def main():
|
||||||
config_file = None
|
config_file = None
|
||||||
if db_exists(cursor, db):
|
if db_exists(cursor, db):
|
||||||
if state == "absent":
|
if state == "absent":
|
||||||
try:
|
if module.check_mode:
|
||||||
changed = db_delete(cursor, db)
|
changed = True
|
||||||
except Exception, e:
|
else:
|
||||||
module.fail_json(msg="error deleting database: " + str(e))
|
try:
|
||||||
|
changed = db_delete(cursor, db)
|
||||||
|
except Exception, e:
|
||||||
|
module.fail_json(msg="error deleting database: " + str(e))
|
||||||
elif state == "dump":
|
elif state == "dump":
|
||||||
rc, stdout, stderr = db_dump(module, login_host, login_user,
|
if module.check_mode:
|
||||||
login_password, db, target, all_databases,
|
module.exit_json(changed=True, db=db)
|
||||||
login_port, config_file, socket, ssl_cert, ssl_key, ssl_ca)
|
|
||||||
if rc != 0:
|
|
||||||
module.fail_json(msg="%s" % stderr)
|
|
||||||
else:
|
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":
|
elif state == "import":
|
||||||
rc, stdout, stderr = db_import(module, login_host, login_user,
|
if module.check_mode:
|
||||||
login_password, db, target, all_databases,
|
module.exit_json(changed=True, db=db)
|
||||||
login_port, config_file, socket, ssl_cert, ssl_key, ssl_ca)
|
|
||||||
if rc != 0:
|
|
||||||
module.fail_json(msg="%s" % stderr)
|
|
||||||
else:
|
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:
|
else:
|
||||||
if state == "present":
|
if state == "present":
|
||||||
try:
|
if module.check_mode:
|
||||||
changed = db_create(cursor, db, encoding, collation)
|
changed = True
|
||||||
except Exception, e:
|
else:
|
||||||
module.fail_json(msg="error creating database: " + str(e))
|
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)
|
module.exit_json(changed=changed, db=db)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue