# GTID Mysql replication?

**URL:** <https://forum.ansible.com/t/gtid-mysql-replication/17073>\
**Category:** Ansible Project\
**Created:** [December 16, 2014, 6:07am UTC](https://forum.ansible.com/t/gtid-mysql-replication/17073 "2014-12-16T06:07:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Evan\_Tahler](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@Evan\_Tahler](https://forum.ansible.com/u/Evan_Tahler)\
**Post date:** [December 16, 2014, 6:07am UTC](https://forum.ansible.com/t/gtid-mysql-replication/17073/1 "2014-12-16T06:07:23Z")

</div>

Hi!

Is there any (planned) support for [GTID-based replication](http://dev.mysql.com/doc/refman/5.6/en/replication-gtids-howto.html) in the [mysql-replication package](https://github.com/ansible/ansible-modules-extras/blob/devel/database/mysql/mysql_replication.py)?

It looks like someone started this [here](http://ops.kinja.com/mysql_replciation-ansible-module-update-1525041688), but didn’t get it back into master.

---

<div class="post-metadata">

**Author:** ![Evan\_Tahler](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@Evan\_Tahler](https://forum.ansible.com/u/Evan_Tahler)\
**Post date:** [December 22, 2014, 12:45am UTC](https://forum.ansible.com/t/gtid-mysql-replication/17073/2 "2014-12-22T00:45:21Z")

</div>

Here’s how I implemented this using the command line mysql args:

- name: Check if slave is already configured for replication  
mysql\_replication: mode=getslave  
register: slave  
ignore\_errors: true # on the first run, this will error because not replicating yet  
when: ansible\_default\_ipv4.address != mysql\_master\_ip

- name: Get the current master server’s replication status  
mysql\_replication: “mode=getmaster login\_user=‘{{ mysql\_replication\_user }}’ login\_password=‘{{ mysql\_replication\_pass }}’ login\_host=‘{{ mysql\_master\_ip }}’”  
register: mysql\_repl\_stat  
delegate\_to: “{{ mysql\_master\_name }}”  
when: ansible\_default\_ipv4.address != mysql\_master\_ip

- name: ensure mysql replication  
when: "slave|failed and ansible\_default\_ipv4.address != mysql\_master\_ip  
command: "  
/usr/bin/mysql -u {{ mysql\_user }} -p{{ mysql\_pass }} -e  
"  
STOP SLAVE;  
RESET MASTER;  
SET GLOBAL gtid\_purged=‘{{ mysql\_repl\_stat.Executed\_Gtid\_Set }}’;  
CHANGE MASTER TO MASTER\_HOST=‘{{ mysql\_master\_ip }}’, MASTER\_USER=‘{{ mysql\_replication\_user }}’, MASTER\_PASSWORD=‘{{ mysql\_replication\_pass }}’, MASTER\_AUTO\_POSITION=1;  
START SLAVE;  
"  
"

---

<div class="post-metadata">

**Author:** ![Evan\_Tahler](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@Evan\_Tahler](https://forum.ansible.com/u/Evan_Tahler)\
**Post date:** [December 22, 2014, 12:46am UTC](https://forum.ansible.com/t/gtid-mysql-replication/17073/3 "2014-12-22T00:46:12Z")

</div>

It would be great to have this baked in to the [mysql replication module](http://docs.ansible.com/mysql_replication_module.html)
