95 lines
2.4 KiB
YAML
95 lines
2.4 KiB
YAML
---
|
|
- name: Create system group {{ loki_group }}
|
|
ansible.builtin.group:
|
|
name: "{{ loki_group }}"
|
|
system: true
|
|
state: present
|
|
|
|
- name: Create system user {{ loki_user }}
|
|
ansible.builtin.user:
|
|
name: "{{ loki_user }}"
|
|
system: true
|
|
shell: "/usr/sbin/nologin"
|
|
group: "{{ loki_group }}"
|
|
createhome: false
|
|
home: "{{ loki_storage_dir }}"
|
|
|
|
- name: Create loki data directory
|
|
ansible.builtin.file:
|
|
path: "{{ item }}"
|
|
state: directory
|
|
owner: loki
|
|
group: loki
|
|
mode: "0755"
|
|
with_items:
|
|
- "{{ loki_storage_dir }}"
|
|
- "{{ loki_storage_dir }}/index"
|
|
- "{{ loki_storage_dir }}/chunks"
|
|
when: ('loki' in loki_bins)
|
|
|
|
- name: Create Bin directories
|
|
ansible.builtin.file:
|
|
path: "/opt/loki"
|
|
state: directory
|
|
owner: root
|
|
group: root
|
|
mode: "0755"
|
|
|
|
- name: Create loki configuration directories
|
|
ansible.builtin.file:
|
|
path: "{{ item }}"
|
|
state: directory
|
|
owner: root
|
|
group: "{{ loki_group }}"
|
|
mode: "0770"
|
|
with_items:
|
|
- "{{ loki_config_dir }}"
|
|
|
|
- name: Install bin
|
|
block:
|
|
- name: Unpack binaries
|
|
ansible.builtin.unarchive:
|
|
remote_src: true
|
|
src: "https://github.com/grafana/loki/releases/download/v{{ loki_version }}/{{ item }}-linux-{{ go_arch }}.zip"
|
|
dest: "/opt/loki/"
|
|
mode: "0755"
|
|
owner: root
|
|
group: root
|
|
loop: "{{ loki_bins }}"
|
|
notify:
|
|
- restart loki
|
|
|
|
- name: Create bin symlink
|
|
ansible.builtin.file:
|
|
src: "/opt/loki/{{ item }}-linux-{{ go_arch }}"
|
|
dest: "/usr/local/bin/{{ item }}"
|
|
state: link
|
|
loop: "{{ loki_bins }}"
|
|
notify:
|
|
- restart loki
|
|
|
|
- name: Create systemd service unit
|
|
ansible.builtin.template:
|
|
src: "{{ item }}.service.j2"
|
|
dest: "/etc/systemd/system/{{ item }}.service"
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
notify: "restart {{ item }}"
|
|
loop: "{{ loki_bins }}"
|
|
when: item == 'loki' or item == 'promtail'
|
|
|
|
- name: Find temps files to del
|
|
ansible.builtin.find:
|
|
paths: /tmp
|
|
file_type: file
|
|
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"
|
|
register: to_del
|
|
|
|
- name: Clean temp files
|
|
ansible.builtin.file:
|
|
path: "{{ item.path }}"
|
|
state: absent
|
|
loop: "{{ to_del.files }}"
|