fix warning to be displayed only when option is not set by the user

This commit is contained in:
Laurent Indermuehle 2023-10-06 14:09:28 +02:00
parent 7e2449813c
commit 2d2e56d13a
No known key found for this signature in database
GPG key ID: 93FA944C9F34DD09
3 changed files with 13 additions and 12 deletions

View file

@ -128,7 +128,6 @@ options:
feature was introduced but since MySQL/MariaDB is case sensitive you should set this
to C(true) in most cases.
type: bool
default: false
version_added: '3.8.0'
notes:
@ -970,7 +969,7 @@ def main():
check_implicit_admin=dict(type='bool', default=False),
set_default_role_all=dict(type='bool', default=True),
members_must_exist=dict(type='bool', default=True),
column_case_sensitive=dict(type='bool', default=False),
column_case_sensitive=dict(type='bool', default=None), # TODO 4.0.0 add default=True
)
module = AnsibleModule(
argument_spec=argument_spec,
@ -1018,6 +1017,11 @@ def main():
if mysql_driver is None:
module.fail_json(msg=mysql_driver_fail_msg)
# TODO Release 4.0.0 : Remove this test and variable assignation
if column_case_sensitive is None:
column_case_sensitive = False
module.warn("Option column_case_sensitive not provided, column's name will be uppercased")
cursor = None
try:
if check_implicit_admin:
@ -1087,10 +1091,6 @@ def main():
try:
if state == 'present':
if not role.exists:
# TODO Release 4.0.0 : Remove this warning or change the message.
if not column_case_sensitive and "(" in str(priv):
module.warn("column_case_sensitive set to False, column's name will be uppercased")
if subtract_privs:
priv = None # avoid granting unwanted privileges
if detach_members:

View file

@ -163,7 +163,6 @@ options:
- This feature was introduced because MySQL 8 and above uses case sensitive
fields names in privileges.
type: bool
default: false
version_added: '3.8.0'
notes:
@ -414,7 +413,7 @@ def main():
resource_limits=dict(type='dict'),
force_context=dict(type='bool', default=False),
session_vars=dict(type='dict'),
column_case_sensitive=dict(type='bool', default=False)
column_case_sensitive=dict(type='bool', default=None), # TODO 4.0.0 add default=True
)
module = AnsibleModule(
argument_spec=argument_spec,
@ -477,6 +476,11 @@ def main():
module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. "
"Exception message: %s" % (config_file, to_native(e)))
# TODO Release 4.0.0 : Remove this test and variable assignation
if column_case_sensitive is None:
column_case_sensitive = False
module.warn("Option column_case_sensitive not provided, column's name will be uppercased")
if not sql_log_bin:
cursor.execute("SET SQL_LOG_BIN=0;")
@ -491,9 +495,6 @@ def main():
except Exception as e:
module.fail_json(msg=to_native(e))
# TODO Release 4.0.0 : Remove this warning or change the message.
if not column_case_sensitive and "(" in str(priv):
module.warn("column_case_sensitive set to False, column's name will be uppercased")
priv = privileges_unpack(priv, mode, column_case_sensitive, ensure_usage=not subtract_privs)
password_changed = False
if state == "present":

View file

@ -25,7 +25,7 @@
# ================= Reproduce failure =====================================
- name: Mysql_user Column case sensitive | Create users
- name: Mysql_user Column case sensitive | Create test user
community.mysql.mysql_user:
<<: *mysql_params
name: column_case_sensitive