mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
Allow an empty password when adding a new MySQL user. (#3445)
This commit is contained in:
parent
58f30646ed
commit
54e62c2022
1 changed files with 6 additions and 6 deletions
|
@ -32,7 +32,7 @@ options:
|
||||||
required: true
|
required: true
|
||||||
password:
|
password:
|
||||||
description:
|
description:
|
||||||
- set the user's password. (Required when adding a user)
|
- set the user's password.
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
encrypted:
|
encrypted:
|
||||||
|
@ -232,6 +232,8 @@ def user_add(cursor, user, host, host_all, password, encrypted, new_priv, check_
|
||||||
cursor.execute("CREATE USER %s@%s IDENTIFIED BY PASSWORD %s", (user,host,password))
|
cursor.execute("CREATE USER %s@%s IDENTIFIED BY PASSWORD %s", (user,host,password))
|
||||||
elif password and not encrypted:
|
elif password and not encrypted:
|
||||||
cursor.execute("CREATE USER %s@%s IDENTIFIED BY %s", (user,host,password))
|
cursor.execute("CREATE USER %s@%s IDENTIFIED BY %s", (user,host,password))
|
||||||
|
else:
|
||||||
|
cursor.execute("CREATE USER %s@%s", (user,host))
|
||||||
|
|
||||||
if new_priv is not None:
|
if new_priv is not None:
|
||||||
for db_table, priv in new_priv.iteritems():
|
for db_table, priv in new_priv.iteritems():
|
||||||
|
@ -266,13 +268,13 @@ def user_mod(cursor, user, host, host_all, password, encrypted, new_priv, append
|
||||||
if bool(password):
|
if bool(password):
|
||||||
# Determine what user management method server uses
|
# Determine what user management method server uses
|
||||||
old_user_mgmt = server_version_check(cursor)
|
old_user_mgmt = server_version_check(cursor)
|
||||||
|
|
||||||
if old_user_mgmt:
|
if old_user_mgmt:
|
||||||
cursor.execute("SELECT password FROM user WHERE user = %s AND host = %s", (user,host))
|
cursor.execute("SELECT password FROM user WHERE user = %s AND host = %s", (user,host))
|
||||||
else:
|
else:
|
||||||
cursor.execute("SELECT authentication_string FROM user WHERE user = %s AND host = %s", (user,host))
|
cursor.execute("SELECT authentication_string FROM user WHERE user = %s AND host = %s", (user,host))
|
||||||
current_pass_hash = cursor.fetchone()
|
current_pass_hash = cursor.fetchone()
|
||||||
|
|
||||||
if encrypted:
|
if encrypted:
|
||||||
encrypted_string = (password)
|
encrypted_string = (password)
|
||||||
if is_hash(password):
|
if is_hash(password):
|
||||||
|
@ -300,7 +302,7 @@ def user_mod(cursor, user, host, host_all, password, encrypted, new_priv, append
|
||||||
else:
|
else:
|
||||||
cursor.execute("ALTER USER %s@%s IDENTIFIED BY %s", (user, host, password))
|
cursor.execute("ALTER USER %s@%s IDENTIFIED BY %s", (user, host, password))
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
# Handle privileges
|
# Handle privileges
|
||||||
if new_priv is not None:
|
if new_priv is not None:
|
||||||
curr_priv = privileges_get(cursor, user,host)
|
curr_priv = privileges_get(cursor, user,host)
|
||||||
|
@ -566,8 +568,6 @@ def main():
|
||||||
except (SQLParseError, InvalidPrivsError, MySQLdb.Error), e:
|
except (SQLParseError, InvalidPrivsError, MySQLdb.Error), e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
else:
|
else:
|
||||||
if password is None:
|
|
||||||
module.fail_json(msg="password parameter required when adding a user")
|
|
||||||
if host_all:
|
if host_all:
|
||||||
module.fail_json(msg="host_all parameter cannot be used when adding a user")
|
module.fail_json(msg="host_all parameter cannot be used when adding a user")
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue