Skip to content

Commit

Permalink
Added README for how to use zookeeper_use_servers_inventory_hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
ObjectiveTruth committed Jul 29, 2022
1 parent 8304811 commit 70e6f5c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 22 deletions.
81 changes: 61 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,67 @@ See <https://github.com/ansible/ansible/issues/71528> for more information.

## Role Variables

| Variable | Default |
| ----------------------- | ----------------------------------------------------------------- |
| zookeeper_mirror | <http://www-eu.apache.org/dist/zookeeper> |
| zookeeper_version | 3.7.1 |
| zookeeper_package | apache-zookeeper-{{ zookeeper_version }}-bin.tar.gz |
| zookeeper_group | zookeeper |
| zookeeper_user | zookeeper |
| zookeeper_root_dir | /usr/share |
| zookeeper_install_dir | '{{ zookeeper_root_dir}}/apache-zookeeper-{{zookeeper_version}}' |
| zookeeper_dir | '{{ zookeeper_root_dir }}/zookeeper' |
| zookeeper_log_dir | /var/log/zookeeper |
| zookeeper_data_dir | /var/lib/zookeeper |
| zookeeper_data_log_dir | /var/lib/zookeeper |
| zookeeper_client_port | 2181 |
| zookeeper_id | 1 |
| zookeeper_leader_port | 2888 |
| zookeeper_election_port | 3888 |
| zookeeper_servers | zookeeper-nodes |
| zookeeper_environment | "JVMFLAGS": "-javaagent:/opt/jolokia/jolokia-jvm-1.6.0-agent.jar" |
| zookeeper_firewalld | false |
| Variable | Default | Comment |
|------------------------------------------|-------------------------------------------------------------------|----------------------------------------------------------------|
| zookeeper_mirror | <http://www-eu.apache.org/dist/zookeeper> ||
| zookeeper_version | 3.7.1 ||
| zookeeper_package | apache-zookeeper-{{ zookeeper_version }}-bin.tar.gz ||
| zookeeper_group | zookeeper ||
| zookeeper_user | zookeeper ||
| zookeeper_root_dir | /usr/share ||
| zookeeper_install_dir | '{{ zookeeper_root_dir}}/apache-zookeeper-{{zookeeper_version}}' ||
| zookeeper_dir | '{{ zookeeper_root_dir }}/zookeeper' ||
| zookeeper_log_dir | /var/log/zookeeper ||
| zookeeper_data_dir | /var/lib/zookeeper ||
| zookeeper_data_log_dir | /var/lib/zookeeper ||
| zookeeper_client_port | 2181 ||
| zookeeper_id | 1 | Unique per server and should be declared in the inventory file |
| zookeeper_leader_port | 2888 ||
| zookeeper_election_port | 3888 ||
| zookeeper_servers | zookeeper-nodes | See below |
| zookeeper_servers_use_inventory_hostname | false | See below |
| zookeeper_environment | "JVMFLAGS": "-javaagent:/opt/jolokia/jolokia-jvm-1.6.0-agent.jar" ||
| zookeeper_firewalld | false ||

## Inventory and zookeeper_servers variable

zookeeper_servers variable above accepts a list of inventory host names.
These will be used in the `zoo.cfg` to configure a multi-server cluster
so the hosts can find each other. By default, the hostname used in
the `zoo.cfg` will be the hostname reported by the `hostname` command on
the server(provided by the ansible_nodename variable). See the example below.

Assuming the below inventory file, and that the `hostname` command returns
only the hostname and does not include the domain name.

```ini
[zookeeper-nodes]
zoo1.foo.com zookeeper_id=1 #hostname command returns "zoo1"
zoo2.foo.com zookeeper_id=2 #hostname command returns "zoo2"
zoo3.foo.com zookeeper_id=3 #hostname command returns "zoo3"
```

And assuming the following role variables:

```yaml
...
- role: sleighzy.zookeeper
zookeeper_servers:
- zoo1.foo.com
- zoo2.foo.com
- zoo3.foo.com
```
The templated `zoo.cfg` file will contain the below entries:

```ini
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888
```

If you DO NOT want this behaviour and would like the `zoo.cfg` to template the
inventory_hostname then set `zookeeper_servers_use_inventory_hostname` to `true`

### Default Ports

Expand Down
2 changes: 1 addition & 1 deletion defaults/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ zookeeper_id: 1
zookeeper_leader_port: 2888
zookeeper_election_port: 3888
zookeeper_servers: "{{ groups['zookeeper-nodes'] }}"
zookeeper_use_servers_inventory_hostname: false
zookeeper_servers_use_inventory_hostname: false
zookeeper_environment: {}

# Set to "false" to disable the AdminServer. By default the AdminServer is enabled.
Expand Down
2 changes: 1 addition & 1 deletion templates/zoo.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ autopurge.purgeInterval={{ zookeeper_purge_interval }}
# a single unique number, e.g. 1, 2, etc.
{% for host in zookeeper_servers %}
server.{{ hostvars[host].zookeeper_id | default(zookeeper_id) }}={{
host if zookeeper_use_servers_inventory_hostname else hostvars[host].ansible_nodename
host if zookeeper_servers_use_inventory_hostname else hostvars[host].ansible_nodename
}}:{{ zookeeper_leader_port }}:{{ zookeeper_election_port }}
{% endfor %}

Expand Down

0 comments on commit 70e6f5c

Please sign in to comment.