---
- name: "Add nodes to required groups"
  hosts: localhost
  connection: local
  gather_facts: False
  tasks:
    - name: "Add all cluster nodes to the kafka-nodes group"
      add_host:
        name: "{{ hostvars[item.1].inventory_hostname }}"
        id: "{{ item.0 + 1 }}"
        groups: kafka-nodes
      with_indexed_items: groups['kafka-nodes']|sort

- name: "Show debug info"
  hosts: kafka-nodes
  sudo: yes
  sudo_user: root
  tasks:
    - name: "Show Kafka nodes info"
      debug: var=hostvars[inventory_hostname]
      when: debug


- name: "Apply zookeeper and kafka roles to the Kafka cluster"
  hosts: kafka-nodes
  sudo: yes
  sudo_user: root
  roles:
    - kafka

---
- name: "Add nodes to required groups"
  hosts: localhost
  connection: local
  gather_facts: False
  tasks:
    - name: "Add all cluster nodes to the kafka-nodes group"
      add_host:
        name: "{{ hostvars[item.1].inventory_hostname }}"
        id: "{{ item.0 + 1 }}"
        groups: kafka-nodes
      with_indexed_items: groups['kafka-nodes']|sort

- name: "Show debug info"
  hosts: kafka-nodes
  sudo: yes
  sudo_user: root
  tasks:
    - name: "Show Kafka nodes info"
      debug: var=hostvars[inventory_hostname]
      when: debug

- name: "Apply the common role to all nodes"
  hosts: kafka-nodes
  sudo: yes
  sudo_user: root
  roles:
    - common

- name: "Apply zookeeper and kafka roles to the Kafka cluster"
  hosts: kafka-nodes
  sudo: yes
  sudo_user: root
  roles:
    - kafka

Fix for the common role.
Fix for the common role.
