Files
gitlab-mirror/roles/promtail/tasks/main.yml
2025-12-26 22:30:14 +04:00

103 lines
2.7 KiB
YAML

---
- name: "Install packages"
ansible.builtin.apt:
name: [acl, unzip]
state: present
update_cache: true
cache_valid_time: 3600
- name: "Create the 'promtail' user"
ansible.builtin.user:
name: promtail
groups:
- adm
- systemd-journal
shell: /bin/false
home: /var/lib/promtail
state: present
system: true
- name: "Set facl to allow promtail user to read '/var/log' contents"
ansible.posix.acl:
path: /var/log
entity: promtail
etype: user
permissions: rX
state: present
- name: "Make promtail user owner of '{{ promtail_positions_path }}'"
changed_when: false
ansible.builtin.file:
path: "{{ promtail_positions_path }}"
owner: promtail
group: promtail
state: touch
mode: "0750"
- name: "Install the requested Promtail version"
block:
- name: "Check Promtail version"
ansible.builtin.command: /usr/bin/promtail --version
register: promtail_version_check
changed_when: false
- name: "Assert version correctness"
ansible.builtin.assert:
that: "promtail_version in promtail_version_check.stdout"
success_msg: "Expected Promtail version available ({{ promtail_version }})"
fail_msg: "Expected version '{{ promtail_version }}'; available is '{{ promtail_version_check.stdout }}'"
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"
dest: /usr/bin/
remote_src: true
- name: "Rename and set permissions for the Promtail binary"
ansible.builtin.copy:
src: "/usr/bin/promtail-linux-amd64"
dest: "/usr/bin/promtail"
owner: root
group: root
mode: "0755"
remote_src: true
- name: "Cleanup the downloaded file"
ansible.builtin.file:
path: "/usr/bin/promtail-linux-amd64"
state: absent
- name: "Template the systemd unit file"
notify: "Enable and restart the Promtail daemon"
ansible.builtin.template:
src: promtail.service.j2
dest: /etc/systemd/system/promtail.service
owner: root
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: "Enable and restart the Promtail daemon"
ansible.builtin.template:
src: templates/promtail.yml.j2
dest: /etc/promtail/config.yml
owner: root
group: root
mode: "0644"