mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-08-03 04:34:27 -07:00
Merge branch 'main' into password_expiration_mysql_user
This commit is contained in:
commit
273fd2cdcc
21 changed files with 693 additions and 103 deletions
|
@ -577,14 +577,14 @@ def db_create(cursor, db, encoding, collation):
|
|||
def main():
|
||||
argument_spec = mysql_common_argument_spec()
|
||||
argument_spec.update(
|
||||
name=dict(type='list', required=True, aliases=['db']),
|
||||
name=dict(type='list', elements='str', required=True, aliases=['db']),
|
||||
encoding=dict(type='str', default=''),
|
||||
collation=dict(type='str', default=''),
|
||||
target=dict(type='path'),
|
||||
state=dict(type='str', default='present', choices=['absent', 'dump', 'import', 'present']),
|
||||
single_transaction=dict(type='bool', default=False),
|
||||
quick=dict(type='bool', default=True),
|
||||
ignore_tables=dict(type='list', default=[]),
|
||||
ignore_tables=dict(type='list', elements='str', default=[]),
|
||||
hex_blob=dict(default=False, type='bool'),
|
||||
force=dict(type='bool', default=False),
|
||||
master_data=dict(type='int', default=0, choices=[0, 1, 2]),
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = r'''
|
||||
|
@ -292,6 +293,7 @@ from ansible_collections.community.mysql.plugins.module_utils.mysql import (
|
|||
mysql_driver_fail_msg,
|
||||
get_connector_name,
|
||||
get_connector_version,
|
||||
get_server_implementation,
|
||||
)
|
||||
|
||||
from ansible_collections.community.mysql.plugins.module_utils.user import (
|
||||
|
@ -325,9 +327,10 @@ class MySQL_Info(object):
|
|||
5. add info about the new subset with an example to RETURN block
|
||||
"""
|
||||
|
||||
def __init__(self, module, cursor):
|
||||
def __init__(self, module, cursor, server_implementation):
|
||||
self.module = module
|
||||
self.cursor = cursor
|
||||
self.server_implementation = server_implementation
|
||||
self.info = {
|
||||
'version': {},
|
||||
'databases': {},
|
||||
|
@ -497,7 +500,10 @@ class MySQL_Info(object):
|
|||
|
||||
def __get_slave_status(self):
|
||||
"""Get slave status if the instance is a slave."""
|
||||
res = self.__exec_sql('SHOW SLAVE STATUS')
|
||||
if self.server_implementation == "mariadb":
|
||||
res = self.__exec_sql('SHOW ALL SLAVES STATUS')
|
||||
else:
|
||||
res = self.__exec_sql('SHOW SLAVE STATUS')
|
||||
if res:
|
||||
for line in res:
|
||||
host = line['Master_Host']
|
||||
|
@ -692,8 +698,8 @@ def main():
|
|||
argument_spec = mysql_common_argument_spec()
|
||||
argument_spec.update(
|
||||
login_db=dict(type='str'),
|
||||
filter=dict(type='list'),
|
||||
exclude_fields=dict(type='list'),
|
||||
filter=dict(type='list', elements='str'),
|
||||
exclude_fields=dict(type='list', elements='str'),
|
||||
return_empty_dbs=dict(type='bool', default=False),
|
||||
)
|
||||
|
||||
|
@ -738,10 +744,12 @@ def main():
|
|||
'Exception message: %s' % (connector_name, connector_version, config_file, to_native(e)))
|
||||
module.fail_json(msg)
|
||||
|
||||
server_implementation = get_server_implementation(cursor)
|
||||
|
||||
###############################
|
||||
# Create object and do main job
|
||||
|
||||
mysql = MySQL_Info(module, cursor)
|
||||
mysql = MySQL_Info(module, cursor, server_implementation)
|
||||
|
||||
module.exit_json(changed=False,
|
||||
connector_name=connector_name,
|
||||
|
|
|
@ -36,6 +36,7 @@ options:
|
|||
- List of values to be passed as positional arguments to the query.
|
||||
- Mutually exclusive with I(named_args).
|
||||
type: list
|
||||
elements: raw
|
||||
named_args:
|
||||
description:
|
||||
- Dictionary of key-value arguments to pass to the query.
|
||||
|
@ -141,7 +142,7 @@ def main():
|
|||
argument_spec.update(
|
||||
query=dict(type='raw', required=True),
|
||||
login_db=dict(type='str'),
|
||||
positional_args=dict(type='list'),
|
||||
positional_args=dict(type='list', elements='raw'),
|
||||
named_args=dict(type='dict'),
|
||||
single_transaction=dict(type='bool', default=False),
|
||||
)
|
||||
|
|
|
@ -931,7 +931,7 @@ class Role():
|
|||
if privs:
|
||||
result = user_mod(self.cursor, self.name, self.host,
|
||||
None, None, None, None, None, None,
|
||||
privs, append_privs, subtract_privs, None,
|
||||
privs, append_privs, subtract_privs, None, None,
|
||||
self.module, None, None, role=True,
|
||||
maria_role=self.is_mariadb)
|
||||
changed = result['changed']
|
||||
|
|
|
@ -179,6 +179,13 @@ options:
|
|||
fields names in privileges.
|
||||
type: bool
|
||||
version_added: '3.8.0'
|
||||
attributes:
|
||||
description:
|
||||
- "Create, update, or delete user attributes (arbitrary 'key: value' comments) for the user."
|
||||
- MySQL server must support the INFORMATION_SCHEMA.USER_ATTRIBUTES table. Provided since MySQL 8.0.
|
||||
- To delete an existing attribute, set its value to null.
|
||||
type: dict
|
||||
version_added: '3.9.0'
|
||||
|
||||
notes:
|
||||
- "MySQL server installs with default I(login_user) of C(root) and no password.
|
||||
|
@ -271,6 +278,13 @@ EXAMPLES = r'''
|
|||
FUNCTION my_db.my_function: EXECUTE
|
||||
state: present
|
||||
|
||||
- name: Modify user attributes, creating the attribute 'foo' and removing the attribute 'bar'
|
||||
community.mysql.mysql_user:
|
||||
name: bob
|
||||
attributes:
|
||||
foo: "foo"
|
||||
bar: null
|
||||
|
||||
- name: Modify user to require TLS connection with a valid client certificate
|
||||
community.mysql.mysql_user:
|
||||
name: bob
|
||||
|
@ -419,6 +433,7 @@ def main():
|
|||
tls_requires=dict(type='dict'),
|
||||
append_privs=dict(type='bool', default=False),
|
||||
subtract_privs=dict(type='bool', default=False),
|
||||
attributes=dict(type='dict'),
|
||||
check_implicit_admin=dict(type='bool', default=False),
|
||||
update_password=dict(type='str', default='always', choices=['always', 'on_create', 'on_new_username'], no_log=False),
|
||||
sql_log_bin=dict(type='bool', default=True),
|
||||
|
@ -453,6 +468,7 @@ def main():
|
|||
append_privs = module.boolean(module.params["append_privs"])
|
||||
subtract_privs = module.boolean(module.params['subtract_privs'])
|
||||
update_password = module.params['update_password']
|
||||
attributes = module.params['attributes']
|
||||
ssl_cert = module.params["client_cert"]
|
||||
ssl_key = module.params["client_key"]
|
||||
ssl_ca = module.params["ca_cert"]
|
||||
|
@ -522,23 +538,25 @@ def main():
|
|||
|
||||
priv = privileges_unpack(priv, mode, column_case_sensitive, ensure_usage=not subtract_privs)
|
||||
password_changed = False
|
||||
final_attributes = None
|
||||
if state == "present":
|
||||
if user_exists(cursor, user, host, host_all):
|
||||
try:
|
||||
if update_password == "always":
|
||||
result = user_mod(cursor, user, host, host_all, password, encrypted,
|
||||
plugin, plugin_hash_string, plugin_auth_string,
|
||||
priv, append_privs, subtract_privs, tls_requires, module,
|
||||
priv, append_privs, subtract_privs, attributes, tls_requires, module,
|
||||
password_expire, password_expire_interval)
|
||||
|
||||
else:
|
||||
result = user_mod(cursor, user, host, host_all, None, encrypted,
|
||||
None, None, None,
|
||||
priv, append_privs, subtract_privs, tls_requires, module,
|
||||
priv, append_privs, subtract_privs, attributes, tls_requires, module,
|
||||
password_expire, password_expire_interval)
|
||||
changed = result['changed']
|
||||
msg = result['msg']
|
||||
password_changed = result['password_changed']
|
||||
final_attributes = result['attributes']
|
||||
|
||||
except (SQLParseError, InvalidPrivsError, mysql_driver.Error) as e:
|
||||
module.fail_json(msg=to_native(e))
|
||||
|
@ -551,10 +569,11 @@ def main():
|
|||
reuse_existing_password = update_password == 'on_new_username'
|
||||
result = user_add(cursor, user, host, host_all, password, encrypted,
|
||||
plugin, plugin_hash_string, plugin_auth_string,
|
||||
priv, tls_requires, module, reuse_existing_password,
|
||||
priv, attributes, tls_requires, module, reuse_existing_password,
|
||||
password_expire, password_expire_interval)
|
||||
changed = result['changed']
|
||||
password_changed = result['password_changed']
|
||||
final_attributes = result['attributes']
|
||||
if changed:
|
||||
msg = "User added"
|
||||
|
||||
|
@ -571,7 +590,7 @@ def main():
|
|||
else:
|
||||
changed = False
|
||||
msg = "User doesn't exist"
|
||||
module.exit_json(changed=changed, user=user, msg=msg, password_changed=password_changed)
|
||||
module.exit_json(changed=changed, user=user, msg=msg, password_changed=password_changed, attributes=final_attributes)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -176,7 +176,7 @@ def setvariable(cursor, mysqlvar, value, mode='global'):
|
|||
def main():
|
||||
argument_spec = mysql_common_argument_spec()
|
||||
argument_spec.update(
|
||||
variable=dict(type='str'),
|
||||
variable=dict(type='str', required=True),
|
||||
value=dict(type='str'),
|
||||
mode=dict(type='str', choices=['global', 'persist', 'persist_only'], default='global'),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue