From ec2fe4cb48da71dd97074aae6b22f757afb45494 Mon Sep 17 00:00:00 2001 From: Wayne Schneider Date: Mon, 15 Aug 2016 15:09:13 -0500 Subject: [PATCH] Update to use Docker networking instead of links. --- docker/docker-deploy.yml | 77 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 11 deletions(-) diff --git a/docker/docker-deploy.yml b/docker/docker-deploy.yml index 9acbd96..20578b5 100644 --- a/docker/docker-deploy.yml +++ b/docker/docker-deploy.yml @@ -43,16 +43,17 @@ become: yes service: name=docker enabled=yes state=started - - name: Build ZooKeeper links for Solr containers - set_fact: - zk_links: [] - zk_solr: [] + - name: Discover Docker networks + become: yes + command: docker network ls + register: docker_nets + changed_when: false + + - name: Create luinet network + become: yes + command: docker network create luinet + when: docker_nets.stdout.find('luinet') == -1 - - set_fact: - zk_links: "{{ zk_links + ['zk'+item+':ZK'+item] }}" - zk_solr: "{{ zk_solr + ['$ZK'+item+'_PORT_2181_TCP_ADDR:$ZK'+item+'_PORT_2181_TCP_PORT/solr'] }}" - with_sequence: start=1 end={{ num_zk_servers }} - - name: Launch ZooKeeper containers become: yes docker_container: @@ -60,6 +61,25 @@ image: jplock/zookeeper with_sequence: start=1 end={{ num_zk_servers }} + - name: Get ZooKeeper container networks + become: yes + command: docker inspect --format={% raw %}'{{json .NetworkSettings.Networks}}'{% endraw %} zk{{ item }} + register: zk_net + with_sequence: start=1 end={{ num_zk_servers }} + changed_when: false + + - name: Connect ZooKeeper containers to luinet network + become: yes + command: docker network connect luinet zk{{ item }} + with_sequence: start=1 end={{ num_zk_servers }} + when: (zk_net.results[item|int-1].stdout|from_json).luinet is not defined + + - name: Disconnect ZooKeeper containers from bridge network + become: yes + command: docker network disconnect bridge zk{{ item }} + with_sequence: start=1 end={{ num_zk_servers }} + when: (zk_net.results[item|int-1].stdout|from_json).bridge is defined + - name: Get contents of /solr path in ZooKeeper become: yes command: docker exec -t zk1 bin/zkCli.sh get /solr @@ -75,6 +95,16 @@ become: yes docker_image: name=lui-solr path={{ docker_image_path }} + - name: Build ZooKeeper links for Solr containers + set_fact: + # zk_links: [] + zk_solr: [] + + - set_fact: + # zk_links: "{{ zk_links + ['zk'+item+':ZK'+item] }}" + zk_solr: "{{ zk_solr + ['zk'+item+':2181'] }}" + with_sequence: start=1 end={{ num_zk_servers }} + - name: Launch Solr containers become: yes docker_container: @@ -82,9 +112,34 @@ image: lui-solr tty: yes published_ports: "{{ 8983+item|int-1 }}:8983" - links: "{{ zk_links }}" - command: bash -c '/opt/solr/bin/solr start -f -z {{ zk_solr|join(",") }}' + command: bash -c '/opt/solr/bin/solr start -f -z {{ zk_solr|join(",") }}/solr' + with_sequence: start=1 end={{ num_solr_servers }} + + - name: Get Solr container networks + become: yes + command: docker inspect --format={% raw %}'{{json .NetworkSettings.Networks}}'{% endraw %} solr{{ item }} + register: solr_net + with_sequence: start=1 end={{ num_solr_servers }} + changed_when: false + + - name: Connect Solr containers to luinet network + become: yes + command: docker network connect luinet solr{{ item }} + with_sequence: start=1 end={{ num_solr_servers }} + register: solr_luinet + when: (solr_net.results[item|int-1].stdout|from_json).luinet is not defined + + - name: Disconnect Solr containers from bridge network + become: yes + command: docker network disconnect bridge solr{{ item }} + with_sequence: start=1 end={{ num_solr_servers }} + when: (solr_net.results[item|int-1].stdout|from_json).bridge is defined + + - name: Restart solr on network change + become: yes + command: docker restart solr{{ item }} with_sequence: start=1 end={{ num_solr_servers }} + when: solr_luinet.results[item|int-1]|changed - name: Wait for ZooKeeper to see Solr become: yes -- 1.7.10.4