Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: restart kafka if Java or Kafka is updated #7

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ kafka_version: 3.8.0
kafka_scala_version: 2.13
kafka_java_version: 17
kafka_install_dependencies: false
kafka_firewall_add_rules: false

kafka_open_file_limit: 800000
# if kafka_checksum is defined role will use that value instead getting checksum from kafka downloads page
# kafka_checksum: >
# sha512: B8679283 A2D8DAB8 6E7C636B 2C688FE9 D9E64AC4
Expand Down
30 changes: 23 additions & 7 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

- name: Install java
become: true
notify: Restart Kafka
ansible.builtin.package:
name: "{{ kafka__dependencies }}"
state: present
Expand Down Expand Up @@ -71,6 +72,7 @@
dest: "{{ kafka__download_destination }}"
mode: "0644"
timeout: 30

retries: 3
delay: 3

Expand All @@ -80,8 +82,8 @@
src: "{{ kafka__download_destination }}"
copy: false
dest: "{{ kafka_download_directory }}"
owner: "{{ kafka_user }}"
group: "{{ kafka_user_group }}"
owner: "root"
group: "root"

- name: Configure Kafka symlink
become: true
Expand All @@ -91,6 +93,7 @@
state: link
force: true
follow: false
notify: Restart Kafka

- name: Create Kafka data and log directories
become: true
Expand Down Expand Up @@ -136,6 +139,24 @@
create: true
notify: Restart Kafka

- name: Allow Firewall Controller Traffic
ansible.posix.firewalld:
port: 9093/tcp
permanent: true
state: enabled
immediate: true
loop: "{{ ansible_play_hosts }}"
when: "kafka_firewall_add_rules and ansible_os_family == 'RedHat' and 'controller' in (hostvars[item]['kafka_node_roles'] | default(kafka_node_roles))"

- name: Allow Firewall Broker Traffic
ansible.posix.firewalld:
port: 9092/tcp
permanent: true
state: enabled
immediate: true
loop: "{{ ansible_play_hosts }}"
when: "kafka_firewall_add_rules and ansible_os_family == 'RedHat' and 'broker' in (hostvars[item]['kafka_node_roles'] | default(kafka_node_roles))"

- name: Install Kafka service definition
become: true
ansible.builtin.template:
Expand Down Expand Up @@ -166,7 +187,6 @@

- name: Configure Kafka
become: true
become_user: "{{ kafka_user }}"
ansible.builtin.template:
src: server.properties.j2
dest: "{{ kafka__config_path }}"
Expand All @@ -183,7 +203,6 @@

- name: Check if cluster uuid lock file exists
become: true
become_user: "{{ kafka_user }}"
ansible.builtin.stat:
path: "{{ kafka__uuid_file }}"
register: kafka__reg_check_uuid_file
Expand All @@ -203,7 +222,6 @@

- name: Write cluster uuid
become: true
become_user: "{{ kafka_user }}"
ansible.builtin.copy:
content: "{{ kafka__reg_storage_random_uuid.stdout }}"
dest: "{{ kafka__uuid_file }}"
Expand All @@ -212,7 +230,6 @@

- name: Get cluster uuid
become: true
become_user: "{{ kafka_user }}"
ansible.builtin.command:
cmd: cat {{ kafka__uuid_file }}
delegate_to: "{{ groups['kafka__group_controller_nodes'] | first }}"
Expand All @@ -222,7 +239,6 @@

- name: Set cluster uuid
become: true
become_user: "{{ kafka_user }}"
ansible.builtin.set_fact:
kafka_cluster_id: "{{ kafka__reg_cluster_uuid.stdout }}"

Expand Down
1 change: 1 addition & 0 deletions templates/kafka.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Description=Kafka: Scalable Queuing System
After=network.target

[Service]
LimitNOFILE={{ kafka_open_file_limit}}
Copy link
Owner

@dragomirr dragomirr Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix spacing.

Also for kafka user below, I noticed that now while you are at it.

Thanks

Type=simple
EnvironmentFile=-/etc/sysconfig/kafka
User={{ kafka_user}}
Expand Down