--- - name: Prepare swarm manager docker_swarm: state: present advertise_addr: "{{ interface }}" when: inventory_hostname in groups['manager'] - name: Get the Manager join-token shell: docker swarm join-token --quiet worker register: worker_token when: inventory_hostname in groups['manager'] - name: Prepare swarm workers docker_swarm: state: join advertise_addr: "{{ interface }}" join_token: "{{ hostvars[groups['manager'][0]]['worker_token']['stdout'] }}" #remote_addrs: "{{ hostvars[groups['manager'][0]]['ansible_lxcbr0_ipv4.address'] }}" remote_addrs: "10.0.3.1" when: inventory_hostname in groups['workers'] - name: Prepare docker mysql data volume file: 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 docker node update --label-add node2=true worker2 when: inventory_hostname in groups['manager'] #- name: Add docker labels for galera secondary nodes # docker_node: # labels: # 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]