Skip to content

Commit

Permalink
Merge pull request #29 from ernestas-poskus/features/allow_zookeeper_…
Browse files Browse the repository at this point in the history
…hosts_to_accept_list_and_hash

Allow zookeeper hosts to accept list and hash
  • Loading branch information
ernestas-poskus committed Jun 5, 2016
2 parents 24c3a25 + e3a103b commit 06f703c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 14 deletions.
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
language: python
python: "2.7"

env:
- SITE=playbook.yml

before_install:
- sudo apt-get update -qq
- sudo apt-get install curl -y
Expand All @@ -17,7 +14,13 @@ install:

script:
# Check the role/playbook's syntax.
- "ansible-playbook -i ci/inventory ci/$SITE --syntax-check"
- "ansible-playbook -i ci/inventory ci/playbook.yml --syntax-check"

# Run the ansible ci playbook
- "ansible-playbook -i ci/inventory ci/playbook.yml --connection=local --sudo -vvvv"

# Run the ansible hosts list
- "ansible-playbook -i ci/inventory ci/hosts_list.yml --connection=local --sudo -vvvv"

# Run the ansible hosts hash
- "ansible-playbook -i ci/inventory ci/hosts_hash.yml --connection=local --sudo -vvvv"
23 changes: 23 additions & 0 deletions ci/hosts_hash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
#
# Host hash playbook
#

- hosts: localhost
connection: local
sudo: yes
roles:
- role: ../../
zookeeper_hosts:
- host: "{{inventory_hostname}}" # the machine running
id: 2

- hosts: localhost
connection: local
sudo: yes
gather_facts: false
tasks:
# Expecting myid to be 2 as defined in zookeeper_hosts variable
- shell: "grep 2 /var/lib/zookeeper/myid"
register: status
failed_when: status.rc != 0
22 changes: 22 additions & 0 deletions ci/hosts_list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
#
# Host list playbook
#

- hosts: localhost
connection: local
sudo: yes
roles:
- role: ../../
zookeeper_hosts:
- "{{inventory_hostname}}"

- hosts: localhost
connection: local
sudo: yes
gather_facts: false
tasks:
# Expecting myid to be 1 defined by loop.index
- shell: "grep 1 /var/lib/zookeeper/myid"
register: status
failed_when: status.rc != 0
6 changes: 2 additions & 4 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
ansible_playbook_version: 0.1
zookeeper_playbook_version: "0.9.1.1"
zookeeper_playbook_version: "0.9.2"
zookeeper_version: 3.4.6
zookeeper_url: http://www.us.apache.org/dist/zookeeper/zookeeper-{{zookeeper_version}}/zookeeper-{{zookeeper_version}}.tar.gz

Expand All @@ -9,13 +9,11 @@ client_port: 2181
init_limit: 5
sync_limit: 2
tick_time: 2000
zoo_id: 1
data_dir: /var/lib/zookeeper
log_dir: /var/log/zookeeper
zookeeper_dir: /opt/zookeeper-{{zookeeper_version}}

# List of dict (i.e. {zookeeper_hosts:[{host:,id:},{host:,id:},...]})
zookeeper_hosts:
- host: "{{inventory_hostname}}" # the machine running
- host: "{{inventory_hostname}}" # the machine running
id: 1

12 changes: 11 additions & 1 deletion templates/myid.j2
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
{{ zoo_id }}
{% for server in zookeeper_hosts %}
{% if server.host is defined %}
{% if server.host == inventory_hostname %}
{{ server.id }}
{% endif %}
{% else %}
{% if server == inventory_hostname %}
{{ loop.index }}
{% endif %}
{% endif %}
{% endfor %}
10 changes: 5 additions & 5 deletions templates/zoo.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ clientPort={{ client_port }}
initLimit={{ init_limit }}
syncLimit={{ sync_limit }}

{#
Also consider:
server.{{server.id}}={{server.host}}:2888:3888
#}

{% for server in zookeeper_hosts %}
server.{{loop.index}}={{server.host}}:2888:3888
{% if server.host is defined %}
server.{{server.id}}={{server.host}}:2888:3888
{% else %}
server.{{loop.index}}={{server}}:2888:3888
{% endif %}
{% endfor %}

0 comments on commit 06f703c

Please sign in to comment.