# 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.

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.

## Start the Deployment

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

### Standalone Mode

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

If the servers have not been installed Java, you can append below part to the above playbook.

Now you can start deploying standalone ZooKeeper servers.

### Replicated Mode

Just as standalone mode, create a playbook named zookeeper_cluster.yml and insert below contents.

Also you can add ansible-java as a dependency.

Run below command to deploy ZooKeeper cluster.