role myInfora.docker.promtail added

This commit is contained in:
2025-09-14 15:06:21 +00:00
parent 12f2c73ff7
commit 3294c0dd61
3 changed files with 158 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
galaxy_info:
author: mf
description: promtail docker role
company: limbosolutions
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []

View File

@@ -0,0 +1,93 @@
---
- name: Check folders
become: true
ansible.builtin.file:
path: "{{ config_file.host_path }}"
state: directory
mode: '0755'
- name: Setup config File
become: true
ansible.builtin.copy:
dest: "{{ config_file.host_path }}/config.yaml"
mode: '0644'
content: |
# file maintained by myLimbo.docker.promtail ansible role
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /data/positions.yaml
clients:
- url: {{loki.url}}
scrape_configs:
{% if scrape.host_log_files.enabled == true %}
- job_name: varlog
static_configs:
- targets:
- localhost
labels:
job: varlog
host: "{{ labels.host }}"
__path__: /var/log/*log
{% endif %}
- job_name: journald
journal:
json: true
max_age: 12h
path: /var/log/journal
# matches: _TRANSPORT=kernel
labels:
job: journald
host: "{{ labels.host }}"
relabel_configs:
- source_labels: ['__journal__systemd_unit']
target_label: 'journal_systemd_unit'
- source_labels: ['__journal_syslog_identifier']
target_label: 'journal_syslog_identifier'
- source_labels: ['__journal__hostname']
target_label: 'journal_hostname'
pipeline_stages:
- match:
selector: '{journal_systemd_unit="docker.service"}'
stages:
- json:
expressions:
container_name: CONTAINER_NAME
- labels:
container_name:
{% if scrape.docker.enabled == true %}
- job_name: docker
docker_sd_configs:
- host: unix:///var/run/docker.sock
refresh_interval: 5s
pipeline_stages:
- static_labels:
job: "docker"
host: "{{ labels.host }}"
relabel_configs:
- source_labels: ['container_name']
target_label: "container_name"
{% endif %}
- name: Docker Container Setup
become: true
community.docker.docker_container:
name: promtail
image: grafana/promtail:latest
state: started
restart_policy: unless-stopped
pull: yes
command: -config.file=/mnt/config/config.yaml -config.expand-env=true
volumes:
- "{{ config_file.host_path }}:/mnt/config"
- promtail-data:/data
- /var/log:/var/log
- /var/log/journal/:/var/log/journal
- /run/log/journal/:/run/log/journal
- /etc/machine-id:/etc/machine-id
- /var/run/docker.sock:/var/run/docker.sock

View File

@@ -0,0 +1,12 @@
---
config_file:
host_path: /etc/myLimbo/docker-promtail
loki:
url: http://loki.lan
scrape:
labels:
host: "$HOSTNAME"
docker:
enabled: false
host_log_files:
enabled: false