# mysql\_user throws an SQL error when the user already exists

**URL:** <https://forum.ansible.com/t/mysql-user-throws-an-sql-error-when-the-user-already-exists/13355>\
**Category:** Ansible Project\
**Created:** [August 23, 2013, 5:01pm UTC](https://forum.ansible.com/t/mysql-user-throws-an-sql-error-when-the-user-already-exists/13355 "2013-08-23T17:01:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Hamelink](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@John\_Hamelink](https://forum.ansible.com/u/John_Hamelink)\
**Post date:** [August 23, 2013, 5:01pm UTC](https://forum.ansible.com/t/mysql-user-throws-an-sql-error-when-the-user-already-exists/13355/1 "2013-08-23T17:01:38Z")

</div>

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:

```auto

> 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’

```auto

```

Any help would be really appreciated!

Best,  
JH

```auto

```

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 23, 2013, 9:59pm UTC](https://forum.ansible.com/t/mysql-user-throws-an-sql-error-when-the-user-already-exists/13355/2 "2013-08-23T21:59:11Z")

</div>

“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!

---

<div class="post-metadata">

**Author:** ![John\_Hamelink](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@John\_Hamelink](https://forum.ansible.com/u/John_Hamelink)\
**Post date:** [August 23, 2013, 11:27pm UTC](https://forum.ansible.com/t/mysql-user-throws-an-sql-error-when-the-user-already-exists/13355/3 "2013-08-23T23:27:45Z")

</div>

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 🙂

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 24, 2013, 4:59pm UTC](https://forum.ansible.com/t/mysql-user-throws-an-sql-error-when-the-user-already-exists/13355/4 "2013-08-24T16:59:41Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![John\_Hamelink](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@John\_Hamelink](https://forum.ansible.com/u/John_Hamelink)\
**Post date:** [August 26, 2013, 1:30pm UTC](https://forum.ansible.com/t/mysql-user-throws-an-sql-error-when-the-user-already-exists/13355/5 "2013-08-26T13:30:22Z")

</div>

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](https://github.com/ansible/ansible/issues/3767)

Best!  
JH
