This guide provides a full Ansible playbook to install Zookeeper with distro-aware package handling and baseline service configuration for Debian 10+, Ubuntu LTS, and RHEL 9+ compatible systems.
- name: Install Zookeeper
hosts: zookeeper
become: true
vars:
app_config_dir: /etc/zookeeper
tasks:
- name: Install package on Debian/Ubuntu
apt:
name:
- zookeeper
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install package on RHEL family
dnf:
name:
- zookeeper
state: present
when: ansible_os_family == "RedHat"
- name: Create configuration directory
file:
path: "{{ app_config_dir }}"
state: directory
mode: "0755"
- name: Enable and start service
service:
name: zookeeper
state: started
enabled: true
failed_when: false
- name: Verify ZooKeeper is running
command: "echo ruok | nc 127.0.0.1 2181"
register: zk_status
changed_when: false
failed_when: false
- name: Show ZooKeeper status
debug:
var: zk_status.stdout
Any questions?
Feel free to contact us. Find all contact information on our contact page.