Skip to content

Instantly share code, notes, and snippets.

@gpkvt
Last active January 11, 2020 22:55
Show Gist options
  • Save gpkvt/9134191 to your computer and use it in GitHub Desktop.
Save gpkvt/9134191 to your computer and use it in GitHub Desktop.
SaltStack: MySQL-Replication (Slave-Info)
{% set query = [] %}
{% if not salt['mysql.get_slave_status']()['Master_Host'] %}
{% for host, hostinfo in salt['mine.get']("*.mysql_master?.de", 'grains.items').items() %}
{% if hostinfo['cluster'] == "active" and hostinfo['host'] == salt['grains.get']('host') %}
{% do query.append(salt['mine.get'](hostinfo['fqdn'], 'mysql.get_master_status')[hostinfo['fqdn']]) %}
{% do query.append(salt['grains.get']('ipv4')[0].split('.')[-1]) %}
{% endif %}
{% endfor %}
{% set doquery = "CHANGE MASTER TO MASTER_HOST='192.168.0."+ query[1] +"', MASTER_USER='repl', MASTER_PASSWORD='foobar', MASTER_LOG_FILE='"+ query[0]['File'] +"', MASTER_LOG_POS="+ query[0]['Position']|string +";" %}
{{ salt['mysql.query']('mysql', doquery) }}
{% endif %}
{% if salt['mysql.get_slave_status']()['Slave_SQL_Running'] == 'Yes' and salt['mysql.get_slave_status']()['Slave_IO_Running'] == 'Yes' %}
signal_true:
cmd.run:
- name: /bin/true
{% else %}
signal_false:
cmd.run:
- name: /bin/false
{% endif %}
@didinux
Copy link

didinux commented Nov 18, 2015

Hello,

I have try a mysql replication of salt. But i don't understand.
How do I get the value of the position and the log file on the master to send in Application Change to master to the slave.

Can you explain me the function set doquery ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment