- hosts: zookeeper1, zookeeper2, zookeeper3 become: True tasks: - name: Update machines and install Java, Zookeeper shell: | apt update apt install -y default-jdk mkdir Zookeeper_node cd Zookeeper_node/ && wget https://dlcdn.apache.org/zookeeper/zookeeper-3.8.0/apache-zookeeper-3.8.0-bin.tar.gz && tar -xzf apache-zookeeper-3.8.0-bin.tar.gz && cd apache-zookeeper-3.8.0-bin - name: On zookeeper1 instance create Zookeeper directory when: "'zookeeper1' in group_names" shell: mkdir /tmp/zookeeper && echo 1 >> /tmp/zookeeper/myid - name: On zookeeper1 instance setup confiuration for Zookeeper cluster when: "'zookeeper1' in group_names" copy: dest: "/home/ubuntu/Zookeeper_node/apache-zookeeper-3.8.0-bin/conf/zoo.cfg" content: | tickTime=2000 dataDir=/tmp/zookeeper clientPort=2181 maxClientCnxns=60 initLimit=10 syncLimit=5 4lw.commands.whitelist=* server.1=0.0.0.0:2888:3888 server.2={{zk_2_ip}}:2888:3888 server.3={{zk_3_ip}}:2888:3888 - name: On zookeeper2 instance create Zookeeper directory when: "'zookeeper2' in group_names" shell: mkdir /tmp/zookeeper && echo 2 >> /tmp/zookeeper/myid - name: On zookeeper1 instance setup confiuration for Zookeeper cluster when: "'zookeeper2' in group_names" copy: dest: "/home/ubuntu/Zookeeper_node/apache-zookeeper-3.8.0-bin/conf/zoo.cfg" content: | tickTime=2000 dataDir=/tmp/zookeeper clientPort=2181 maxClientCnxns=60 initLimit=10 syncLimit=5 4lw.commands.whitelist=* server.1={{zk_1_ip}}:2888:3888 server.2=0.0.0.0:2888:3888 server.3={{zk_3_ip}}:2888:3888 - name: On zookeeper3 instance create Zookeeper directory when: "'zookeeper3' in group_names" shell: mkdir /tmp/zookeeper && echo 3 >> /tmp/zookeeper/myid - name: On zookeeper3 instance setup confiuration for Zookeeper cluster when: "'zookeeper3' in group_names" copy: dest: "/home/ubuntu/Zookeeper_node/apache-zookeeper-3.8.0-bin/conf/zoo.cfg" content: | tickTime=2000 dataDir=/tmp/zookeeper clientPort=2181 maxClientCnxns=60 initLimit=10 syncLimit=5 4lw.commands.whitelist=* server.1={{zk_1_ip}}:2888:3888 server.2={{zk_2_ip}}:2888:3888 server.3=0.0.0.0:2888:3888 - name: Start Zookeeper server command: /home/ubuntu/Zookeeper_node/apache-zookeeper-3.8.0-bin/bin/zkServer.sh start