diff --git a/Makefile b/Makefile index 07a29e0..c983726 100644 --- a/Makefile +++ b/Makefile @@ -8,3 +8,6 @@ provision: swarm_deploy: /bin/bash ./ansible_swarm_config.sh + +clean: + /bin/bash ./clean.sh diff --git a/clean.sh b/clean.sh new file mode 100755 index 0000000..6b042c7 --- /dev/null +++ b/clean.sh @@ -0,0 +1,5 @@ +#!/bin/bash +docker stack rm stack +lxc-stop --name worker1; lxc-stop --name worker2 +docker node rm worker1; docker node rm worker2 +rm -rf /var/lib/lxc/worker* diff --git a/roles/lxc_swarm/tasks/Dockerfile.yml b/roles/lxc_swarm/tasks/Dockerfile.yml deleted file mode 100644 index f18f4b3..0000000 --- a/roles/lxc_swarm/tasks/Dockerfile.yml +++ /dev/null @@ -1,40 +0,0 @@ ---- -- setup: - tags: galera - -- name: Copy galera template - template: - src: galera.cnf.j2 - dest: /opt/galera.cnf - owner: root - group: root - mode: '0644' - remote_src: no - tags: galera - -- name: Galera template fix - shell: sed -i "s/ /,/g;s/ 1/1/g;s/ "/"/g" /opt/galera.cnf - -#- name: set mysql options fact -# set_fact: -# extra_docker_options: "--wsrep-new-cluster" -# when: ansible_hostname == 'worker1' - -- name: Copy Dockerfile template - template: - src: Dockerfile.j2 - dest: /opt/Dockerfile - remote_src: no - -#- name: Build 'swarm-galera' image -# docker_image: -# name: 'swarm-galera' -# build: -# path: / -# tag: v1 -# source: build - -- name: Build image from Dockerfile - shell: docker build -t ubuntu:galera-node-{{ ansible_hostname }} . - args: - chdir: /opt diff --git a/roles/lxc_swarm/tasks/deploy.yml b/roles/lxc_swarm/tasks/deploy.yml index c0c1870..5c48194 100644 --- a/roles/lxc_swarm/tasks/deploy.yml +++ b/roles/lxc_swarm/tasks/deploy.yml @@ -7,17 +7,17 @@ openssl rand -base64 32 > .secrets/mysql_root_password run_once: true -- name: Deploy swarm stack - shell: docker stack deploy -c stack_mariadb.yaml stack +- name: Deploy swarm stack deployment file + shell: docker stack deploy -c stack.yaml stack -- name: Update swarm stack with proper environmental variables +- name: Update swarm stack service "bnode" 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 + env MASTER_ADDR="${MASTER_ADDR}" docker stack deploy -c stack.yaml stack docker service scale stack_bnode=1 - sleep 30 +# sleep 30 args: executable: /bin/bash diff --git a/roles/lxc_swarm/tasks/main.yml b/roles/lxc_swarm/tasks/main.yml index a4c367f..dbaaf75 100644 --- a/roles/lxc_swarm/tasks/main.yml +++ b/roles/lxc_swarm/tasks/main.yml @@ -18,5 +18,5 @@ # tags: swarm - include: deploy.yml - tags: swarm, deploy + tags: swarm when: inventory_hostname in groups['manager'] diff --git a/roles/lxc_swarm/templates/Dockerfile.j2 b/roles/lxc_swarm/templates/Dockerfile.j2 deleted file mode 100644 index ed9b222..0000000 --- a/roles/lxc_swarm/templates/Dockerfile.j2 +++ /dev/null @@ -1,11 +0,0 @@ -FROM ubuntu:16.04 -RUN apt-get update -RUN apt-get install -y software-properties-common wget -RUN wget https://mariadb.org/mariadb_release_signing_key.asc -O - | apt-key add - -RUN add-apt-repository "deb [arch=amd64,arm64,i386,ppc64el] http://mirrors.coreix.net/mariadb/repo/10.4/ubuntu xenial main" -RUN apt-get update -RUN apt install -y rsync mariadb-server-10.4 galera-4 mariadb-client-10.4 -RUN systemctl unmask mariadb -COPY galera.cnf /etc/mysql/conf.d/galera.cnf -#RUN echo "wsrep_node_address=`ip a s eth0|grep inet|head -1|awk '{print $2}'|cut -d "/" -f 1`" >> /etc/mysql/conf.d/galera.cnf -ENTRYPOINT ["mysqld","{{ extra_docker_options }}"] diff --git a/roles/lxc_swarm/templates/galera.cnf.j2 b/roles/lxc_swarm/templates/galera.cnf.j2 deleted file mode 100644 index c44c992..0000000 --- a/roles/lxc_swarm/templates/galera.cnf.j2 +++ /dev/null @@ -1,17 +0,0 @@ -[mysqld] -binlog_format=ROW -default-storage-engine=innodb -innodb_autoinc_lock_mode=2 -bind-address=0.0.0.0 - -# Galera Provider Configuration -wsrep_on=ON -wsrep_provider=/usr/lib/galera/libgalera_smm.so - -# Galera Cluster Configuration -wsrep_cluster_name="galera_cluster" - -# Galera Synchronization Configuration -wsrep_sst_method=rsync - -# Galera Node Configuration