Browse Source

Docker image changes

dev
root 5 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 - 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 - include: swarm.yml
tags: swarm tags: swarm
- setup: #- setup:
tags: swarm # tags: swarm
- include: Dockerfile.yml
when: inventory_hostname in groups['workers']
tags: swarm
- include: deploy.yml - include: deploy.yml
tags: swarm, deploy
when: inventory_hostname in groups['manager'] 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" remote_addrs: "10.0.3.1"
when: inventory_hostname in groups['workers'] when: inventory_hostname in groups['workers']
- name: Prepare docker volumes - name: Prepare docker mysql data volume
file: file:
path: /var/container_data/mysql path: /var/lib/mysql
state: directory state: directory
mode: '0777' mode: '0777'
recurse: true recurse: true
when: inventory_hostname in groups['workers'] 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 - name: Add docker labels for galera master and secondary nodes
shell: | shell: |
docker node update --label-add node1=true worker1 docker node update --label-add node1=true worker1
@ -39,3 +47,13 @@
# hostname: 'worker2' # hostname: 'worker2'
# node2: true # node2: true
# when: inventory_hostname in groups['workers'] # 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 # Galera Cluster Configuration
wsrep_cluster_name="galera_cluster" 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 # Galera Synchronization Configuration
wsrep_sst_method=rsync wsrep_sst_method=rsync
# Galera Node Configuration # 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