Generalize Docker deployment playbook.
authorWayne Schneider <wayne@indexdata.com>
Mon, 15 Aug 2016 17:18:58 +0000 (12:18 -0500)
committerWayne Schneider <wayne@indexdata.com>
Mon, 15 Aug 2016 17:18:58 +0000 (12:18 -0500)
docker/Vagrantfile
docker/docker-deploy.yml
docker/group_vars/dev
docker/roles/dev/tasks/main.yml [deleted file]
docker/roles/prod/tasks/main.yml [deleted file]

index c2d4e33..01235ca 100644 (file)
@@ -19,6 +19,7 @@ Vagrant.configure(2) do |config|
 
   # Set up port forwarding
   config.vm.network "forwarded_port", guest: 8983, host: 8983
+  config.vm.network "forwarded_port", guest: 8983, host: 8984
 
   config.vm.provision "ansible" do |ansible|
     ansible.playbook = "docker-deploy.yml"
index ca0d4ab..9acbd96 100644 (file)
@@ -1,5 +1,5 @@
 ---
-# 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
-
index 4540562..a95559e 100644 (file)
@@ -1,3 +1,7 @@
 ---
 docker_users:
   - vagrant
+docker_image_path: /vagrant/docker/solr
+num_solr_servers: 2
+num_zk_servers: 1
+num_shards: 2
diff --git a/docker/roles/dev/tasks/main.yml b/docker/roles/dev/tasks/main.yml
deleted file mode 100644 (file)
index 5fd2412..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
----
-- name: Build the lui-solr image
-  become: yes
-  docker_image: name=lui-solr path=/vagrant/docker/solr
diff --git a/docker/roles/prod/tasks/main.yml b/docker/roles/prod/tasks/main.yml
deleted file mode 100644 (file)
index eee7663..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
----
-- name: Disable Docker apt repo
-  become: yes
-  apt_repository: repo="deb https://apt.dockerproject.org/repo debian-jessie main" state=absent