olimp/roles/promtail/tasks/main.yml
Administrator 1a38a968a4 Update 2 files
- /roles/promtail/tasks/main.yml
- /roles/promtail/templates/promtail-config.yml.j2
2025-11-21 16:34:09 +00:00

102 lines
2.3 KiB
YAML

---
- name: Create Promtail directories
file:
path: "{{ item }}"
state: directory
mode: '0755'
loop:
- "{{ promtail_config_dir }}"
- "{{ promtail_data_dir }}"
become: yes
- name: Set proper permissions for Promtail data directory
file:
path: "{{ promtail_data_dir }}"
state: directory
owner: promtail
group: promtail
mode: '0755'
recurse: yes
become: yes
- name: Add promtail user to adm group for system log access
user:
name: promtail
groups: adm
append: yes
become: yes
- name: Download Promtail binary
get_url:
url: "https://github.com/grafana/loki/releases/download/v{{ loki_version }}/promtail-linux-amd64.zip"
dest: /tmp/promtail-linux-amd64.zip
mode: '0644'
timeout: 60
become: yes
- name: Install Promtail binary
unarchive:
src: /tmp/promtail-linux-amd64.zip
dest: /usr/local/bin/
remote_src: yes
owner: root
group: root
mode: '0755'
become: yes
- name: Create Promtail system user
user:
name: promtail
system: yes
shell: /usr/sbin/nologin
create_home: no
become: yes
- name: Deploy Promtail configuration
template:
src: promtail-config.yml.j2
dest: "{{ promtail_config_dir }}/promtail-config.yml"
mode: '0644'
notify: restart promtail
become: yes
- name: Deploy Promtail systemd service (as root)
copy:
content: |
[Unit]
Description=Promtail log collector
Documentation=https://grafana.com/docs/loki/latest/clients/promtail/
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/bin/promtail-linux-amd64 \
-config.file={{ promtail_config_dir }}/promtail-config.yml
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
dest: /etc/systemd/system/promtail.service
mode: '0644'
notify: restart promtail
become: yes
- name: Start and enable Promtail service
systemd:
name: promtail
state: started
enabled: yes
daemon_reload: yes
become: yes
- name: Clean up temporary files
file:
path: /tmp/promtail-linux-amd64.zip
state: absent
become: yes