From ff2586ec7b7de8105e651f107f546b252b5453ea Mon Sep 17 00:00:00 2001 From: Jakub Duchek Date: Sun, 29 Mar 2026 12:26:11 +0200 Subject: [PATCH] Fixes #365 - Add tail command to show recent service logs Add a new foremanctl tail command as an alternative to foreman-tail. It uses journalctl to show recent logs from all Foreman services (foreman, dynflow, pulp, candlepin, httpd, redis, postgresql). Supports --service to filter specific services and --lines to control how many recent lines to display (default 50). Only services that are actually running are included in the output. --- src/playbooks/tail/metadata.obsah.yaml | 13 +++++++ src/playbooks/tail/tail.yaml | 49 ++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/playbooks/tail/metadata.obsah.yaml create mode 100644 src/playbooks/tail/tail.yaml diff --git a/src/playbooks/tail/metadata.obsah.yaml b/src/playbooks/tail/metadata.obsah.yaml new file mode 100644 index 000000000..ba0833231 --- /dev/null +++ b/src/playbooks/tail/metadata.obsah.yaml @@ -0,0 +1,13 @@ +--- +help: | + Show recent logs from Foreman services (similar to foreman-tail) +variables: + services: + parameter: --service + help: Specific service to tail. Can be specified multiple times. Defaults to all services. + action: append + persist: false + lines: + help: Number of recent log lines to show per service. + default: 50 + persist: false diff --git a/src/playbooks/tail/tail.yaml b/src/playbooks/tail/tail.yaml new file mode 100644 index 000000000..9d5b2e097 --- /dev/null +++ b/src/playbooks/tail/tail.yaml @@ -0,0 +1,49 @@ +--- +- name: Show recent Foreman service logs + hosts: quadlet + become: true + gather_facts: true + tags: + - foremanctl_suppress_default_output + vars: + services: [] + lines: 50 + all_services: + - foreman + - dynflow-sidekiq@orchestrator + - dynflow-sidekiq@worker + - dynflow-sidekiq@worker-hosts-queue + - pulp-api + - pulp-content + - candlepin + - httpd + - redis + - postgresql + tasks: + - name: Gather service facts + ansible.builtin.service_facts: + + - name: Determine active services + ansible.builtin.set_fact: + target_services: >- + {{ + (services if services | length > 0 else all_services) + | select('in', ansible_facts.services | map('regex_replace', '\.service$', '') | list) + | list + }} + + - name: Fetch recent logs + ansible.builtin.command: + cmd: >- + journalctl --no-pager -n {{ lines }} -u {{ item }} + loop: "{{ target_services }}" + register: log_results + changed_when: false + + - name: Display logs + ansible.builtin.debug: + msg: "{{ item.stdout_lines }}" + loop: "{{ log_results.results }}" + loop_control: + label: "{{ item.item }}" + when: item.stdout_lines | length > 0