ansible-loki-role/tasks/install.yml

83 lines
2.0 KiB
YAML
Raw Normal View History

2020-04-19 22:28:06 +02:00
---
- 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
2020-04-20 02:21:00 +02:00
home: "{{ loki_storage_dir }}"
2020-04-19 22:28:06 +02:00
2020-04-20 02:21:00 +02:00
- 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"
2020-04-22 00:54:44 +02:00
when: ('loki' in loki_bins)
2020-04-19 22:28:06 +02:00
2021-12-17 12:22:43 +01:00
- name: Create loki configuration directories
2020-04-19 22:28:06 +02:00
file:
path: "{{ item }}"
state: directory
owner: root
group: "{{ loki_group }}"
mode: 0770
with_items:
- "{{ loki_config_dir }}"
- block:
2021-12-17 12:22:43 +01:00
- name: Download binaries
2020-04-19 22:28:06 +02:00
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 }}"
2020-05-04 23:48:42 +02:00
check_mode: false
2020-04-19 22:28:06 +02:00
2021-12-17 12:22:43 +01:00
- name: Unpack binaries
2020-04-19 22:28:06 +02:00
unarchive:
src: "/tmp/{{ item }}-{{ loki_version }}-linux-{{ go_arch }}.zip"
dest: "/tmp"
loop: "{{ loki_bins }}"
2020-05-04 23:48:42 +02:00
check_mode: false
2020-04-19 22:28:06 +02:00
2021-12-17 12:22:43 +01:00
- name: Copy binaries
2020-04-19 22:28:06 +02:00
copy:
src: "/tmp/{{ item }}-linux-{{ go_arch }}"
dest: "/usr/local/bin/{{ item }}"
mode: 0755
owner: root
group: root
2021-12-17 12:22:43 +01:00
remote_src: true
2020-04-19 22:28:06 +02:00
loop: "{{ loki_bins }}"
notify:
- restart loki
2021-12-17 12:22:43 +01:00
- name: Create systemd service unit
2020-04-19 22:28:06 +02:00
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
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'