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

Add support for RedHat #27

Open
wants to merge 19 commits into
base: master
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
10 changes: 7 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
apache_mirror: http://apache.mirrors.tds.net
kafka_apache_mirror: "{{apache_mirror}}"
kafka_hosts: "{{ansible_fqdn}}:9092"
kafka_version: 0.8.1.1
kafka_version: "0.8.2.2"
scala_version: "2.10"
run_mode: Deploy
skip_install: False

Expand All @@ -18,11 +20,13 @@ kafka_log_retention_bytes: 104857600 #100 M
kafka_log_retention_hours: 24
kafka_log_segment_bytes: "{{kafka_log_retention_bytes}}"
kafka_log_cleanup_interval_mins: 1
log_dir: /var/log
kafka_log_dir: "{{ log_dir }}/kafka"
kafka_heap_opts: "-Xmx1G -Xms1G"
kafka_tarball_location: /root
kafka_tarball_name: "kafka_2.9.2-{{kafka_version}}.tgz"
kafka_tarball_name: "kafka_{{ scala_version }}-{{ kafka_version }}.tgz"
monasca_wait_for_period: 30
monasca_log_level: WARN
zookeeper_connection_timeout_ms: 1000000

verify: True
download_tmp_dir: "/opt/monasca_download_dir"
4 changes: 4 additions & 0 deletions tasks/DebianInst.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: Install OpenJDK
apt: name=openjdk-7-jre-headless state=present
when: not skip_install
4 changes: 4 additions & 0 deletions tasks/RedHatInst.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: Install OpenJDK
yum: name=java-1.7.0-openjdk state=present
when: not skip_install
64 changes: 47 additions & 17 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,32 @@
user: name={{kafka_user}} system=yes group={{kafka_group}}

- name: Uncompress the kafka tar
unarchive: copy=no creates=/opt/kafka_2.9.2-{{kafka_version}} dest=/opt src="{{ kafka_tarball_location }}/{{ kafka_tarball_name }}"
unarchive:
copy=no
creates="/opt/kafka_{{ scala_version }}-{{ kafka_version }}"
dest=/opt
src="{{ download_tmp_dir }}/kafka_{{ scala_version }}-{{ kafka_version }}.tgz"
owner="{{ kafka_user }}"
group="{{ kafka_group }}"
mode="u=rwX,g=rX,o-rwx"

- name: Link /opt/kafka to the right version
file: path=/opt/kafka state=link src=/opt/kafka_2.9.2-{{kafka_version}}
file:
path=/opt/kafka
state=link
src="/opt/kafka_{{ scala_version }}-{{ kafka_version }}"
owner="{{ kafka_user }}"
group="{{ kafka_group }}"

- name: Overwrite the start script so the Java Opts can be changed if Kafka 0.8.1.1
lineinfile: dest=/opt/kafka_2.9.2-{{kafka_version}}/bin/kafka-server-start.sh regexp="^export KAFKA_HEAP_OPTS=" line="export KAFKA_HEAP_OPTS=\"{{ kafka_heap_opts }}\""
- name: Overwrite the start script so the Java Opts can be changed
lineinfile:
dest="/opt/kafka_{{ scala_version }}-{{ kafka_version }}/bin/kafka-server-start.sh"
regexp="^(\s*)export KAFKA_HEAP_OPTS="
line="\1export KAFKA_HEAP_OPTS=\"{{ kafka_heap_opts }}\""
backrefs=yes
notify:
- restart kafka
when: kafka_version == "0.8.1.1"
when: kafka_version|version_compare('0.8', '>=')

- name: Detect if this is a systemd based system
command: cat /proc/1/comm
Expand All @@ -25,14 +41,14 @@
- set_fact: use_systemd=False
when: init.stdout != 'systemd'

- name: create upstart config
template: dest={{kafka_upstart_conf}} owner=root group=root mode=644 src=kafka.conf.j2
- name: Create upstart config
template: dest={{kafka_upstart_conf}} owner=root group=root mode=640 src=kafka.conf.j2
notify:
- restart kafka
when: not use_systemd

- name: create systemd config
template: dest={{kafka_systemd_service}} owner=root group=root mode=644 src=kafka.service.j2
- name: Create systemd config
template: dest={{kafka_systemd_service}} owner=root group=root mode=640 src=kafka.service.j2
notify:
- restart kafka
when: use_systemd
Expand All @@ -41,26 +57,40 @@
when: use_systemd

- name: Create data_dir
file: path={{kafka_data_dir}} state=directory owner={{kafka_user}} group={{kafka_group}} mode=755
file: path={{kafka_data_dir}} state=directory owner={{ kafka_user }} group={{ kafka_group }} mode=750

- name: Remove lost+found in the datadir
file: path="{{kafka_data_dir}}/lost+found" state=absent

- name: Create log_dir
file: path={{kafka_log_dir}} state=directory owner={{kafka_user}} group={{kafka_group}} mode=755
file: path={{kafka_log_dir}} state=directory owner={{ kafka_user }} group={{ kafka_group }} mode=750

- name: link conf_dir to /opt/kafka/config
file: path={{kafka_conf_dir}} state=link src=/opt/kafka/config
- name: Link conf_dir to /opt/kafka/config
file:
path={{kafka_conf_dir}}
state=link
src=/opt/kafka/config
owner="{{ kafka_user }}"
group="{{ kafka_group }}"

# Setup log4j.properties
- name: create log4j.properties
template: dest="{{kafka_conf_dir}}/log4j.properties" owner={{kafka_user}} group={{kafka_group}} mode=644 src=log4j.properties.j2
- name: Create log4j.properties
template:
dest="{{kafka_conf_dir}}/log4j.properties"
owner={{kafka_user}}
group={{kafka_group}}
mode=640 src=log4j.properties.j2
notify:
- restart kafka

# Setup server.properties
- name: create server.properties
template: dest="{{kafka_conf_dir}}/server.properties" owner={{kafka_user}} group={{kafka_group}} mode=640 src=server.properties.j2
- name: Create server.properties
template:
dest="{{kafka_conf_dir}}/server.properties"
owner={{kafka_user}}
group={{kafka_group}}
mode=640
src=server.properties.j2
notify:
- restart kafka

Expand Down
34 changes: 31 additions & 3 deletions tasks/install.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
---
- name: Install OpenJDK
apt: name=openjdk-7-jre-headless state=present
- include: DebianInst.yml
when: "ansible_os_family == 'Debian'"

- include: RedHatInst.yml
when: "ansible_os_family == 'RedHat'"

- name: Check if temporary directory already exists
stat: path="{{ download_tmp_dir }}"
register: st

- name: Create download temporary directory
file: path="{{ download_tmp_dir }}" state=directory force=true
when: download_tmp_dir is defined and not st.stat.exists

- name: Setup group
group: name="{{ kafka_group }}" system=yes

- name: Setup user
user: name="{{ kafka_user }}" system=yes group="{{ kafka_group }}"

- name: Fetch kafka binary package
get_url: dest="{{ kafka_tarball_location }}/{{ kafka_tarball_name }}" url="{{apache_mirror}}/kafka/{{kafka_version}}/{{kafka_tarball_name}}"
get_url:
dest="{{ download_tmp_dir }}/{{kafka_tarball_name}}"
url="{{kafka_apache_mirror}}/kafka/{{kafka_version}}/{{kafka_tarball_name}}"

- name: Set owner and group for kafka package
file:
path="{{ download_tmp_dir }}/{{kafka_tarball_name}}"
state=file
owner={{ kafka_user }}
group={{ kafka_group }}
mode=640
when: download_tmp_dir is defined and not st.stat.exists
3 changes: 3 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@

- include: start.yml
when: run_mode == 'Start' or run_mode == 'Deploy'

- include: status.yml
when: run_mode == 'Status' or run_mode == 'Deploy'
4 changes: 0 additions & 4 deletions tasks/start.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
- name: Enable and Start Kafka
service: name=kafka state=started enabled=yes

- name: wait for kafka port
wait_for: host={{kafka_listen_address| default('localhost')}} port={{kafka_port}} state=started timeout={{ monasca_wait_for_period }}
when: verify
9 changes: 9 additions & 0 deletions tasks/status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# Copyright 2016 FUJITSU LIMITED

- name: Check Kafka status
wait_for:
host="{{ kafka_listen_address|default('localhost') }} "
port="{{ kafka_port|int }} "
state=started
timeout="{{ monasca_wait_for_period|int }}"
1 change: 1 addition & 0 deletions templates/kafka.service.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[Unit]
Description=Kafka Daemon
Requires=network.target
Copy link
Contributor

Choose a reason for hiding this comment

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

In some installs zookeeper runs on the same box as kafka. In those cases it is important that zookeeper start first. In cases where zookeeper is not on the same box systemd handles the situation properly and ignores this line. The line should stay for that first case.

After=zookeeper.service

[Service]
Expand Down
5 changes: 2 additions & 3 deletions templates/log4j.properties.j2
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ log4j.logger.kafka={{ monasca_log_level }}, kafkaAppender
#log4j.logger.kafka.request.logger=TRACE, requestAppender
#log4j.additivity.kafka.request.logger=false

log4j.logger.kafka.controller=TRACE, controllerAppender
log4j.logger.kafka.controller={{ monasca_log_level }}, controllerAppender
log4j.additivity.kafka.controller=false

log4j.logger.state.change.logger=TRACE, stateChangeAppender
log4j.logger.state.change.logger={{ monasca_log_level }}, stateChangeAppender
log4j.additivity.state.change.logger=false

5 changes: 1 addition & 4 deletions templates/server.properties.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# The id of the broker. This must be set to a unique integer for each broker.
{% for url in kafka_hosts.split(',') %}
{%- set url_host = url.split(':')[0] -%}
{%- if url_host == ansible_fqdn or url_host in ansible_all_ipv4_addresses
or ( kafka_id is defined and loop.index0 == kafka_id | int ) -%}
{%- if url_host == ansible_fqdn or url_host in ansible_all_ipv4_addresses -%}
broker.id={{loop.index0}}

############################# Socket Server Settings #############################
Expand Down Expand Up @@ -109,5 +108,3 @@ zookeeper.connect={{zookeeper_hosts}}

# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms={{zookeeper_connection_timeout_ms}}