Tutorial on ZooKeeper – Part 4: Use Ansible to Setup ZooKeeper Servers

From the last tutorial, we know how to install and configure a ZooKeeper cluster starting from scratch.

In order to simplify the deployment, I’ve written a ansible-zookeeper role, which is originally forked from AnsibleShipyard and modified to support both standalone mode and replicated mode (also known as cluster), to deploy ZooKeeper servers.

Note: This role requires Java support. You can install manually or use role ansible-java as a dependency. This role assumes that all your to-be-deployed servers have been already installed these required softwares.

Clone the Role

Before the deployment, you have to first clone the role to your ansible playbooks folder (just for better management), of course you can specify to other folders.

Prepare your own inventory

Just as last tutorial said, you have to be clear enough about your ZooKeeper servers. Touch your inventory file to store these servers. In order to differentiate these two modes for better demonstration, I create two sections, one is zookeeper_servers for standalone mode, the other is cluster_hosts for replicated mode. You can also give them other names. Take your choice.

1

$ vim myinventory

Start the Deployment

The default mode of this role is standalone, which means you can omit below parts in your yaml file.

1

vars:
install_mode: "standalone"

Standalone Mode

Once you have your own inventory file, you can create a blow playbook named zookeeper_standalone.yml and insert below contents.