Merge pull request #3582 from resmo/fix/mysql
mysql_variables and mysql_user fixes
This commit is contained in:
commit
e29878e9f0
2 changed files with 14 additions and 17 deletions
|
@ -247,7 +247,7 @@ def is_hash(password):
|
|||
ishash = True
|
||||
return ishash
|
||||
|
||||
def user_mod(cursor, user, host, host_all, password, encrypted, new_priv, append_privs, check_mode):
|
||||
def user_mod(cursor, user, host, host_all, password, encrypted, new_priv, append_privs, module):
|
||||
changed = False
|
||||
grant_option = False
|
||||
|
||||
|
@ -272,7 +272,7 @@ def user_mod(cursor, user, host, host_all, password, encrypted, new_priv, append
|
|||
encrypted_string = (password)
|
||||
if is_hash(password):
|
||||
if current_pass_hash[0] != encrypted_string:
|
||||
if check_mode:
|
||||
if module.check_mode:
|
||||
return True
|
||||
if old_user_mgmt:
|
||||
cursor.execute("SET PASSWORD FOR %s@%s = %s", (user, host, password))
|
||||
|
@ -288,7 +288,7 @@ def user_mod(cursor, user, host, host_all, password, encrypted, new_priv, append
|
|||
cursor.execute("SELECT CONCAT('*', UCASE(SHA1(UNHEX(SHA1(%s)))))", (password,))
|
||||
new_pass_hash = cursor.fetchone()
|
||||
if current_pass_hash[0] != new_pass_hash[0]:
|
||||
if check_mode:
|
||||
if module.check_mode:
|
||||
return True
|
||||
if old_user_mgmt:
|
||||
cursor.execute("SET PASSWORD FOR %s@%s = PASSWORD(%s)", (user, host, password))
|
||||
|
@ -308,7 +308,7 @@ def user_mod(cursor, user, host, host_all, password, encrypted, new_priv, append
|
|||
grant_option = True
|
||||
if db_table not in new_priv:
|
||||
if user != "root" and "PROXY" not in priv and not append_privs:
|
||||
if check_mode:
|
||||
if module.check_mode:
|
||||
return True
|
||||
privileges_revoke(cursor, user,host,db_table,priv,grant_option)
|
||||
changed = True
|
||||
|
@ -317,7 +317,7 @@ def user_mod(cursor, user, host, host_all, password, encrypted, new_priv, append
|
|||
# we can perform a straight grant operation.
|
||||
for db_table, priv in new_priv.iteritems():
|
||||
if db_table not in curr_priv:
|
||||
if check_mode:
|
||||
if module.check_mode:
|
||||
return True
|
||||
privileges_grant(cursor, user,host,db_table,priv)
|
||||
changed = True
|
||||
|
@ -328,7 +328,7 @@ def user_mod(cursor, user, host, host_all, password, encrypted, new_priv, append
|
|||
for db_table in db_table_intersect:
|
||||
priv_diff = set(new_priv[db_table]) ^ set(curr_priv[db_table])
|
||||
if (len(priv_diff) > 0):
|
||||
if check_mode:
|
||||
if module.check_mode:
|
||||
return True
|
||||
if not append_privs:
|
||||
privileges_revoke(cursor, user,host,db_table,curr_priv[db_table],grant_option)
|
||||
|
@ -554,9 +554,9 @@ def main():
|
|||
if user_exists(cursor, user, host, host_all):
|
||||
try:
|
||||
if update_password == 'always':
|
||||
changed = user_mod(cursor, user, host, host_all, password, encrypted, priv, append_privs, module.check_mode)
|
||||
changed = user_mod(cursor, user, host, host_all, password, encrypted, priv, append_privs, module)
|
||||
else:
|
||||
changed = user_mod(cursor, user, host, host_all, None, encrypted, priv, append_privs, module.check_mode)
|
||||
changed = user_mod(cursor, user, host, host_all, None, encrypted, priv, append_privs, module)
|
||||
|
||||
except (SQLParseError, InvalidPrivsError, MySQLdb.Error), e:
|
||||
module.fail_json(msg=str(e))
|
||||
|
|
|
@ -51,7 +51,6 @@ EXAMPLES = '''
|
|||
'''
|
||||
|
||||
|
||||
import os
|
||||
import warnings
|
||||
from re import match
|
||||
|
||||
|
@ -118,9 +117,9 @@ def main():
|
|||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
login_user=dict(default=None),
|
||||
login_password=dict(default=None),
|
||||
login_host=dict(default="127.0.0.1"),
|
||||
login_port=dict(default="3306", type='int'),
|
||||
login_password=dict(default=None, no_log=True),
|
||||
login_host=dict(default="localhost"),
|
||||
login_port=dict(default=3306, type='int'),
|
||||
login_unix_socket=dict(default=None),
|
||||
variable=dict(default=None),
|
||||
value=dict(default=None),
|
||||
|
@ -128,19 +127,16 @@ def main():
|
|||
ssl_key=dict(default=None),
|
||||
ssl_ca=dict(default=None),
|
||||
connect_timeout=dict(default=30, type='int'),
|
||||
config_file=dict(default="~/.my.cnf")
|
||||
config_file=dict(default="~/.my.cnf", type="path")
|
||||
)
|
||||
)
|
||||
user = module.params["login_user"]
|
||||
password = module.params["login_password"]
|
||||
host = module.params["login_host"]
|
||||
port = module.params["login_port"]
|
||||
ssl_cert = module.params["ssl_cert"]
|
||||
ssl_key = module.params["ssl_key"]
|
||||
ssl_ca = module.params["ssl_ca"]
|
||||
connect_timeout = module.params['connect_timeout']
|
||||
config_file = module.params['config_file']
|
||||
config_file = os.path.expanduser(os.path.expandvars(config_file))
|
||||
db = 'mysql'
|
||||
|
||||
mysqlvar = module.params["variable"]
|
||||
|
@ -187,4 +183,5 @@ def main():
|
|||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.database import *
|
||||
from ansible.module_utils.mysql import *
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in a new issue