| # |
| # Licensed to the Apache Software Foundation (ASF) under one or more |
| # contributor license agreements. See the NOTICE file distributed with |
| # this work for additional information regarding copyright ownership. |
| # The ASF licenses this file to You under the Apache License, Version 2.0 |
| # (the "License"); you may not use this file except in compliance with |
| # the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| --- |
| # This role will install Kafka with Zookeeper in group 'kafka' in the environment inventory |
| |
| - name: (re)start zookeeper |
| docker_container: |
| name: zookeeper{{ groups['zookeepers'].index(inventory_hostname) }} |
| image: zookeeper:{{ zookeeper.version }} |
| state: started |
| recreate: true |
| restart_policy: "{{ docker.restart.policy }}" |
| env: |
| TZ: "{{ docker.timezone }}" |
| ZOO_MY_ID: "{{ groups['zookeepers'].index(inventory_hostname) + 1 }}" |
| ZOO_SERVERS: "{% set zhosts = [] %} |
| {% for host in groups['zookeepers'] %} |
| {% if host == inventory_hostname %} |
| {{ zhosts.append('server.' + (loop.index|string) + '=' + '0.0.0.0:2888:3888') }} |
| {% else %} |
| {{ zhosts.append('server.' + (loop.index|string) + '=' + hostvars[host].ansible_host + ':' + ((2888+loop.index-1)|string) + ':' + ((3888+loop.index-1)|string) ) }} |
| {% endif %} |
| {% endfor %} |
| {{ zhosts | join(' ') }}" |
| ports: |
| - "{{ zookeeper.port + groups['zookeepers'].index(inventory_hostname) }}:2181" |
| - "{{ 2888 + groups['zookeepers'].index(inventory_hostname) }}:2888" |
| - "{{ 3888 + groups['zookeepers'].index(inventory_hostname) }}:3888" |
| pull: "{{ zookeeper.pull_zookeeper | default(true) }}" |
| |
| - name: wait until the Zookeeper in this host is up and running |
| action: shell (echo ruok; sleep 1) | nc {{ ansible_host }} {{ zookeeper.port + groups['zookeepers'].index(inventory_hostname) }} |
| register: result |
| until: (result.rc == 0) and (result.stdout == 'imok') |
| retries: 36 |
| delay: 5 |