28 lines
866 B
YAML
28 lines
866 B
YAML
---
|
|
# View logs for a specific service
|
|
# Usage: ansible-playbook playbooks/common/logs.yml -e "service_name=plex" -e "target_host=atlantis"
|
|
- name: View service logs
|
|
hosts: "{{ target_host }}"
|
|
gather_facts: false
|
|
|
|
vars:
|
|
log_lines: 100
|
|
follow_logs: false
|
|
|
|
tasks:
|
|
- name: Validate service_name is provided
|
|
ansible.builtin.fail:
|
|
msg: "service_name variable is required. Use -e 'service_name=<name>'"
|
|
when: service_name is not defined
|
|
|
|
- name: Get service logs
|
|
ansible.builtin.command:
|
|
cmd: "docker compose logs --tail={{ log_lines }} {{ '--follow' if follow_logs else '' }}"
|
|
chdir: "{{ docker_data_path }}/{{ service_name }}"
|
|
register: logs_result
|
|
become: "{{ ansible_become | default(false) }}"
|
|
|
|
- name: Display logs
|
|
ansible.builtin.debug:
|
|
msg: "{{ logs_result.stdout }}"
|