---
-# deploy a Docker server with 1 Zookeeper, 3 Solr, 1 HAProxy
+# deploy a Docker server with Zookeeper, Solr, HAProxy
- hosts: all
tasks:
become: yes
service: name=docker enabled=yes state=started
- - name: Check for luinet network
- command: docker network ls -f name=luinet -q
- register: luinet
-
- - name: Create luinet network
- command: docker network create luinet
- when: luinet.stdout == ""
-
- - name: Launch ZooKeeper
- docker_container: name=zk1 image=jplock/zookeeper
-
- - name: Get networks for ZooKeeper
- shell: "docker inspect --format={% raw %}'{{json .NetworkSettings.Networks}}'{% endraw %} zk1"
- register: zk1_networks
-
- - name: Attach ZooKeeper to luinet network
- command: docker network connect luinet zk1
- when: (zk1_networks.stdout|from_json).luinet is not defined
+ - 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+'_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:
+ name: zk{{ item }}
+ image: jplock/zookeeper
+ with_sequence: start=1 end={{ num_zk_servers }}
- - name: Detach ZooKeeper from bridge network
- command: docker network disconnect bridge zk1
- when: (zk1_networks.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
+ register: zk1_solr
+ changed_when: false
-- hosts: dev
- roles:
- - dev
+ - name: Create /solr path in ZooKeeper
+ become: yes
+ command: docker exec -t zk1 bin/zkCli.sh create /solr []
+ when: zk1_solr.stdout.find('Node does not exist') != -1
-- hosts: prod
- roles:
- - prod
+ - name: Build the lui-solr image
+ become: yes
+ docker_image: name=lui-solr path={{ docker_image_path }}
-- hosts: all
+ - name: Launch Solr containers
+ become: yes
+ docker_container:
+ name: solr{{ item }}
+ 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(",") }}'
+ with_sequence: start=1 end={{ num_solr_servers }}
+
+ - name: Wait for ZooKeeper to see Solr
+ become: yes
+ command: docker exec -t zk1 bin/zkCli.sh get /solr/live_nodes
+ register: solr_nodes
+ until: solr_nodes.stdout.find('numChildren = {{ num_solr_servers }}') != -1
+ retries: 3
+ delay: 2
+ changed_when: false
+
+ - name: Check lui collection
+ become: yes
+ command: docker exec -t zk1 bin/zkCli.sh ls /solr/collections
+ register: lui_collection
+ changed_when: false
- tasks:
- - name: Get networks for Solr
- shell: "docker inspect --format={% raw %}'{{json .NetworkSettings.Networks}}'{% endraw %} solr1"
- register: solr1_networks
-
- - name: Attach Solr to luinet network
- command: docker network connect luinet solr1
- when: (solr1_networks.stdout|from_json).luinet is not defined
-
- - name: Detach Solr from bridge network
- command: docker network disconnect bridge solr1
- when: (solr1_networks.stdout|from_json).bridge is defined
-
- # - name: Create Solr container
- # docker_container:
- # name: solr1
- # tty: yes
- # published_ports: 8983:8983
- # #volumes: /vagrant/conf/solr/solr-home:/opt/solr/server/solr
- # command: bash -c '/opt/solr/bin/solr start -f -z zk1:2181'
+ - name: Create lui collection
+ become: yes
+ command: docker exec -t solr1 bin/solr create -c lui -d /opt/solr/lui-solr -shards 2 -replicationFactor 2
+ when: (lui_collection.stdout_lines|last).find('lui') == -1