---
-# 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: Launch ZooKeeper
+ - 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=zk1 image=jplock/zookeeper
+ docker_container:
+ name: zk{{ item }}
+ image: jplock/zookeeper
+ with_sequence: start=1 end={{ num_zk_servers }}
- 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
- 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
-# Separate paths for setting up Solr nodes
-
-- hosts: dev
- roles:
- - dev
-
-- hosts: prod
- roles:
- - prod
-
-# Back to everyone
-
-- hosts: all
- tasks:
- - name: Launch Solr1
+ - name: Build the lui-solr image
become: yes
- docker_container:
- name: solr1
- image: lui-solr
- tty: yes
- published_ports: 8983:8983
- links: zk1:ZK1
- command: bash -c '/opt/solr/bin/solr start -f -z $ZK1_PORT_2181_TCP_ADDR:$ZK1_PORT_2181_TCP_PORT/solr'
+ docker_image: name=lui-solr path={{ docker_image_path }}
- - name: Launch Solr2
+ - name: Launch Solr containers
become: yes
docker_container:
- name: solr2
+ name: solr{{ item }}
image: lui-solr
tty: yes
- published_ports: 8984:8983
- links: zk1:ZK1
- command: bash -c '/opt/solr/bin/solr start -f -z $ZK1_PORT_2181_TCP_ADDR:$ZK1_PORT_2181_TCP_PORT/solr'
+ 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 }}
- ### HERE I AM ###
- # wait for ZooKeeper to see all the solr nodes before proceeding
- # look at Ansible until module
+ - 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
- name: Create lui collection
become: yes
- command: docker exec -t solr1 bin/solr create -c lui -d /opt/solr/lui-solr -shards 2
+ 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
-