3
0
forked from jakub/ansible

edit kafka

This commit is contained in:
martin.fencl
2025-11-24 23:16:12 +01:00
parent aa4c6fb6b6
commit 04450776fe

View File

@@ -1,6 +1,6 @@
# update_redpanda_console.yml
- name: Update Redpanda Console on VM via Proxmox
- name: Update Kafka broker3 and Redpanda Console on VM via Proxmox
hosts: proxmox
gather_facts: false
become: true
@@ -18,9 +18,14 @@
DEBUG: "{{ lookup('env', 'DEBUG') | default(0) | int }}"
RETRIES: "{{ lookup('env', 'RETRIES') | default(25) | int }}"
# --- Redpanda Console specifics ---
redpanda_console_image: "docker.redpanda.com/redpandadata/console:latest"
redpanda_console_container: "kafka-ui"
# --- Kafka / Redpanda Console specifics ---
kafka_project: "kafka"
kafka_compose_file: "/data/compose/kafka/docker-compose.yml"
kafka_services:
- broker3
- kafka-ui
redpanda_console_port: 8084
# Controller-side URL (default to direct VM IP/port)
@@ -33,9 +38,10 @@
docker_prefix: "unalias docker 2>/dev/null || true; DOCKER_CLI_HINTS=0; command docker"
# Commands to run on the target VM (quiet outputs)
# NOTE: This only pulls the latest image; it does NOT recreate the container.
redpanda_console_commands:
- "{{ docker_prefix }} pull -q {{ redpanda_console_image }} >/dev/null"
# Uses the compose stack for broker3 + kafka-ui
kafka_commands:
- "{{ docker_prefix }} compose -p {{ kafka_project }} -f {{ kafka_compose_file }} pull {{ kafka_services | join(' ') }} >/dev/null"
- "{{ docker_prefix }} compose -p {{ kafka_project }} -f {{ kafka_compose_file }} up -d --no-deps --force-recreate {{ kafka_services | join(' ') }} >/dev/null"
tasks:
- name: Ensure sshpass is installed (for password-based SSH) # English comments
@@ -44,7 +50,7 @@
state: present
update_cache: yes
- name: Run Redpanda Console update commands on VM (via SSH) # use SSHPASS env, hide item value
- name: Run Kafka update commands on VM (via SSH) # use SSHPASS env, hide item value
ansible.builtin.command:
argv:
- sshpass
@@ -60,15 +66,15 @@
- "{{ ('sudo ' if use_sudo else '') + item }}"
environment:
SSHPASS: "{{ vm_pass }}" # supply password via environment
loop: "{{ redpanda_console_commands }}"
loop: "{{ kafka_commands }}"
loop_control:
index_var: idx # capture loop index
label: "cmd-{{ idx }}" # avoid printing full command in (item=...) line
register: redpanda_cmds
register: kafka_cmds
changed_when: false
no_log: "{{ DEBUG == 0 }}" # hide outputs and env when not debugging
- name: Show outputs for each Redpanda Console command
- name: Show outputs for each Kafka command
ansible.builtin.debug:
msg: |
CMD: {{ item.item }}
@@ -77,24 +83,24 @@
{{ (item.stdout | default('')).strip() }}
STDERR:
{{ (item.stderr | default('')).strip() }}
loop: "{{ redpanda_cmds.results }}"
loop: "{{ kafka_cmds.results }}"
when: DEBUG == 1
- name: Fail play if any Redpanda Console command failed # also hide item label
- name: Fail play if any Kafka command failed # also hide item label
ansible.builtin.assert:
that: "item.rc == 0"
fail_msg: "Redpanda Console update failed on VM: {{ item.item }} (rc={{ item.rc }})"
success_msg: "All Redpanda Console update commands succeeded."
loop: "{{ redpanda_cmds.results }}"
fail_msg: "Kafka/Redpanda Console update failed on VM: {{ item.item }} (rc={{ item.rc }})"
success_msg: "All Kafka/Redpanda Console update commands succeeded."
loop: "{{ kafka_cmds.results }}"
loop_control:
index_var: idx
label: "cmd-{{ idx }}"
# -------------------------
# Readiness checks (controller first, then VM fallback)
# Readiness check Redpanda Console UI
# -------------------------
- name: Redpanda Console | Wait for overview page (controller first, with retries)
- name: Redpanda Console | Wait for overview page (controller, with retries)
ansible.builtin.uri:
url: "{{ redpanda_console_url }}"
method: GET
@@ -111,73 +117,33 @@
failed_when: false
changed_when: false
- name: Redpanda Console | VM-side fetch (HTML via Python, with retries)
ansible.builtin.command:
argv:
- sshpass
- -e
- ssh
- -o
- StrictHostKeyChecking=no
- -o
- ConnectTimeout=15
- "{{ vm_user }}@{{ vm_ip }}"
- bash
- -lc
- |
python3 - <<'PY'
# Fetch Redpanda Console overview page from localhost and print HTML to stdout
import urllib.request, sys
try:
with urllib.request.urlopen("http://127.0.0.1:{{ redpanda_console_port }}/overview", timeout=15) as r:
sys.stdout.write(r.read().decode(errors='ignore'))
except Exception:
pass
PY
environment:
SSHPASS: "{{ vm_pass }}"
register: redpanda_vm
changed_when: false
failed_when: false
when: redpanda_controller.status | default(0) != 200 or redpanda_controller.content is not defined
retries: "{{ redpanda_retries }}"
delay: "{{ redpanda_delay }}"
until: (redpanda_vm.stdout | default('') | trim | length) > 0
no_log: "{{ DEBUG == 0 }}"
- name: Redpanda Console | Choose overview HTML (controller wins, else VM)
ansible.builtin.set_fact:
redpanda_overview_html: >-
{{
(
redpanda_controller.content
if (redpanda_controller is defined)
and ((redpanda_controller.status|default(0))==200)
and (redpanda_controller.content is defined)
else
(redpanda_vm.stdout | default('') | trim)
)
}}
when:
- (redpanda_controller is defined and (redpanda_controller.status|default(0))==200 and (redpanda_controller.content is defined))
or ((redpanda_vm.stdout | default('') | trim | length) > 0)
- name: Redpanda Console | Print concise summary
ansible.builtin.debug:
msg: >-
Redpanda Console overview {{ 'reachable' if (redpanda_overview_html is defined) else 'NOT reachable' }}.
Source={{ 'controller' if ((redpanda_controller is defined) and (redpanda_controller.status|default(0))==200 and (redpanda_controller.content is defined)) else 'vm' if (redpanda_vm.stdout|default('')|trim|length>0) else 'n/a' }};
length={{ (redpanda_overview_html | default('')) | length }};
contains('Redpanda')={{ (redpanda_overview_html is defined) and ('Redpanda' in redpanda_overview_html) }}
when: DEBUG == 1
- name: Redpanda Console | Web UI unavailable (after retries)
ansible.builtin.debug:
msg: "Redpanda Console web UI není dostupná ani po pokusech."
when: redpanda_overview_html is not defined and DEBUG == 1
Redpanda Console overview {{ 'reachable' if (redpanda_controller is defined and (redpanda_controller.status|default(0))==200) else 'NOT reachable' }}.
status={{ redpanda_controller.status | default('n/a') }};
length={{ (redpanda_controller.content | default('')) | length }};
when: DEBUG == 1 and (redpanda_controller is defined)
# Optional detailed dump (short excerpt only)
- name: Redpanda Console | HTML excerpt (debug)
ansible.builtin.debug:
msg: "{{ (redpanda_overview_html | default(''))[:500] }}"
when: redpanda_overview_html is defined and DEBUG == 1
msg: "{{ (redpanda_controller.content | default(''))[:500] }}"
when: DEBUG == 1 and (redpanda_controller is defined) and (redpanda_controller.content is defined)
# -------------------------
# Final assertion: Console URL must be reachable
# -------------------------
- name: Redpanda Console | Assert overview reachable (if URL configured)
ansible.builtin.assert:
that:
- >
not (redpanda_console_url is defined and (redpanda_console_url | length) > 0)
or
(
redpanda_controller is defined
and (redpanda_controller.status | default(0)) == 200
)
fail_msg: "Redpanda Console URL {{ redpanda_console_url }} is NOT reachable with HTTP 200 after retries."
success_msg: "Redpanda Console URL {{ redpanda_console_url }} is reachable with HTTP 200."