Browse Source

Docker image changes

dev
root 4 years ago
parent
commit
079ded4dd1
  1. 38
      roles/lxc_swarm/tasks/deploy.yml
  2. 10
      roles/lxc_swarm/tasks/main.yml
  3. 22
      roles/lxc_swarm/tasks/swarm.yml
  4. 7
      roles/lxc_swarm/templates/galera.cnf.j2

38
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

10
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

22
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]

7
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] }}"

Loading…
Cancel
Save