2020-04-19 22:28:06 +02:00
|
|
|
---
|
2023-05-20 15:28:15 +02:00
|
|
|
- name: Create system group {{ loki_group }}
|
|
|
|
ansible.builtin.group:
|
2020-04-19 22:28:06 +02:00
|
|
|
name: "{{ loki_group }}"
|
|
|
|
system: true
|
|
|
|
state: present
|
|
|
|
|
2023-05-20 15:28:15 +02:00
|
|
|
- name: Create system user {{ loki_user }}
|
|
|
|
ansible.builtin.user:
|
2020-04-19 22:28:06 +02:00
|
|
|
name: "{{ loki_user }}"
|
|
|
|
system: true
|
|
|
|
shell: "/usr/sbin/nologin"
|
|
|
|
group: "{{ loki_group }}"
|
|
|
|
createhome: false
|
2020-04-20 02:21:00 +02:00
|
|
|
home: "{{ loki_storage_dir }}"
|
2020-04-19 22:28:06 +02:00
|
|
|
|
2023-05-20 15:28:15 +02:00
|
|
|
- name: Create loki data directory
|
|
|
|
ansible.builtin.file:
|
2020-04-20 02:21:00 +02:00
|
|
|
path: "{{ item }}"
|
|
|
|
state: directory
|
|
|
|
owner: loki
|
|
|
|
group: loki
|
2023-05-20 15:28:15 +02:00
|
|
|
mode: "0755"
|
2020-04-20 02:21:00 +02:00
|
|
|
with_items:
|
|
|
|
- "{{ loki_storage_dir }}"
|
|
|
|
- "{{ loki_storage_dir }}/index"
|
|
|
|
- "{{ loki_storage_dir }}/chunks"
|
2020-04-22 00:54:44 +02:00
|
|
|
when: ('loki' in loki_bins)
|
2020-04-19 22:28:06 +02:00
|
|
|
|
2023-05-23 19:02:58 +02:00
|
|
|
- name: Create Bin directories
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "/opt/loki"
|
|
|
|
state: directory
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: "0755"
|
|
|
|
|
2021-12-17 12:22:43 +01:00
|
|
|
- name: Create loki configuration directories
|
2023-05-20 15:28:15 +02:00
|
|
|
ansible.builtin.file:
|
2020-04-19 22:28:06 +02:00
|
|
|
path: "{{ item }}"
|
|
|
|
state: directory
|
|
|
|
owner: root
|
|
|
|
group: "{{ loki_group }}"
|
2023-05-20 15:28:15 +02:00
|
|
|
mode: "0770"
|
2020-04-19 22:28:06 +02:00
|
|
|
with_items:
|
|
|
|
- "{{ loki_config_dir }}"
|
|
|
|
|
2023-05-23 19:02:58 +02:00
|
|
|
- name: Install bin
|
2023-05-20 15:28:15 +02:00
|
|
|
block:
|
2021-12-17 12:22:43 +01:00
|
|
|
- name: Unpack binaries
|
2023-05-20 15:28:15 +02:00
|
|
|
ansible.builtin.unarchive:
|
2022-01-16 13:19:08 +01:00
|
|
|
remote_src: true
|
2023-05-20 15:28:15 +02:00
|
|
|
src: "https://github.com/grafana/loki/releases/download/v{{ loki_version }}/{{ item }}-linux-{{ go_arch }}.zip"
|
2023-05-23 19:02:58 +02:00
|
|
|
dest: "/opt/loki/"
|
2023-05-20 15:28:15 +02:00
|
|
|
mode: "0755"
|
2020-04-19 22:28:06 +02:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
loop: "{{ loki_bins }}"
|
|
|
|
notify:
|
|
|
|
- restart loki
|
2022-01-16 14:01:32 +01:00
|
|
|
|
2023-05-23 19:02:58 +02:00
|
|
|
- name: Create bin symlink
|
2023-05-20 15:28:15 +02:00
|
|
|
ansible.builtin.file:
|
2023-05-23 19:02:58 +02:00
|
|
|
src: "/opt/loki/{{ item }}-linux-{{ go_arch }}"
|
|
|
|
dest: "/usr/local/bin/{{ item }}"
|
|
|
|
state: link
|
2022-01-16 14:01:32 +01:00
|
|
|
loop: "{{ loki_bins }}"
|
2023-05-23 19:02:58 +02:00
|
|
|
notify:
|
|
|
|
- restart loki
|
2020-04-19 22:28:06 +02:00
|
|
|
|
2021-12-17 12:22:43 +01:00
|
|
|
- name: Create systemd service unit
|
2023-05-20 15:28:15 +02:00
|
|
|
ansible.builtin.template:
|
2020-04-20 18:03:35 +02:00
|
|
|
src: "{{ item }}.service.j2"
|
|
|
|
dest: "/etc/systemd/system/{{ item }}.service"
|
2020-04-19 22:28:06 +02:00
|
|
|
owner: root
|
|
|
|
group: root
|
2023-05-20 15:28:15 +02:00
|
|
|
mode: "0644"
|
2020-04-20 18:03:35 +02:00
|
|
|
notify: "restart {{ item }}"
|
2020-04-19 22:28:06 +02:00
|
|
|
loop: "{{ loki_bins }}"
|
2020-04-20 18:03:35 +02:00
|
|
|
when: item == 'loki' or item == 'promtail'
|
2022-01-16 14:01:32 +01:00
|
|
|
|
|
|
|
- name: Find temps files to del
|
2023-05-20 15:28:15 +02:00
|
|
|
ansible.builtin.find:
|
2022-01-16 14:01:32 +01:00
|
|
|
paths: /tmp
|
|
|
|
file_type: file
|
2022-03-04 14:43:35 +01:00
|
|
|
patterns: "loki-*-linux-{{ go_arch }}.zip,promtail-*-linux-{{ go_arch }}.zip"
|
|
|
|
excludes: "loki-{{ loki_version }}-linux-{{ go_arch }}.zip,promtail-{{ loki_version }}-linux-{{ go_arch }}.zip"
|
2022-01-16 14:01:32 +01:00
|
|
|
register: to_del
|
|
|
|
|
|
|
|
- name: Clean temp files
|
2023-05-20 15:28:15 +02:00
|
|
|
ansible.builtin.file:
|
2022-01-16 14:01:32 +01:00
|
|
|
path: "{{ item.path }}"
|
|
|
|
state: absent
|
|
|
|
loop: "{{ to_del.files }}"
|