Deploy promtail using ansible. Supports amd64 and arm architectures. For recent changes, please check the CHANGELOG or have a look at github releases
- Ansible >= 2.7
All variables which can be overridden are stored in defaults/main.yml file as well as in table below.
Name | Default Value | Description |
---|---|---|
promtail_version |
"3.0.0" | promtail package version. Also accepts latest as parameter. |
promtail_custom_checksum |
"" | Custom checksum for custom build promtail binaries |
promtail_binary_local_dir |
"" | Allows to use local packages instead of ones distributed on github. As parameter it takes the path where zip archive of promtail is stored on host on which ansible is ran. |
promtail_extra_args |
[] | Allows to set extra arguments to the binary within the systemd service file. |
promtail_config_dir |
/etc/promtail | Directory for storing promtail configuration file |
promtail_config_expand_env |
"false" | value of promtail -config.expand-env option |
promtail_config_file_sd_dir |
"{{ promtail_config_dir }}/file_sd" | Default directory for file_sd discovery |
promtail_config_file |
"{{ promtail_config_dir }}/promtail.yml" | Configuration file used by promtail |
promtail_system_user |
promtail | User the promtail process will run at |
promtail_system_group |
"{{ promtail_system_user }}" | Group of the promtail user |
promtail_user_additional_groups |
"adm" | Additional groups to be added to promtail user to give access to allow scraping of specific log files |
promtail_config_clients |
see defaults/main.yml | promtail clients section |
promtail_loki_server_url |
http://127.0.0.1:3100 | Server url where promtail will push its result |
promtail_config_server |
see defaults/main.yml | promtail server section |
promtail_positions_directory |
/var/lib/promtail |
Path to the directory where promtail tracks scraped log positons |
promtail_config_positions |
{"filename": "{{ promtail_positions_directory }}/positions.yml"} | promtail positions section |
promtail_config_scrape_configs |
[] | promtail scrape_configs section |
promtail_target_config |
{} | promtail target_config section |
promtail_log_level |
"info" | Loglevel of promtail (one of: debug ,info ,warn ,error ) |
promtail_config_include_default_file_sd_config |
"True" | When set to false, the default file_sd will not be provisioned |
promtail_apt_update_cache |
"True" | When set to false the role will not update the APT cache on its own |
For each section (promtail_config_clients
, promtail_config_server
,promtail_config_positions
,promtail_config_scrape_configs
,promtail_target_config
) the configuration can be passed accrodingly to the official promtail configuration.
The role will converte the ansible vars into the respective yaml configuration for loki.
Basic playbook that will assume that loki will be listening at http://127.0.0.1:3100
and a simple configuration to scrape /var/log
logs:
---
- hosts: all
roles:
- role: patrickjahns.promtail
vars:
promtail_config_scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: varlogs
__path__: /var/log/*log
A more complex example, that overrides server, client, positions configuration and provides a scrap configuration for /var/log
:
---
- hosts: all
roles:
- role: patrickjahns.promtail
vars:
promtail_config_server:
http_listen_port: 9080
grpc_listen_port: 9081
promtail_config_clients:
- url: "http://prometheus.domain.tld:3100/loki/api/v1/push"
external_labels:
host: "{{ ansible_hostname }}"
promtail_config_positions:
filename: "{{ promtail_positions_directory }}/positions.yaml"
sync_period: "60s"
promtail_config_scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: varlogs
__path__: /var/log/*log
The preferred way of locally testing the role is to use Docker and molecule (v3.x). You will have to install Docker on your system. See "Get started" for a Docker package suitable to for your system. We are using tox to simplify process of testing on multiple ansible versions. To install tox execute:
pip3 install tox
To run tests on all ansible versions (WARNING: this can take some time)
tox
To run a custom molecule command on custom environment with only default test scenario:
tox -e ansible29 -- molecule test -s default
For more information about molecule go to their docs.
If you would like to run tests on remote docker host just specify DOCKER_HOST
variable before running tox tests.
Github actions is used to test and validate this ansible role via ansible-later and molecule. Molecule tests will run with several operation systems as well as ansible version in order to ensure compatability.
This project is licensed under MIT License. See LICENSE for more details.