From 079ded4dd13e274f9e28d6be2f2836a2a9e147c2 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 12 Jun 2020 22:29:16 +0000 Subject: [PATCH] Docker image changes --- roles/lxc_swarm/tasks/deploy.yml | 38 ++++++++++++++++++++++++- roles/lxc_swarm/tasks/main.yml | 10 ++----- roles/lxc_swarm/tasks/swarm.yml | 22 ++++++++++++-- roles/lxc_swarm/templates/galera.cnf.j2 | 7 ----- 4 files changed, 60 insertions(+), 17 deletions(-) diff --git a/roles/lxc_swarm/tasks/deploy.yml b/roles/lxc_swarm/tasks/deploy.yml index 4909165..c0c1870 100644 --- a/roles/lxc_swarm/tasks/deploy.yml +++ b/roles/lxc_swarm/tasks/deploy.yml @@ -1,3 +1,39 @@ --- +- name: Create swarm secrets + shell: | + mkdir -p .secrets + openssl rand -base64 32 > .secrets/xtrabackup_password + openssl rand -base64 32 > .secrets/mysql_password + openssl rand -base64 32 > .secrets/mysql_root_password + run_once: true + - name: Deploy swarm stack - shell: docker stack deploy -c stack.yaml stack + shell: docker stack deploy -c stack_mariadb.yaml stack + +- name: Update swarm stack with proper environmental variables + shell: | + unset MASTER_ADDR + mcontainer_addr=`ssh root@10.0.3.100 "docker ps|xargs -n1|grep -i NAMES -A 1|tail -1"` + MASTER_ADDR=`ssh -t root@10.0.3.100 "docker exec -it $mcontainer_addr ip a s|grep -i 10.0|head -1 2>/dev/null" 2>&1 |grep inet|awk '{print $2}'|cut -d "/" -f 1|tr -d ' '` + env MASTER_ADDR="${MASTER_ADDR}" docker stack deploy -c stack_mariadb.yaml stack + docker service scale stack_bnode=1 + sleep 30 + args: + executable: /bin/bash + +#- name: Wait for seed container to start +# pause: +# seconds: 30 + +#- name: Start mariadb cluster on node1 +# shell: docker service scale stack_node1=1 + +#- name: Remove seed container +# shell: docker service rm stack_seed + +#- name: Wait for nodes[0] container to start +# pause: +# seconds: 30 + +#- name: Start mariadb on node2 +# shell: docker service scale stack_bnode=1 diff --git a/roles/lxc_swarm/tasks/main.yml b/roles/lxc_swarm/tasks/main.yml index 0f86e24..a4c367f 100644 --- a/roles/lxc_swarm/tasks/main.yml +++ b/roles/lxc_swarm/tasks/main.yml @@ -14,13 +14,9 @@ - include: swarm.yml tags: swarm -- setup: - tags: swarm - -- include: Dockerfile.yml - when: inventory_hostname in groups['workers'] - tags: swarm +#- setup: +# tags: swarm - include: deploy.yml + tags: swarm, deploy when: inventory_hostname in groups['manager'] - tags: swarm diff --git a/roles/lxc_swarm/tasks/swarm.yml b/roles/lxc_swarm/tasks/swarm.yml index dd263f3..f7ae9fd 100644 --- a/roles/lxc_swarm/tasks/swarm.yml +++ b/roles/lxc_swarm/tasks/swarm.yml @@ -19,14 +19,22 @@ remote_addrs: "10.0.3.1" when: inventory_hostname in groups['workers'] -- name: Prepare docker volumes +- name: Prepare docker mysql data volume file: - path: /var/container_data/mysql + path: /var/lib/mysql state: directory mode: '0777' recurse: true when: inventory_hostname in groups['workers'] +#- name: Prepare docker mysql configuration volume +# file: +# path: /etc/container_data/mysql +# state: directory +# mode: '0777' +# recurse: true +# when: inventory_hostname in groups['workers'] + - name: Add docker labels for galera master and secondary nodes shell: | docker node update --label-add node1=true worker1 @@ -39,3 +47,13 @@ # hostname: 'worker2' # node2: true # when: inventory_hostname in groups['workers'] + +- name: Pull 'colinmollenhour/mariadb-galera-swarm' docker image + docker_image: + name: 'colinmollenhour/mariadb-galera-swarm' + source: pull + when: inventory_hostname in groups['workers'] + +- name: Touch flag bootstrap file inside mariadb volume + shell: touch /var/lib/mysql/new-cluster + when: inventory_hostname in groups['workers'][0] diff --git a/roles/lxc_swarm/templates/galera.cnf.j2 b/roles/lxc_swarm/templates/galera.cnf.j2 index eb23f1a..c44c992 100644 --- a/roles/lxc_swarm/templates/galera.cnf.j2 +++ b/roles/lxc_swarm/templates/galera.cnf.j2 @@ -10,15 +10,8 @@ wsrep_provider=/usr/lib/galera/libgalera_smm.so # Galera Cluster Configuration wsrep_cluster_name="galera_cluster" -#wsrep_cluster_address="gcomm://{% for host in groups['workers'] %} {{hostvars[host]['ansible_default_ipv4']['address']}} {% endfor %}" -wsrep_cluster_address="gcomm://{% for address in container_address %} {{address}} {% endfor %}" # Galera Synchronization Configuration wsrep_sst_method=rsync # Galera Node Configuration -#wsrep_node_address="{{ ansible_default_ipv4.address }}" -#wsrep_node_name="{{ ansible_hostname }}" - -wsrep_node_address="{{ container_address[0] if ansible_hostname in groups['workers'][0] else container_address[1] }} -wsrep_node_name="{{ nodes[0] if ansible_hostname in groups['workers'][0] else nodes[1] }}"