Repository: ansible/ansible-modules-extras

Issue:
SQL Syntax error with mysql_replication
**Issue Type:**

Bug Report

**Ansible Version:**

ansible 1.8.2
  configured module search path = /usr/share/ansible

**Environment:**

OS X 10.10.1 > Debian 7.7

**Summary:**

Hello, I try to setup my slaves using ansible, but I have an issue while setting the master state into the slave. I get a mysql exception regarding an SQL Syntax Error.

**Steps To Reproduce:**

``` yaml
- name: get master replication status
  mysql_replication: mode=getmaster login_user={{ master.user }} login_password={{ master.password }}
  delegate_to: "{{master.host}}"
  register: replication
  when: slave|failed

- name: define master status in slave
  mysql_replication: mode=changemaster master_host={{ master.host }} master_log_file={{ replication.File }} master_log_pos={{ replication.Position }} master_user={{ master.user }} master_password={{ master.password }}
  when: slave|failed
```

**Expected Results:**

No error

**Actual Results:**

```
TASK: [db-slave | define master status in slave] *****************************
failed: [a-future-slave] => {"failed": true, "parsed": false}
Change master
Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-tmp-1418728948.93-89965021745143/mysql_replication", line 1949, in <module>
    main()
  File "/root/.ansible/tmp/ansible-tmp-1418728948.93-89965021745143/mysql_replication", line 367, in main
    changemaster(cursor, chm, chm_params)
  File "/root/.ansible/tmp/ansible-tmp-1418728948.93-89965021745143/mysql_replication", line 165, in changemaster
    cursor.execute(query, chm_params)
  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 MariaDB server version for the right syntax to use near ''130779818'' at line 1")
```

From the _a-future-slave_ logs, here is the output I get :

``` logs
Dec 16 12:22:32 a-future-slave ansible-mysql_replication: Invoked with master_ssl_cert=None master_log_pos=130779818 master_ssl=False master_log_file=mysql-bin.000450 login_user=None login_host=localhost master_port=None master_host=my-master master_ssl_ca=None master_ssl_key=None login_unix_socket=None master_connect_retry=None master_user=my_user master_ssl_capath=None mode=changemaster relay_log_pos=None login_password=NOT_LOGGING_PASSWORD master_ssl_cipher=None master_password=my_password relay_log_file=None
```



Discussion:
# Can You Help Us Out?

Thanks for filing a ticket! I am the friendly GitHub Ansibot. 

It looks like you might not have filled out the issue description based on our standard issue template.  You might not have known about that, and that's ok too, we'll tell you how to do it.

We have a standard template because Ansible is a really busy project and it helps to have some standard information in each ticket, and GitHub doesn't yet provide a standard facility to do this like some other bug trackers.  We hope you understand as this is really valuable to us!. 

Solving this is simple: please copy the contents of this [template](https://raw.githubusercontent.com/ansible/ansible/devel/ISSUE_TEMPLATE.md) and **paste it into the description** of your ticket.  That's it!

# If You Had A Question To Ask Instead

If you happened to have a "how do I do this in Ansible" type of question, that's probably more of a user-list question than a bug report, and you should probably ask this question on the project mailing list instead.  

However, if you think you have a bug, the report is the way to go!  We definitely want all the bugs filed :)  Just trying to help!

# About Priority Tags

Since you're here, we'll also share some useful information at this time.

In general tickets will be assigned a priority between P1 (highest) and P5, and then worked in priority order. We may also have some follow up questions along the way, so keeping up with follow up comments via GitHub notifications is a good idea.

Due to large interest in Ansible, humans may not comment on your ticket immediately.  

# Mailing Lists

If you have concerns or questions, you're welcome to stop by the ansible-project or ansible-development mailing lists, as appropriate.  Here are the links:
- https://groups.google.com/forum/#!forum/ansible-project - for discussion of bugs and how-to type questions
- https://groups.google.com/forum/#!forum/ansible-devel - for discussion on how to implement a code change, or feature brainstorming among developers

Thanks again for the interest in Ansible!


Resolving patch:
diff --git a/database/mysql/mysql_replication.py b/database/mysql/mysql_replication.py
--- a/database/mysql/mysql_replication.py
+++ b/database/mysql/mysql_replication.py
@@ -235,12 +235,12 @@ def main():
             master_host=dict(default=None),
             master_user=dict(default=None),
             master_password=dict(default=None),
-            master_port=dict(default=None),
-            master_connect_retry=dict(default=None),
+            master_port=dict(default=None, type='int'),
+            master_connect_retry=dict(default=None, type='int'),
             master_log_file=dict(default=None),
-            master_log_pos=dict(default=None),
+            master_log_pos=dict(default=None, type='int'),
             relay_log_file=dict(default=None),
-            relay_log_pos=dict(default=None),
+            relay_log_pos=dict(default=None, type='int'),
             master_ssl=dict(default=False, type='bool'),
             master_ssl_ca=dict(default=None),
             master_ssl_capath=dict(default=None),


Test patch: