-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkafka_setup.yml
95 lines (83 loc) · 2.91 KB
/
kafka_setup.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
- hosts: all
become: True
vars:
kafka_user: kafka
kafka_source: "https://apache.mirrors.tworzy.net/kafka/2.5.0/kafka_2.12-2.5.0.tgz"
package_req:
- wget
- net-tools
- openjdk-8-jdk
zookeeper_home: "/home/{{ kafka_user }}/zookeeper"
kafka_home: "/home/{{ kafka_user }}/kafka"
tasks:
- name: create user
user:
name: "{{ kafka_user }}"
- name: install packages
package:
state: present
name: "{{ item }}"
with_items:
- "{{ package_req }}"
- name: create directory structure
become_user: "{{ kafka_user }}"
file:
path: "{{ item }}"
state: directory
with_items:
- "{{ zookeeper_home }}"
- "{{ kafka_home }}"
- name: Download and deploy kafka binary
become_user: "{{ kafka_user }}"
unarchive:
src: "{{ kafka_source }}"
dest: "{{ kafka_home }}"
extra_opts: ["--strip-components=1"]
remote_src: yes
### Configuration
- name: Prepare Configuration
set_fact:
brokerid: "{{ hostvars[inventory_hostname].private_ipv4_addresses[0].split('.')[-1][-2:] }}"
tags: zookeeper,kafka,test
- name: Configure Zookeeper
template:
lstrip_blocks: yes
src: resources/templates/zookeeper.j2
dest: "{{ kafka_home }}/config/zookeeper.properties"
tags: zookeeper
- name: Configure Kafka
template:
lstrip_blocks: yes
src: resources/templates/kafka.j2
dest: "{{ kafka_home }}/config/server.properties"
tags: kafka,test
- name: Zookeeper Id
copy:
content: "{{ hostvars[inventory_hostname]['brokerid'] }}"
dest: "{{ zookeeper_home }}/myid"
owner: "{{ kafka_user }}"
group: "{{ kafka_user }}"
tags: zookeeper
- name: SystemD setup
template:
src: "resources/templates/systemd_{{ item }}.j2"
dest: "/etc/systemd/system/{{ item }}.service"
with_items:
- "zookeeper"
- "kafka"
tags: zookeeper,kafka,systemd
- name: Zookeeper start
systemd:
enabled: yes
name: zookeeper
daemon_reload: yes
state: started
tags: zookeeper, kafka, systemd
- name: Kafka start
systemd:
enabled: yes
name: kafka
daemon_reload: yes
state: started
tags: kafka, systemd