From cda78382b6af165b7e5e89e5d2339ed7871e536c Mon Sep 17 00:00:00 2001 From: Tobias Wolf Date: Wed, 31 Aug 2016 23:23:54 +0200 Subject: [PATCH] Fix database table quoting in privileges_unpack() (#3858) In Ansible 2.x this module gives `changed = True` for all privileges that are specified including a table with priv: "database.table:GRANT" Mysql returns escaped names in the format `database`.`tables`:GRANT However in PR #1358, which was intended to support dotted database names (a crazy idea to begin with), the quotes for the table name were left out, leading to `curr_priv != new_priv`. This means that the idempotency comparison between new_priv and curr_priv is always 'changed'. This PR re-introduces quoting to the table part of the priv. --- lib/ansible/modules/database/mysql/mysql_user.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/database/mysql/mysql_user.py b/lib/ansible/modules/database/mysql/mysql_user.py index 4778a4eeac..ee8c56cfb1 100644 --- a/lib/ansible/modules/database/mysql/mysql_user.py +++ b/lib/ansible/modules/database/mysql/mysql_user.py @@ -422,9 +422,12 @@ def privileges_unpack(priv, mode): for item in priv.strip().split('/'): pieces = item.strip().split(':') dbpriv = pieces[0].rsplit(".", 1) - # Do not escape if privilege is for database '*' (all databases) - if dbpriv[0].strip('`') != '*': - pieces[0] = '%s%s%s.%s' % (quote, dbpriv[0].strip('`'), quote, dbpriv[1]) + # Do not escape if privilege is for database or table, i.e. + # neither quote *. nor .* + for i, side in enumerate(dbpriv): + if side.strip('`') != '*': + dbpriv[i] = '%s%s%s' % (quote, side.strip('`'), quote) + pieces[0] = '.'.join(dbpriv) if '(' in pieces[1]: output[pieces[0]] = re.split(r',\s*(?=[^)]*(?:\(|$))', pieces[1].upper())