Merge pull request #68 from corvus-migratorius/fix-promtail

Fix the promtail deployment role
This commit is contained in:
Alexander Gorelyshev
2025-12-26 23:29:14 +04:00
committed by GitHub
10 changed files with 31 additions and 41 deletions

View File

@@ -10,11 +10,12 @@ Role Variables
--------------
(all optional)
`promtail_version`: version to install
`promtail_loki_server`: set loki server
`promtail_loki_port`: set loki port
`custom_server_config`: path to custom config witch replace all config with your own
`custom_scrape_configs`: path to custom scrape configs
- `promtail_version`: Promtail version to install
- `promtail_loki_server`: address of the Loki server
- `promtail_loki_port`: Loki listening port
- `promtail_positions_path`: a YAML file containing last scraped positions in the logs (default: `/var/lib/promtail/positions.yaml`)
- `promtail_custom_scrape_configs`: additional `scrape_configs` configuration
- `promtail_add_var_logs`: scrape the entire `/var/logs` directory (default: `true`)
Dependencies
------------

View File

@@ -1,7 +1,6 @@
---
promtail_version: 2.7.3
promtail_positions_path: /home/promtail/positions.yaml
promtail_version: 3.6.3
promtail_positions_path: /var/lib/promtail/positions.yaml
promtail_http_port: 9080
promtail_loki_server: localhost
promtail_loki_port: 3100
promtail_add_var_logs: true

View File

@@ -1,11 +1,7 @@
---
- name: "Restart the Promtail daemon"
- name: "Enable and restart the Promtail daemon"
ansible.builtin.systemd:
name: promtail
state: restarted
- name: "Reload the Promtail daemon configuration"
ansible.builtin.systemd:
enabled: true
daemon_reload: true

View File

@@ -2,7 +2,7 @@ galaxy_info:
role_name: promtail
namespace: genlab
author: Danilkin Danila
description: Installs Promtail
description: Deploy Promtail
company: Genlab LLC
license: MIT

View File

@@ -3,3 +3,5 @@
hosts: all
roles:
- role: genlab.common.promtail
promtail_version: 3.6.3
promtail_loki_server: localhost # required, but doesn't do anything in these tests

View File

@@ -5,7 +5,7 @@ driver:
name: docker
platforms:
- name: ubuntu
image: geerlingguy/docker-ubuntu2204-ansible:latest
image: geerlingguy/docker-ubuntu2404-ansible:latest
pre_build_image: true
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:

View File

@@ -9,7 +9,7 @@
dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults/"
extensions: ['yml']
# kics-scan ignore-block - kics doesn't like http but it's localhost so it's not important
# kics-scan ignore-block - kics doesn't like HTTP but on localhost it's not important
- name: "Sanity check the Promtail daemon"
retries: 3
delay: 1

View File

@@ -7,19 +7,14 @@
cache_valid_time: 3600
- name: "Create the 'promtail' group"
ansible.builtin.group:
name: promtail
state: present
- name: "Create the 'promtail' user"
ansible.builtin.user:
name: promtail
groups:
- promtail
- systemd-journal
- adm
- systemd-journal
shell: /bin/false
home: /var/lib/promtail
state: present
system: true
@@ -51,7 +46,6 @@
changed_when: false
- name: "Assert version correctness"
notify: "Restart the Promtail daemon"
ansible.builtin.assert:
that: "promtail_version in promtail_version_check.stdout"
success_msg: "Expected Promtail version available ({{ promtail_version }})"
@@ -59,6 +53,7 @@
rescue:
- name: "Install Promtail if its not present"
notify: "Enable and restart the Promtail daemon"
ansible.builtin.unarchive:
src: "https://github.com/grafana/loki/releases/download/v\
{{ promtail_version }}/promtail-linux-amd64.zip"
@@ -81,7 +76,7 @@
- name: "Template the systemd unit file"
notify: "Reload the Promtail daemon configuration"
notify: "Enable and restart the Promtail daemon"
ansible.builtin.template:
src: promtail.service.j2
dest: /etc/systemd/system/promtail.service
@@ -89,19 +84,19 @@
group: root
mode: "0644"
- name: "Ensure '/etc/promtail' exists"
ansible.builtin.file:
path: /etc/promtail
state: directory
owner: promtail
group: promtail
mode: "0755"
- name: "Template Promtail config file"
notify: "Restart the Promtail daemon"
notify: "Enable and restart the Promtail daemon"
ansible.builtin.template:
src: templates/promtail.yml.j2
dest: /usr/local/bin/config-promtail.yml
dest: /etc/promtail/config.yml
owner: root
group: root
mode: "0644"
- name: "Enable and start Promtail daemon"
ansible.builtin.systemd:
name: promtail
state: started
enabled: true

View File

@@ -5,7 +5,7 @@ After=network.target
[Service]
Type=simple
User=promtail
ExecStart=/usr/bin/promtail -config.file /usr/local/bin/config-promtail.yml
ExecStart=/usr/bin/promtail -config.file /etc/promtail/config.yml
[Install]
WantedBy=multi-user.target

View File

@@ -1,10 +1,7 @@
{% if custom_server_config is defined %}
{{ custom_server_config }}
{% else %}
---
server:
http_listen_port: {{ promtail_http_port }}
grpc_listen_port: 0
{% endif %}
positions:
filename: {{ promtail_positions_path }}