diff --git a/README.md b/README.md index 297b596..3fe7079 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Kafka heavily depends on zookeeper which is not part of this role. To install zo ## Role Variables -Available variables listed and described along with default values in `defaults/main.yml`. +Available variables listed and described along with default values in [defaults/main.yml](defaults/main.yml). ## Dependencies @@ -27,7 +27,8 @@ Available variables listed and described along with default values in `defaults/ ## Set up monitoring for Kafka -For enabling monitoring via JMX you have to create an environment file and set the environment variables used in the kafka startup script like this: +For enabling monitoring via JMX you have to create an environment file and set the environment variables used in the kafka startup script +according to your needs: ``` JMX_PORT=1099 @@ -42,6 +43,8 @@ This file needs to be referenced in the `kafka_environment_file` then. Here is a vars: kafka_environment_file: /etc/kafka/custom.env +An overview of the variables used by Kafka can be found in the [Kafka startup script](https://github.com/apache/kafka/blob/trunk/bin/kafka-run-class.sh). + ## Development Use [docker-molecule](https://github.com/nl2go/docker-molecule) following the instructions to run [Molecule](https://molecule.readthedocs.io/en/stable/) diff --git a/molecule/custom_environment/cleanup.yml b/molecule/custom_environment/cleanup.yml new file mode 100644 index 0000000..ea7e2eb --- /dev/null +++ b/molecule/custom_environment/cleanup.yml @@ -0,0 +1,12 @@ +--- +- name: Cleanup test resources + hosts: localhost + tasks: + - name: Stop zookeeper container + docker_container: + name: zookeeper + image: confluentinc/cp-zookeeper:5.5.0 + state: stopped + purge_networks: yes + delegate_to: localhost + run_once: true diff --git a/molecule/custom_environment/converge.yml b/molecule/custom_environment/converge.yml new file mode 100644 index 0000000..1d5d668 --- /dev/null +++ b/molecule/custom_environment/converge.yml @@ -0,0 +1,8 @@ +--- +- name: Configure hosts + hosts: all + become: yes + roles: + - role: ansible-role-kafka + vars: + kafka_environment_file: /etc/kafka/molecule.env diff --git a/molecule/custom_environment/molecule.yml b/molecule/custom_environment/molecule.yml new file mode 100644 index 0000000..fc34a13 --- /dev/null +++ b/molecule/custom_environment/molecule.yml @@ -0,0 +1,34 @@ +--- +driver: + name: docker +lint: | + set -e + yamllint . +platforms: + - name: ubuntu18 + image: ubuntu:18.04 + dockerfile: ../resources/Dockerfile.j2 + networks: + - name: kafka-network +provisioner: + name: ansible + lint: | + set -e + ansible-lint + inventory: + group_vars: + all: + kafka_version: 2.5.0 + host_vars: + ubuntu18: + kafka_zookeeper_connection_hosts: + - zookeeper:2181 +verifier: + name: ansible + lint: | + set -e + ansible-lint +dependency: + name: galaxy + options: + role-file: molecule/resources/requirements.yml diff --git a/molecule/custom_environment/prepare.yml b/molecule/custom_environment/prepare.yml new file mode 100644 index 0000000..1d04510 --- /dev/null +++ b/molecule/custom_environment/prepare.yml @@ -0,0 +1,45 @@ +--- +- name: Install required roles + hosts: all + roles: + - nl2go.openjdk + tasks: + - name: Prepare docker systemctl replacement script + get_url: + url: https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py + dest: /usr/bin/systemctl + mode: '0775' + - name: Start zookeeper container + docker_container: + name: zookeeper + image: confluentinc/cp-zookeeper:5.5.0 + env: + ZOOKEEPER_CLIENT_PORT: "2181" + ZOOKEEPER_TICK_TIME: "2000" + networks: + - name: kafka-network + delegate_to: localhost + run_once: true + - name: Install additional packages needed for testing + apt: + name: + - net-tools + - procps + - name: Set JMX_PORT environment variable + lineinfile: + path: /etc/kafka/molecule.env + regexp: '^JMX_PORT=' + line: JMX_PORT=1099 + create: yes + - name: Set KAFKA_JMX_OPTS environment variable + lineinfile: + path: /etc/kafka/molecule.env + regexp: '^KAFKA_JMX_OPTS=' + line: 'KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"' + create: yes + - name: Set KAFKA_HEAP_OPTS environment variable + lineinfile: + path: /etc/kafka/molecule.env + regexp: '^KAFKA_HEAP_OPTS=' + line: 'KAFKA_HEAP_OPTS="-Xmx192M"' + create: yes diff --git a/molecule/custom_environment/verify.yml b/molecule/custom_environment/verify.yml new file mode 100644 index 0000000..db506d0 --- /dev/null +++ b/molecule/custom_environment/verify.yml @@ -0,0 +1,17 @@ +--- +- name: Verify kafka installation + hosts: all + tasks: + - name: Gather facts on listening ports + listen_ports_facts: + - name: Create list of listening ports + set_fact: + tcp_ports: "{{ ansible_facts.tcp_listen | map(attribute='port') | sort | list }}" + - name: Verify kafka port is in listening ports + assert: + that: + - 9092 in tcp_ports + - name: Verify JMX port is in listening ports + assert: + that: + - 1099 in tcp_ports diff --git a/tasks/install.yml b/tasks/install.yml index 8a5a149..3c63401 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -11,7 +11,7 @@ state: present createhome: no -- name: set kafka_archive_name variable +- name: Set kafka_archive_name variable set_fact: kafka_archive_name: "kafka_{{ kafka_scala_version }}-{{ kafka_version }}"