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 a role to manage the Kafka Exporter #112

Closed
wants to merge 6 commits into from
Closed
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
67 changes: 0 additions & 67 deletions playbooks/amq_streams_distributed.yml

This file was deleted.

16 changes: 0 additions & 16 deletions playbooks/brokers.yml

This file was deleted.

16 changes: 0 additions & 16 deletions playbooks/describe_topic.yml

This file was deleted.

12 changes: 12 additions & 0 deletions playbooks/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@
ansible.builtin.include_role:
name: amq_streams_broker
vars:
amq_streams_common_skip_download: true

Check warning on line 25 in playbooks/playbook.yml

View workflow job for this annotation

GitHub Actions / ci / linter (3.11, 2.15)

var-naming[no-role-prefix]

Variables names from within roles should use amq_streams_broker_ as a prefix. (vars: amq_streams_common_skip_download)

- name: "Ensure Kafka Connect is running and available."
ansible.builtin.include_role:
name: amq_streams_connect
vars:
amq_streams_common_skip_download: true

Check warning on line 31 in playbooks/playbook.yml

View workflow job for this annotation

GitHub Actions / ci / linter (3.11, 2.15)

var-naming[no-role-prefix]

Variables names from within roles should use amq_streams_connect_ as a prefix. (vars: amq_streams_common_skip_download)

Check warning on line 31 in playbooks/playbook.yml

View workflow job for this annotation

GitHub Actions / ci / linter (3.11, 2.15)

var-naming[no-role-prefix]

Variables names from within roles should use amq_streams_connect_ as a prefix. (vars: connectors)
connectors:
- { name: "file", path: "connectors/file.yml" }

- name: "Ensure AMQ Streams Broker is running and available."
ansible.builtin.include_role:
name: amq_streams_exporter
vars:
amq_streams_common_skip_download: true

Check warning on line 39 in playbooks/playbook.yml

View workflow job for this annotation

GitHub Actions / ci / linter (3.11, 2.15)

var-naming[no-role-prefix]

Variables names from within roles should use amq_streams_exporter_ as a prefix. (vars: amq_streams_common_skip_download)

post_tasks:

- name: "Validate that deployment is functional."
Expand All @@ -48,6 +55,11 @@
name: amq_streams_connect
tasks_from: validate.yml

- name: "Validate that Exporter deployment is functional."
ansible.builtin.include_role:
name: amq_streams_exporter
tasks_from: validate.yml

- name: "Ensures topics exist."
ansible.builtin.include_role:
name: amq_streams_broker
Expand All @@ -56,7 +68,7 @@
loop_control:
loop_var: topic
vars:
topic_name: "{{ topic.name }}"

Check warning on line 71 in playbooks/playbook.yml

View workflow job for this annotation

GitHub Actions / ci / linter (3.11, 2.15)

var-naming[no-role-prefix]

Variables names from within roles should use amq_streams_broker_ as a prefix. (vars: topic_name)

Check warning on line 71 in playbooks/playbook.yml

View workflow job for this annotation

GitHub Actions / ci / linter (3.11, 2.15)

var-naming[no-role-prefix]

Variables names from within roles should use amq_streams_broker_ as a prefix. (vars: topic_partitions)

Check warning on line 71 in playbooks/playbook.yml

View workflow job for this annotation

GitHub Actions / ci / linter (3.11, 2.15)

var-naming[no-role-prefix]

Variables names from within roles should use amq_streams_broker_ as a prefix. (vars: topic_replication_factor)
topic_partitions: "{{ topic.partitions }}"
topic_replication_factor: "{{ topic.replication_factor }}"

Expand All @@ -68,7 +80,7 @@
loop_control:
loop_var: topic
vars:
topic_name: "{{ topic.name }}"

Check warning on line 83 in playbooks/playbook.yml

View workflow job for this annotation

GitHub Actions / ci / linter (3.11, 2.15)

var-naming[no-role-prefix]

Variables names from within roles should use amq_streams_broker_ as a prefix. (vars: topic_name)

- name: "Delete topics"
ansible.builtin.include_role:
Expand All @@ -78,4 +90,4 @@
loop_control:
loop_var: topic
vars:
topic_name: "{{ topic.name }}"

Check warning on line 93 in playbooks/playbook.yml

View workflow job for this annotation

GitHub Actions / ci / linter (3.11, 2.15)

var-naming[no-role-prefix]

Variables names from within roles should use amq_streams_broker_ as a prefix. (vars: topic_name)
16 changes: 0 additions & 16 deletions playbooks/zookeepers.yml

This file was deleted.

3 changes: 1 addition & 2 deletions roles/amq_streams_common/tasks/systemd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
ansible.builtin.assert:
that:
- server_name is defined
- server_config is defined
quiet: true

- name: "Ensure {{ server_name }} configuration is deployed ({{ server_config_template }} -> {{ server_config }}."
Expand All @@ -14,7 +13,7 @@
group: root
mode: 0644
when:
- server_config_template is defined
- server_config_template is defined and server_config is defined
notify:
- "Restart {{ server_name }}"
become: yes
Expand Down
2 changes: 1 addition & 1 deletion roles/amq_streams_common/templates/service_systemd.j2
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ After=syslog.target network.target
{% endif %}
#
#
ExecStart={{ server_start }} {{ server_config }} {% if server_extra_args is defined %}{{ server_extra_args }}{% endif %}
ExecStart={{ server_start }} {% if server_config is defined %}{{ server_config }}{% endif %} {% if server_extra_args is defined %}{{ server_extra_args }}{% endif %}

{% if service_start_sleep | int > 0 %}
ExecStartPre=/bin/sleep {{ service_start_sleep | int / 1000 }}
Expand Down
5 changes: 5 additions & 0 deletions roles/amq_streams_exporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Connect Role

Perform installation and configuration of Kafka Export.

## Role Defaults
33 changes: 33 additions & 0 deletions roles/amq_streams_exporter/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
#amq_streams_exporter_target_system: "{{ ansible_system | lower }}"
amq_streams_exporter_target_arch: "{{ ansible_architecture }}"
amq_streams_exporter_version: 1.7.0
amq_streams_exporter_download_base_url: 'https://github.com/danielqsj/kafka_exporter/releases/download/'
amq_streams_exporter_download_url: "{{ amq_streams_exporter_download_base_url }}v{{ amq_streams_exporter_version }}/kafka_exporter-{{ amq_streams_exporter_version }}.{{ amq_streams_exporter_target_system }}-{{ amq_streams_exporter_target_arch }}.tar.gz"
amq_streams_exporter_archive_folder: "kafka_exporter-{{ amq_streams_exporter_version }}.{{ amq_streams_exporter_target_system }}-{{ amq_streams_exporter_target_arch }}"
amq_streams_exporter_archive_name: "{{ amq_streams_exporter_archive_folder }}.tar.gz"
amq_streams_exporter_download_dir: "{{ lookup('env','PWD') | default('/opt') }}"
amq_streams_exporter_download_path: "{{ amq_streams_exporter_download_dir }}/{{ amq_streams_exporter_archive_name }}"
amq_streams_exporter_download_host: localhost
amq_streams_exporter_home: "{{ amq_streams_common_home }}"
amq_streams_exporter_server_start: "{{ amq_streams_common_home }}/{{ amq_streams_exporter_archive_folder }}/{{ amq_streams_exporter_server_start_script }}"
amq_streams_exporter_dependencies:
- tar
- unzip
amq_streams_exporter_service_name: amq_streams_exporter
amq_streams_exporter_server_port: 9308
amq_streams_exporter_server_start_script: kafka_exporter

#amq_streams_exporter_server_config: /etc/amq_streams_exporter
#amq_streams_exporter_config_template: templates/exporter.properties.j2
amq_streams_exporter_systemd_env_file: /etc/amq_streams_exporter.conf
amq_streams_exporter_service_config_template: templates/service.conf.j2
#amq_streams_exporter_service_config_template: templates/service.conf.j2
amq_streams_exporter_user: amq_streams_exporter
amq_streams_exporter_group: amq_streams
amq_streams_exporter_java_opts: ''
amq_streams_exporter_server_port_delay: 0
amq_streams_exporter_server_port_skip_wait: False
amq_streams_exporter_broker_server_host: "{{ groups['brokers'][0] | default('localhost') }}"
amq_streams_exporter_broker_server_port: 9092
amq_streams_exporter_server_extra_args: "--group.filter='.*' --topic.filter='.*' --offset.show-all --verbosity=0 --kafka.version='{{ amq_streams_common_product_version }}' --kafka.server={{ amq_streams_exporter_broker_server_host }}:{{ amq_streams_exporter_broker_server_port }}"
6 changes: 6 additions & 0 deletions roles/amq_streams_exporter/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: "Restart {{ amq_streams_exporter_service_name }}"
ansible.builtin.service:
name: "{{ amq_streams_exporter_service_name }}"
state: restarted
become: yes
29 changes: 29 additions & 0 deletions roles/amq_streams_exporter/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
collections:
- middleware_automation.common

galaxy_info:
role_name: amq_streams_exporter
namespace: middleware_automation
author: Romain Pelisse
description: Install AMQ Streams Exporter server
company: Red Hat, Inc.

license: Apache License 2.0

min_ansible_version: "2.14"

platforms:
- name: EL
versions:
- 8

galaxy_tags:
- java
- jboss
- wildfly
- cli
- server

dependencies:
- { role: amq_streams_common }
45 changes: 45 additions & 0 deletions roles/amq_streams_exporter/tasks/download.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
- name: "Ensure required parameters are provided."
ansible.builtin.assert:
that:
- amq_streams_exporter_download_url is defined
- amq_streams_exporter_download_url | length > 0
- amq_streams_exporter_download_path is defined
quiet: True

- name: "Switch arch to 386 if x86_64 as there is no x86_64 releases of exporter"
ansible.builtin.set_fact:
amq_streams_exporter_target_arch: 386
when:
- amq_streams_exporter_target_arch is defined and amq_streams_exporter_target_arch == 'x86_64'

- name: "Ensure archive file is available on {{ amq_streams_exporter_download_host }}"
delegate_to: "{{ amq_streams_exporter_download_host }}"
block:
- name: "Checks if file is already downloaded on controller"
ansible.builtin.stat:
path: "{{ amq_streams_exporter_download_path }}"
register: exporter_download_path

- name: "Ensures metadate of {{ amq_streams_exporter_download_path }} are correct."
ansible.builtin.assert:
that:
- exporter_download_path is defined
- exporter_download_path.stat is defined
- exporter_download_path.stat.exists is defined
quiet: True

- name: "Download Kafka exporter from {{ amq_streams_exporter_download_url }}."
ansible.builtin.get_url:
url: "{{ amq_streams_exporter_download_url }}"
dest: "{{ amq_streams_exporter_download_path }}"
mode: 0644
when:
- not exporter_download_path.stat.exists

- name: "Extract archive file {{ amq_streams_exporter_archive_name }} in {{ amq_streams_exporter_home }}."
ansible.builtin.unarchive:
src: "{{ amq_streams_exporter_download_path }}"
dest: "{{ amq_streams_exporter_home }}"
owner: "{{ amq_streams_exporter_user | default(omit) }}"
group: "{{ amq_streams_exporter_group | default(omit) }}"
11 changes: 11 additions & 0 deletions roles/amq_streams_exporter/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: "Ensure prerequisite are fullfilled."
ansible.builtin.include_tasks: prereqs.yml

- name: "Download Kafka Exporter (if defined)."
ansible.builtin.include_tasks: download.yml
when:
- not amq_streams_common_redhat_enable is defined or not amq_streams_common_redhat_enable

- name: "Deploy Kafka Connect as a systemd service."
ansible.builtin.include_tasks: service.yml
23 changes: 23 additions & 0 deletions roles/amq_streams_exporter/tasks/prereqs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- name: "Ensure required parameter(s) are defined."
ansible.builtin.assert:
that:
- amq_streams_common_home is defined
- amq_streams_exporter_broker_server_host is defined
- amq_streams_exporter_broker_server_port is defined
quiet: true

- name: "Ensure user and group exists (if provided)."
ansible.builtin.include_role:
name: amq_streams_common
tasks_from: prereqs.yml
vars:
prereqs_user: "{{ amq_streams_exporter_user }}"
prereqs_group: "{{ amq_streams_exporter_group }}"

- name: "Ensure all required system dependencies are present: {{ amq_streams_exporter_dependencies }}"
ansible.builtin.package:
name: "{{ amq_streams_common_dependencies }}"
state: present
when:
- amq_streams_exporter_dependencies is defined and amq_streams_exporter_dependencies | length > 0
28 changes: 28 additions & 0 deletions roles/amq_streams_exporter/tasks/service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
- name: "Configure firewalld for Kafka Connect (if enable)."
ansible.builtin.include_role:
name: amq_streams_common
tasks_from: firewalld.yml
vars:
service_port: "{{ amq_streams_exporter_server_port }}"
when:
- amq_streams_firewalld_enabled is defined and amq_streams_firewalld_enabled
- amq_streams_exporter_server_port is defined

- name: "Deploy Kafka Connect as a systemd service."
ansible.builtin.include_role:
name: amq_streams_common
tasks_from: systemd.yml
vars:
service_systemd_workdir: "{{ amq_streams_common_home }}"
server_name: "{{ amq_streams_exporter_service_name }}"
server_start: "{{ amq_streams_exporter_server_start }}"
service_systemd_env_file: "{{ amq_streams_exporter_systemd_env_file }}"
service_systemd_env_file_template: "{{ amq_streams_exporter_service_config_template }}"
server_extra_args: "{{ amq_streams_exporter_server_extra_args }}"
server_user: "{{ amq_streams_exporter_user }}"
server_group: "{{ amq_streams_exporter_group }}"
server_java_opts: "{{ amq_streams_exporter_java_opts }}"
server_port: "{{ amq_streams_exporter_server_port }}"
skip_wait_for_server_port: "{{ amq_streams_exporter_server_port_skip_wait }}"
delay_before_server_port_check: "{{ amq_streams_exporter_server_port_delay }}"
7 changes: 7 additions & 0 deletions roles/amq_streams_exporter/tasks/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: "Ensure required parameter(s) are provided."
ansible.builtin.include_role:
name: amq_streams_common
tasks_from: validation/service.yml
vars:
service_name: "{{ amq_streams_exporter_service_name }}"
Loading