From fdb5320429d278c9e6f497d5f14a76777c897ca9 Mon Sep 17 00:00:00 2001 From: Egon Rijpkema Date: Tue, 17 Oct 2017 17:12:52 +0200 Subject: [PATCH] add galera.cnf for first node --- mariadb.yml | 7 +++++++ roles/mariadb/tasks/main.yml | 14 ++++++++++++++ test_hosts | 2 ++ 3 files changed, 23 insertions(+) diff --git a/mariadb.yml b/mariadb.yml index 830e63d..2432187 100644 --- a/mariadb.yml +++ b/mariadb.yml @@ -4,3 +4,10 @@ become: True roles: - mariadb + vars: + hostname_node0: "{{ hostvars[groups['mariadb'][0]]['ansible_hostname'] }}" + hostname_node1: "{{ hostvars[groups['mariadb'][1]]['ansible_hostname'] }}" + hostname_node2: "{{ hostvars[groups['mariadb'][2]]['ansible_hostname'] }}" + ip_node0: "hostvars[groups['databases'][0]]['listen_ip'] | default(hostvars[groups['databases'][0]]['ansible_default_ipv4']['address'])" + ip_node1: "hostvars[groups['databases'][1]]['listen_ip'] | default(hostvars[groups['databases'][1]]['ansible_default_ipv4']['address'])" + ip_node2: "hostvars[groups['databases'][2]]['listen_ip'] | default(hostvars[groups['databases'][2]]['ansible_default_ipv4']['address'])" diff --git a/roles/mariadb/tasks/main.yml b/roles/mariadb/tasks/main.yml index 002fdbb..d28b8a3 100644 --- a/roles/mariadb/tasks/main.yml +++ b/roles/mariadb/tasks/main.yml @@ -31,6 +31,20 @@ dest: /srv/mariadb/etc/mysql mode: 660 +- name: Set galara.cnf on first node if we have at least three nodes. + copy: + src: files/galera-master.cnf + dest: /srv/mariadb/etc/mysql/conf.d/galera.cnf + mode: 660 + when: ansible_nodename == hostname_node0 and hostvars[groups['mariadb']]|length >= 3 + +- name: Set galara.cnf on other nodes if we have at least three nodes. + copy: + src: files/galera-slave.cnf + dest: /srv/mariadb/etc/mysql/conf.d/galera.cnf + mode: 660 + when: ansible_nodename != hostname_node0 and hostvars[groups['mariadb']]|length >= 3 + - command: systemctl daemon-reload - name: make sure service is started diff --git a/test_hosts b/test_hosts index f6969ba..f7eeb58 100644 --- a/test_hosts +++ b/test_hosts @@ -1,5 +1,7 @@ [databases] +ansible-test ansible-test-2 +ansible-test-3 [keystone] ansible-test-3