diff --git a/ansible/playbooks/roles/kafka/defaults/main.yml b/ansible/playbooks/roles/kafka/defaults/main.yml index 0abffa7915..418416f82f 100644 --- a/ansible/playbooks/roles/kafka/defaults/main.yml +++ b/ansible/playbooks/roles/kafka/defaults/main.yml @@ -1,4 +1,6 @@ kafka_version: 2.6.0 scala_version: 2.12 kafka_bin_filename: "kafka_2.12-2.6.0.tgz" +kafka_install_dir: "/opt/kafka_{{ scala_version }}-{{ kafka_version }}" + prometheus_jmx_exporter_path: /opt/jmx-exporter/jmx_prometheus_javaagent.jar diff --git a/ansible/playbooks/roles/kafka/tasks/common/download_and_unpack_binary.yml b/ansible/playbooks/roles/kafka/tasks/common/download_and_unpack_binary.yml new file mode 100644 index 0000000000..3f7450c9a9 --- /dev/null +++ b/ansible/playbooks/roles/kafka/tasks/common/download_and_unpack_binary.yml @@ -0,0 +1,22 @@ +--- + +- name: Download Kafka binaries + include_role: + name: download + tasks_from: download_file + vars: + file_name: "{{ kafka_bin_filename }}" + +- name: Uncompress the Kafka tar + unarchive: + remote_src: yes + creates: "{{ kafka_install_dir }}" + src: "{{ download_directory }}/{{ kafka_bin_filename }}" + dest: /opt + +- name: Change ownership on Kafka directory + file: + path: "{{ kafka_install_dir }}" + state: directory + owner: kafka + group: kafka \ No newline at end of file diff --git a/ansible/playbooks/roles/kafka/tasks/start.yml b/ansible/playbooks/roles/kafka/tasks/common/start.yml similarity index 92% rename from ansible/playbooks/roles/kafka/tasks/start.yml rename to ansible/playbooks/roles/kafka/tasks/common/start.yml index 47a87e4181..7ea0224c90 100644 --- a/ansible/playbooks/roles/kafka/tasks/start.yml +++ b/ansible/playbooks/roles/kafka/tasks/common/start.yml @@ -5,6 +5,7 @@ name: kafka state: started enabled: yes + daemon-reload: yes # - name: wait for kafka port # wait_for: host={{kafka.listen_address| default('localhost')}} port={{kafka.port}} state=started timeout={{ kafka.wait_for_period }} diff --git a/ansible/playbooks/roles/kafka/tasks/common/stop.yml b/ansible/playbooks/roles/kafka/tasks/common/stop.yml new file mode 100644 index 0000000000..27b4ab806e --- /dev/null +++ b/ansible/playbooks/roles/kafka/tasks/common/stop.yml @@ -0,0 +1,6 @@ +--- + +- name: Stop Kafka + systemd: + name: kafka + state: stopped diff --git a/ansible/playbooks/roles/kafka/tasks/main.yml b/ansible/playbooks/roles/kafka/tasks/main.yml index 30df870093..d9bfcf2938 100644 --- a/ansible/playbooks/roles/kafka/tasks/main.yml +++ b/ansible/playbooks/roles/kafka/tasks/main.yml @@ -13,5 +13,4 @@ - include_tasks: metrics.yml when: exporter.stat.exists -- include_tasks: start.yml - +- include_tasks: common/start.yml diff --git a/ansible/playbooks/roles/kafka/tasks/metrics.yml b/ansible/playbooks/roles/kafka/tasks/metrics.yml index 519d2476ff..5860540c83 100644 --- a/ansible/playbooks/roles/kafka/tasks/metrics.yml +++ b/ansible/playbooks/roles/kafka/tasks/metrics.yml @@ -7,7 +7,7 @@ append: yes - name: prometheus jmx | configuration file - become: yes + become: true copy: dest: "{{ specification.prometheus_jmx_config }}" src: jmx-kafka-config.yml diff --git a/ansible/playbooks/roles/kafka/tasks/setup-kafka.yml b/ansible/playbooks/roles/kafka/tasks/setup-kafka.yml index 7b793c8191..4db5b1fc6c 100644 --- a/ansible/playbooks/roles/kafka/tasks/setup-kafka.yml +++ b/ansible/playbooks/roles/kafka/tasks/setup-kafka.yml @@ -24,16 +24,8 @@ module_defaults: yum: { lock_timeout: "{{ yum_lock_timeout }}" } -- name: Set Kafka file name to install - set_fact: - kafka_file_name: "{{ kafka_bin_filename }}" - -- name: Download Kafka binaries - include_role: - name: download - tasks_from: download_file - vars: - file_name: "{{ kafka_file_name }}" +- name: Download and unpack Kafka's binary + include_tasks: common/download_and_unpack_binary.yml - name: Add Kafka's bin dir to the PATH copy: @@ -41,31 +33,11 @@ dest: "/etc/profile.d/kafka_path.sh" mode: 0755 -- name: Check for Kafka package - stat: - path: /opt/kafka_{{ scala_version }}-{{ kafka_version }}/bin/kafka-server-start.sh - register: kafka_package - -- name: Uncompress the Kafka tar - unarchive: - remote_src: yes - creates: /opt/kafka_{{ scala_version }}-{{ kafka_version }} - src: "{{ download_directory }}/{{ kafka_file_name }}" - dest: /opt - when: not kafka_package.stat.exists - -- name: Change ownership on kafka directory. - file: - path: /opt/kafka_{{ scala_version }}-{{ kafka_version }} - state: directory - owner: kafka - group: kafka - - name: Link /opt/kafka to the right version file: - dest: /opt/kafka + path: /opt/kafka state: link - src: /opt/kafka_{{ scala_version }}-{{ kafka_version }} + src: "{{ kafka_install_dir }}" - name: Create systemd config template: @@ -78,7 +50,8 @@ - restart kafka - name: Reload daemon - command: systemctl daemon-reload + systemd: + daemon-reload: yes - name: Create data_dir file: @@ -114,7 +87,7 @@ # Setup log4j.properties - name: Create log4j.properties file: - dest: "{{ specification.kafka_var.conf_dir }}/log4j.properties" + path: "{{ specification.kafka_var.conf_dir }}/log4j.properties" owner: "{{ specification.kafka_var.user }}" group: "{{ specification.kafka_var.group }}" mode: 0644 diff --git a/ansible/playbooks/roles/kafka/tasks/stop.yml b/ansible/playbooks/roles/kafka/tasks/stop.yml deleted file mode 100644 index d8416fb302..0000000000 --- a/ansible/playbooks/roles/kafka/tasks/stop.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- - -- name: Stop Kafka - service: name=kafka state=stopped diff --git a/ansible/playbooks/roles/kafka/tasks/upgrade/install-upgrade.yml b/ansible/playbooks/roles/kafka/tasks/upgrade/install-upgrade.yml index eb2448e81d..68ead8df3c 100644 --- a/ansible/playbooks/roles/kafka/tasks/upgrade/install-upgrade.yml +++ b/ansible/playbooks/roles/kafka/tasks/upgrade/install-upgrade.yml @@ -1,45 +1,24 @@ --- -- name: Set Kafka installation file name as fact - set_fact: - kafka_installation_file_name: "kafka_{{ scala_version }}-{{ kafka_version.new }}.tgz" - -- name: Download Kafka binaries - include_role: - name: download - tasks_from: download_file - vars: - file_name: "{{ kafka_installation_file_name }}" - -- name: Uncompress Kafka installation file - unarchive: - remote_src: yes - src: "{{ download_directory }}/{{ kafka_installation_file_name }}" - dest: /opt - -- name: Change ownership on kafka directory - file: - path: /opt/kafka_{{ scala_version }}-{{ kafka_version.new }} - state: directory - owner: kafka - group: kafka +- name: Download and unpack Kafka's binary + include_tasks: common/download_and_unpack_binary.yml - name: Copy configuration from previous version copy: remote_src: yes src: /opt/kafka/config/ - dest: /opt/kafka_{{ scala_version }}-{{ kafka_version.new }}/config + dest: "{{ kafka_install_dir}}/config" mode: preserve - name: Link /opt/kafka to recently installed version file: dest: /opt/kafka state: link - src: /opt/kafka_{{ scala_version }}-{{ kafka_version.new }} + src: "{{ kafka_install_dir}}" force: yes - name: Remove previous version binaries file: - path: /opt/kafka_{{ scala_version }}-{{ kafka_version.old }} + path: /opt/kafka_{{ scala_version }}-{{ old_kafka_version }} state: absent - name: Get log.dirs property diff --git a/ansible/playbooks/roles/kafka/tasks/upgrade/main.yml b/ansible/playbooks/roles/kafka/tasks/upgrade/main.yml index 68798a0953..d79968d856 100644 --- a/ansible/playbooks/roles/kafka/tasks/upgrade/main.yml +++ b/ansible/playbooks/roles/kafka/tasks/upgrade/main.yml @@ -1,11 +1,6 @@ --- -- name: Include defaults from kafka role - include_vars: - file: roles/kafka/defaults/main.yml - name: kafka_defaults - - name: Include pre-flight checks - include_tasks: kafka/preflight-check.yml + include_tasks: upgrade/preflight-check.yml - name: Get installed Kafka version shell: >- @@ -13,13 +8,9 @@ /opt/kafka/bin/kafka-server-start.sh --version | grep Commit | grep -oP '^\d+\.\d+\.\d+' register: result -- name: Set common facts +- name: Set old Kafka version fact set_fact: - kafka_version: - old: "{{ result.stdout }}" - new: "{{ kafka_defaults.kafka_version }}" - scala_version: "{{ kafka_defaults.scala_version }}" - kafka_bin_filename: "{{ kafka_defaults.kafka_bin_filename }}" + old_kafka_version: "{{ result.stdout }}" - name: Check for upgrade flag file stat: @@ -34,20 +25,18 @@ state: touch - name: Stop Kafka service - service: - name: kafka - state: stopped + include_tasks: common/stop.yml - name: Include update Kafka properties tasks - include_tasks: kafka/update-properties.yml + include_tasks: upgrade/update-properties.yml - name: Include Kafka upgrade tasks - include_tasks: kafka/install-upgrade.yml + include_tasks: upgrade/install-upgrade.yml - name: Include set Kafka version tasks - include_tasks: kafka/set-updated-version.yml + include_tasks: upgrade/set-updated-version.yml when: - - lock_file_status.stat.exists or kafka_version.old is version( kafka_version.new, '<' ) + - lock_file_status.stat.exists or old_kafka_version is version( kafka_version, '<' ) - name: Remove Kafka upgrade flag file file: diff --git a/ansible/playbooks/roles/kafka/tasks/upgrade/set-updated-version.yml b/ansible/playbooks/roles/kafka/tasks/upgrade/set-updated-version.yml index 0eda1ed76c..6014cb41f6 100644 --- a/ansible/playbooks/roles/kafka/tasks/upgrade/set-updated-version.yml +++ b/ansible/playbooks/roles/kafka/tasks/upgrade/set-updated-version.yml @@ -10,7 +10,4 @@ line: "inter.broker.protocol.version={{ kafka_version.new }}" - name: Start kafka service - systemd: - name: kafka - state: started - daemon-reload: yes + include_tasks: common/start.yml