Last active
January 11, 2020 22:55
-
-
Save gpkvt/9134191 to your computer and use it in GitHub Desktop.
SaltStack: MySQL-Replication (Slave-Info)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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 %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ?