ansible-loki-role/tasks/install.yml
2022-03-04 14:43:35 +01:00

106 lines
2.7 KiB
YAML

---
- name: create {{ loki_group }} system group
group:
name: "{{ loki_group }}"
system: true
state: present
- name: create {{ loki_user }} system user
user:
name: "{{ loki_user }}"
system: true
shell: "/usr/sbin/nologin"
group: "{{ loki_group }}"
createhome: false
home: "{{ loki_storage_dir }}"
- name: create loki data directory
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 loki configuration directories
file:
path: "{{ item }}"
state: directory
owner: root
group: "{{ loki_group }}"
mode: 0770
with_items:
- "{{ loki_config_dir }}"
- block:
- name: Download binaries
get_url:
url: "https://github.com/grafana/loki/releases/download/v{{ loki_version }}/{{ item }}-linux-{{ go_arch }}.zip"
dest: "/tmp/{{ item }}-{{ loki_version }}-linux-{{ go_arch }}.zip"
checksum: "sha256:{{ __loki_bins_checksum[item] }}"
register: _download_archive
until: _download_archive is succeeded
retries: 5
delay: 2
loop: "{{ loki_bins }}"
check_mode: false
- name: Unpack binaries
unarchive:
remote_src: true
src: "/tmp/{{ item }}-{{ loki_version }}-linux-{{ go_arch }}.zip"
dest: "/tmp"
loop: "{{ loki_bins }}"
check_mode: false
when: _download_archive is changed
- name: Copy binaries
copy:
src: "/tmp/{{ item }}-linux-{{ go_arch }}"
dest: "/usr/local/bin/{{ item }}"
mode: 0755
owner: root
group: root
remote_src: true
loop: "{{ loki_bins }}"
notify:
- restart loki
when: _download_archive is changed
- name: Clean binaries
file:
path: "/tmp/{{ item }}-linux-{{ go_arch }}"
state: absent
loop: "{{ loki_bins }}"
when: _download_archive is changed
- name: Create systemd service unit
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
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
file:
path: "{{ item.path }}"
state: absent
loop: "{{ to_del.files }}"