--- - 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