From 0bd368eca6e38f70c6d12b0b9bf10f8fd2f19ae4 Mon Sep 17 00:00:00 2001 From: Wayne Schneider Date: Mon, 15 Aug 2016 12:18:58 -0500 Subject: [PATCH] Generalize Docker deployment playbook. --- docker/Vagrantfile | 1 + docker/docker-deploy.yml | 70 +++++++++++++++++++------------------- docker/group_vars/dev | 4 +++ docker/roles/dev/tasks/main.yml | 4 --- docker/roles/prod/tasks/main.yml | 4 --- 5 files changed, 40 insertions(+), 43 deletions(-) delete mode 100644 docker/roles/dev/tasks/main.yml delete mode 100644 docker/roles/prod/tasks/main.yml diff --git a/docker/Vagrantfile b/docker/Vagrantfile index c2d4e33..01235ca 100644 --- a/docker/Vagrantfile +++ b/docker/Vagrantfile @@ -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" diff --git a/docker/docker-deploy.yml b/docker/docker-deploy.yml index ca0d4ab..9acbd96 100644 --- a/docker/docker-deploy.yml +++ b/docker/docker-deploy.yml @@ -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: @@ -43,65 +43,65 @@ 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 - diff --git a/docker/group_vars/dev b/docker/group_vars/dev index 4540562..a95559e 100644 --- a/docker/group_vars/dev +++ b/docker/group_vars/dev @@ -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 index 5fd2412..0000000 --- a/docker/roles/dev/tasks/main.yml +++ /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 index eee7663..0000000 --- a/docker/roles/prod/tasks/main.yml +++ /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 -- 1.7.10.4