From b9f10515ce673258cc8507d6fec20b7fe0f46a54 Mon Sep 17 00:00:00 2001 From: Michael Vasseur Date: Sun, 17 Mar 2024 21:29:40 +0100 Subject: [PATCH] Replication fails in the ICPC image Because we have more interfaces we need to specify which network interface we want to use. --- .../ansible/roles/keepalived/templates/keepalived.conf.j2 | 2 +- .../ansible/roles/mysql_replication/tasks/main.yml | 8 ++++++++ .../mysql_replication/templates/mysql.replication.cnf.j2 | 2 +- .../mysql_replication/templates/setup-replication.sh.j2 | 4 ++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/provision-contest/ansible/roles/keepalived/templates/keepalived.conf.j2 b/provision-contest/ansible/roles/keepalived/templates/keepalived.conf.j2 index 8f4f5456..9d3a77d5 100644 --- a/provision-contest/ansible/roles/keepalived/templates/keepalived.conf.j2 +++ b/provision-contest/ansible/roles/keepalived/templates/keepalived.conf.j2 @@ -1,6 +1,6 @@ vrrp_instance lb_ipv4 { state MASTER - interface {{ ansible_facts['default_ipv4']['interface'] }} + interface {{ KEEPALIVED_INTERFACE|default(ansible_facts['default_ipv4']['interface']) }} use_vmac virtual_router_id 32 priority {{KEEPALIVED_PRIORITY}} diff --git a/provision-contest/ansible/roles/mysql_replication/tasks/main.yml b/provision-contest/ansible/roles/mysql_replication/tasks/main.yml index d820927f..0f873b66 100644 --- a/provision-contest/ansible/roles/mysql_replication/tasks/main.yml +++ b/provision-contest/ansible/roles/mysql_replication/tasks/main.yml @@ -13,6 +13,14 @@ regexp: '^bind-address\s*=' replace: '#bind-address =' +- name: Set the replication interface variable + set_fact: + replication_interface: "{{ REPLICATION_INTERFACE|default(ansible_default_ipv4.interface) }}" + +- name: Set the variable for the IP address of the replication interface + set_fact: + replication_interface_ip_address: "{{ vars['ansible_' + replication_interface]['ipv4']['address'] }}" + - name: Add mysql config snippet for replication template: src: mysql.replication.cnf.j2 diff --git a/provision-contest/ansible/roles/mysql_replication/templates/mysql.replication.cnf.j2 b/provision-contest/ansible/roles/mysql_replication/templates/mysql.replication.cnf.j2 index 12ca2520..93f58de0 100644 --- a/provision-contest/ansible/roles/mysql_replication/templates/mysql.replication.cnf.j2 +++ b/provision-contest/ansible/roles/mysql_replication/templates/mysql.replication.cnf.j2 @@ -8,4 +8,4 @@ log-bin = /var/log/mysql/mysql-bin.log binlog_do_db = domjudge # Host specific replication configuration -server_id = {{ ansible_default_ipv4.address | ipaddr('int') }} +server_id = {{ replication_interface_ip_address | ipaddr('int') }} diff --git a/provision-contest/ansible/roles/mysql_replication/templates/setup-replication.sh.j2 b/provision-contest/ansible/roles/mysql_replication/templates/setup-replication.sh.j2 index 0d32c5f9..d791d3f0 100755 --- a/provision-contest/ansible/roles/mysql_replication/templates/setup-replication.sh.j2 +++ b/provision-contest/ansible/roles/mysql_replication/templates/setup-replication.sh.j2 @@ -181,7 +181,7 @@ service mysql start echo "Starting replication locally..." mysql -e " -CHANGE MASTER TO MASTER_HOST='{{ SERVER_IP_PREFIX }}.${PRIMARY_SERVER_ID}', +CHANGE MASTER TO MASTER_HOST='${PRIMARY}', MASTER_USER='replication', MASTER_PASSWORD='{{ REPLICATION_PASSWORD }}', MASTER_LOG_FILE='${PRIMARY_BINLOG}', @@ -217,7 +217,7 @@ OUR_LOGPOS=$(get_field 'Position' "$OUR_STATUS") if [ "$SETUP_MASTER_MASTER" -eq 1 ]; then echo "Starting replication on $PRIMARY..." ssh "$PRIMARY" "mysql -e ' - CHANGE MASTER TO MASTER_HOST=\"{{ SERVER_IP_PREFIX }}.${OUR_SERVER_ID}\", + CHANGE MASTER TO MASTER_HOST=\"{{ replication_interface_ip_address }}\", MASTER_USER=\"replication\", MASTER_PASSWORD=\"{{ REPLICATION_PASSWORD }}\", MASTER_LOG_FILE=\"${OUR_BINLOG}\",