forked from jakub/ansible
edit kafka
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# update_redpanda_console.yml
|
# 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
|
hosts: proxmox
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
become: true
|
become: true
|
||||||
@@ -18,9 +18,14 @@
|
|||||||
DEBUG: "{{ lookup('env', 'DEBUG') | default(0) | int }}"
|
DEBUG: "{{ lookup('env', 'DEBUG') | default(0) | int }}"
|
||||||
RETRIES: "{{ lookup('env', 'RETRIES') | default(25) | int }}"
|
RETRIES: "{{ lookup('env', 'RETRIES') | default(25) | int }}"
|
||||||
|
|
||||||
# --- Redpanda Console specifics ---
|
# --- Kafka / Redpanda Console specifics ---
|
||||||
redpanda_console_image: "docker.redpanda.com/redpandadata/console:latest"
|
kafka_project: "kafka"
|
||||||
redpanda_console_container: "kafka-ui"
|
kafka_compose_file: "/data/compose/kafka/docker-compose.yml"
|
||||||
|
|
||||||
|
kafka_services:
|
||||||
|
- broker3
|
||||||
|
- kafka-ui
|
||||||
|
|
||||||
redpanda_console_port: 8084
|
redpanda_console_port: 8084
|
||||||
|
|
||||||
# Controller-side URL (default to direct VM IP/port)
|
# 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"
|
docker_prefix: "unalias docker 2>/dev/null || true; DOCKER_CLI_HINTS=0; command docker"
|
||||||
|
|
||||||
# Commands to run on the target VM (quiet outputs)
|
# Commands to run on the target VM (quiet outputs)
|
||||||
# NOTE: This only pulls the latest image; it does NOT recreate the container.
|
# Uses the compose stack for broker3 + kafka-ui
|
||||||
redpanda_console_commands:
|
kafka_commands:
|
||||||
- "{{ docker_prefix }} pull -q {{ redpanda_console_image }} >/dev/null"
|
- "{{ 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:
|
tasks:
|
||||||
- name: Ensure sshpass is installed (for password-based SSH) # English comments
|
- name: Ensure sshpass is installed (for password-based SSH) # English comments
|
||||||
@@ -44,7 +50,7 @@
|
|||||||
state: present
|
state: present
|
||||||
update_cache: yes
|
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:
|
ansible.builtin.command:
|
||||||
argv:
|
argv:
|
||||||
- sshpass
|
- sshpass
|
||||||
@@ -60,15 +66,15 @@
|
|||||||
- "{{ ('sudo ' if use_sudo else '') + item }}"
|
- "{{ ('sudo ' if use_sudo else '') + item }}"
|
||||||
environment:
|
environment:
|
||||||
SSHPASS: "{{ vm_pass }}" # supply password via environment
|
SSHPASS: "{{ vm_pass }}" # supply password via environment
|
||||||
loop: "{{ redpanda_console_commands }}"
|
loop: "{{ kafka_commands }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
index_var: idx # capture loop index
|
index_var: idx # capture loop index
|
||||||
label: "cmd-{{ idx }}" # avoid printing full command in (item=...) line
|
label: "cmd-{{ idx }}" # avoid printing full command in (item=...) line
|
||||||
register: redpanda_cmds
|
register: kafka_cmds
|
||||||
changed_when: false
|
changed_when: false
|
||||||
no_log: "{{ DEBUG == 0 }}" # hide outputs and env when not debugging
|
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:
|
ansible.builtin.debug:
|
||||||
msg: |
|
msg: |
|
||||||
CMD: {{ item.item }}
|
CMD: {{ item.item }}
|
||||||
@@ -77,24 +83,24 @@
|
|||||||
{{ (item.stdout | default('')).strip() }}
|
{{ (item.stdout | default('')).strip() }}
|
||||||
STDERR:
|
STDERR:
|
||||||
{{ (item.stderr | default('')).strip() }}
|
{{ (item.stderr | default('')).strip() }}
|
||||||
loop: "{{ redpanda_cmds.results }}"
|
loop: "{{ kafka_cmds.results }}"
|
||||||
when: DEBUG == 1
|
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:
|
ansible.builtin.assert:
|
||||||
that: "item.rc == 0"
|
that: "item.rc == 0"
|
||||||
fail_msg: "Redpanda Console update failed on VM: {{ item.item }} (rc={{ item.rc }})"
|
fail_msg: "Kafka/Redpanda Console update failed on VM: {{ item.item }} (rc={{ item.rc }})"
|
||||||
success_msg: "All Redpanda Console update commands succeeded."
|
success_msg: "All Kafka/Redpanda Console update commands succeeded."
|
||||||
loop: "{{ redpanda_cmds.results }}"
|
loop: "{{ kafka_cmds.results }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
index_var: idx
|
index_var: idx
|
||||||
label: "cmd-{{ 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:
|
ansible.builtin.uri:
|
||||||
url: "{{ redpanda_console_url }}"
|
url: "{{ redpanda_console_url }}"
|
||||||
method: GET
|
method: GET
|
||||||
@@ -111,73 +117,33 @@
|
|||||||
failed_when: false
|
failed_when: false
|
||||||
changed_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
|
- name: Redpanda Console | Print concise summary
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: >-
|
msg: >-
|
||||||
Redpanda Console overview {{ 'reachable' if (redpanda_overview_html is defined) else 'NOT reachable' }}.
|
Redpanda Console overview {{ 'reachable' if (redpanda_controller is defined and (redpanda_controller.status|default(0))==200) 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' }};
|
status={{ redpanda_controller.status | default('n/a') }};
|
||||||
length={{ (redpanda_overview_html | default('')) | length }};
|
length={{ (redpanda_controller.content | default('')) | length }};
|
||||||
contains('Redpanda')={{ (redpanda_overview_html is defined) and ('Redpanda' in redpanda_overview_html) }}
|
when: DEBUG == 1 and (redpanda_controller is defined)
|
||||||
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
|
|
||||||
|
|
||||||
# Optional detailed dump (short excerpt only)
|
# Optional detailed dump (short excerpt only)
|
||||||
- name: Redpanda Console | HTML excerpt (debug)
|
- name: Redpanda Console | HTML excerpt (debug)
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: "{{ (redpanda_overview_html | default(''))[:500] }}"
|
msg: "{{ (redpanda_controller.content | default(''))[:500] }}"
|
||||||
when: redpanda_overview_html is defined and DEBUG == 1
|
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."
|
||||||
|
|||||||
Reference in New Issue
Block a user