- hosts: kafka1, kafka2, kafka3 become: True tasks: - name: Update machines and install Java, Kafka shell: | apt update apt install -y default-jdk mkdir kafka_node cd kafka_node/ && wget https://dlcdn.apache.org/kafka/3.2.3/kafka_2.13-3.2.3.tgz && tar -xzf kafka_2.13-3.2.3.tgz && cd kafka_2.13-3.2.3 - name: On all kafka instances create log directory shell: mkdir /tmp/kafka-logs - name: On kafka1 instance update broker id when: "'kafka1' in group_names" lineinfile: path: /home/ubuntu/kafka_node/kafka_2.13-3.2.3/config/server.properties regexp: '^(.*)broker.id(.*)$' line: 'broker.id=1' backrefs: yes - name: On kafka2 instance update broker id when: "'kafka2' in group_names" lineinfile: path: /home/ubuntu/kafka_node/kafka_2.13-3.2.3/config/server.properties regexp: '^(.*)broker.id(.*)$' line: 'broker.id=2' backrefs: yes - name: On kafka3 instance update broker id when: "'kafka3' in group_names" lineinfile: path: /home/ubuntu/kafka_node/kafka_2.13-3.2.3/config/server.properties regexp: '^(.*)broker.id(.*)$' line: 'broker.id=3' backrefs: yes - name: On all kafka instance uncomment listeners lineinfile: path: /home/ubuntu/kafka_node/kafka_2.13-3.2.3/config/server.properties regexp: '^(.*)#listeners=PLAINTEXT://:9092(.*)$' line: 'listeners=PLAINTEXT://:9093' backrefs: yes - name: On all kafka instance update zookeeper.connect lineinfile: path: /home/ubuntu/kafka_node/kafka_2.13-3.2.3/config/server.properties regexp: '^(.*)zookeeper.connect=localhost:2181(.*)$' line: 'zookeeper.connect={{zk_1_ip}}:2181,{{zk_2_ip}}:2181,{{zk_3_ip}}:2181' backrefs: yes #- name: Start kafka_server # command: /home/ubuntu/kafka_node/kafka_2.13-3.2.3/bin/kafka-server-start.sh -daemon /home/ubuntu/kafka_node/kafka_2.13-3.2.3/config/server.properties