mysql_user throws an SQL error when the user already exists

Hey guys,

I have a task in my playbook that looks like this:

  • name: Ensure the database user for database
    mysql_user: name=‘{{database_user}}’ password=‘{{database_password}}’ priv=‘“{{database}}”.*:ALL’ state=present
    ignore_errors: yes
    when: “‘instance’ in repos”

{{database}} contains the string “glasgow-locum-group_production”.
ignore_errors still causes the task to fail.
When I run this task without any matching user in the database, it runs fine. If I run the task again, then I get this error:


> TASK: [Ensure the database user for database] ********************************* 
> fatal: [bravo.farmer.io] => failed to parse: Traceback (most recent call last):
>   File "/home/john/.ansible/tmp/ansible-1377268811.91-196684433087208/mysql_user", line 1281, in <module>
>     main()
>   File "/home/john/.ansible/tmp/ansible-1377268811.91-196684433087208/mysql_user", line 374, in main
>     changed = user_mod(cursor, user, host, password, priv)
>   File "/home/john/.ansible/tmp/ansible-1377268811.91-196684433087208/mysql_user", line 156, in user_mod
>     privileges_revoke(cursor, user,host,db_table)
>   File "/home/john/.ansible/tmp/ansible-1377268811.91-196684433087208/mysql_user", line 237, in privileges_revoke
>     cursor.execute(query)
>   File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
>     self.errorhandler(self, exc, value)
>   File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
>     raise errorclass, errorvalue
> _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-locum-group_production.* FROM 'glg'@'localhost'' at line 1")
>  
>  
> FATAL: all hosts have already failed -- aborting
>  
> PLAY RECAP ******************************************************************** 
>            to retry, use: --limit @/var/tmp/ansible/site.retry

I've enabled logging on mysqld and it shows that ansible either fails at or after the following SQL query:

41 Query REVOKE ALL PRIVILEGES ON glasgow-locum-group_production.* FROM ‘glg’@‘localhost’


Any help would be really appreciated!

Best,
JH


“ignore_errors still causes the task to fail.”

Probably because it got a traceback rather than returned a failure code. This indicates the module is unhappy and I do NOT think you want that to continue on without reporting a problem, and am unclear why you would.

Can you share the version of Ansible you are using (ansible --version) ?

Can you also tell me the value of ‘database’ and if there are perhaps any characters in the database password that might be causing a problem with the module.

Definitely want to get this fixed, but need a bit more info.

Thanks!

Hi Michael,

Probably because it got a traceback rather than returned a failure code. This indicates the module is unhappy and I do NOT think you want that to continue on without reporting a problem, and am unclear why you would.

100% agree - I just wanted to see if it would make a difference so I could continue building out other aspects of my config :slight_smile:

I’m running ansible 1.2.3 (just freshly updated from arch’s repository).

{{database}} is “glasgow-locum-group_production” (minus the quotes of course)
{{database_password}} is a 32 character mixture of letters and numbers, starting with 4 numbers

Best,
JH

Ok, please see if this occurs in 1.3 (devel) or not, and if it does, make sure there’s a bug tracking this.

Thanks!

Hi Michael, I can verify that the bug occurs on devel as well. I’m going to try and find a fix today. There is an open ticket with a user with a similar problem here: https://github.com/ansible/ansible/issues/3767

Best!
JH