Install the latest promtail version with ansible.
Have a look at the defaults to see what variables you can set.
If your loki instance does not run on the same host, you should set loki_host
to the corresponding ip.
For promtail, as an example config, you can turn on two jobs as an example config by setting either one of promtail_job_journal
or promtail_job_nginx
to true
.
In most cases, however, you would probably want to provide your own config-templates for loki and promtail.
You can achieve this by changing the path to the template file in promtail_config_template
.
Make sure that promtail has reading rights on the corresponding log files.
Per default the promtail user will be added to the adm
group that can read logs.
If you want to change this behavior set make_varlog_accessible
to false
.
You can also add the user to arbitrary other groups by specifying additional_groups
as a list.
Your playbook might look like this:
---
- hosts: all
become: true
roles:
- role: elan.monitoring_promtail
promtail_config_template: 'my_templates/promtail_config.yml.j2'
promtail_use_tls: true
In this case you would have a configuration template for promtail that is located in a folder my_templates
relative to the playbook.
Or, if you want to use the pre-installed template, it could look something like this:
---
- hosts: all
become: true
roles:
- role: elan.monitoring_promtail
loki_host: your-loki.your-domain.com
use_basic_auth: true
basic_auth_user: loki
basic_auth_password: 1234
promtail_job_journal: true
promtail_job_nginx: true
For development and testing you can use molecule. With podman as driver you can install it like this – preferably in a virtual environment:
pip install -r .dev_requirements.txt
Then you can create the test instances, apply the ansible config (converge) and destroy the test instances with these commands:
molecule create
molecule converge
molecule destroy
If you want to inspect a running test instance use molecule login --host <instance_name>
, where you replace <instance_name>
with the desired value.
The prepare.yml-file will also install loki in the same container, so that promtail can be tested against a local installation of loki.