add loki role
This commit is contained in:
48
roles/loki/tasks/configure.yaml
Normal file
48
roles/loki/tasks/configure.yaml
Normal file
@ -0,0 +1,48 @@
|
||||
---
|
||||
- name: create group
|
||||
group:
|
||||
name: "{{ loki_group }}"
|
||||
system: true
|
||||
state: "{{ loki_group_state | default('present') }}"
|
||||
|
||||
- name: create user
|
||||
user:
|
||||
name: "{{ loki_user }}"
|
||||
system: true
|
||||
shell: "{{ loki_user_shell }}"
|
||||
group: "{{ loki_group }}"
|
||||
createhome: false
|
||||
home: "{{ loki_var_path }}"
|
||||
state: "{{ loki_user_state | default('present') }}"
|
||||
|
||||
- name: configure
|
||||
template:
|
||||
src: loki.yaml.j2
|
||||
dest: "{{ loki_config_path }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0444
|
||||
notify: restart loki
|
||||
|
||||
- name: create var path
|
||||
file:
|
||||
path: "{{ loki_var_path }}"
|
||||
state: directory
|
||||
owner: "{{ loki_var_owner }}"
|
||||
group: "{{ loki_var_group }}"
|
||||
mode: "{{ loki_var_mode }}"
|
||||
|
||||
- name: configure systemd template
|
||||
template:
|
||||
src: "{{ loki_service_name }}.j2"
|
||||
dest: "/etc/systemd/system/{{ loki_service_name }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0444
|
||||
notify: restart loki
|
||||
|
||||
- name: manage service
|
||||
service:
|
||||
name: "{{ loki_service_name }}"
|
||||
enabled: "{{ loki_service_enabled }}"
|
||||
state: "{{ loki_service_state }}"
|
0
roles/loki/tasks/default.yaml
Normal file
0
roles/loki/tasks/default.yaml
Normal file
29
roles/loki/tasks/install.yaml
Normal file
29
roles/loki/tasks/install.yaml
Normal file
@ -0,0 +1,29 @@
|
||||
---
|
||||
- block:
|
||||
- name: download archive
|
||||
get_url:
|
||||
url: "{{ loki_release_url }}"
|
||||
dest: "{{ loki_download_path }}"
|
||||
checksum: "{{ loki_checksum }}"
|
||||
register: dl
|
||||
until: dl is success
|
||||
retries: 5
|
||||
delay: 10
|
||||
|
||||
- name: extract archive
|
||||
unarchive:
|
||||
src: "{{ loki_download_path }}"
|
||||
dest: "{{ loki_unarchive_dest_path }}"
|
||||
creates: "{{ loki_extracted_path }}/loki"
|
||||
remote_src: true
|
||||
|
||||
- name: install binaries
|
||||
copy:
|
||||
src: "{{ loki_extracted_path }}"
|
||||
dest: "{{ loki_bin_path }}/loki"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0755
|
||||
remote_src: true
|
||||
notify: restart loki
|
||||
when: loki_version != loki_local_version
|
30
roles/loki/tasks/main.yaml
Normal file
30
roles/loki/tasks/main.yaml
Normal file
@ -0,0 +1,30 @@
|
||||
---
|
||||
- name: gather os specific variables
|
||||
include_vars: "{{ lookup('first_found', possible_files) }}"
|
||||
vars:
|
||||
possible_files:
|
||||
files:
|
||||
- "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yaml"
|
||||
- "{{ ansible_distribution }}.yaml"
|
||||
- "{{ ansible_os_family }}.yaml"
|
||||
- "default.yaml"
|
||||
paths:
|
||||
- vars
|
||||
|
||||
- name: include os specific tasks
|
||||
include_tasks: "{{ lookup('first_found', possible_files) }}"
|
||||
vars:
|
||||
possible_files:
|
||||
files:
|
||||
- "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yaml"
|
||||
- "{{ ansible_distribution }}.yaml"
|
||||
- "{{ ansible_os_family }}.yaml"
|
||||
- "default.yaml"
|
||||
paths:
|
||||
- tasks
|
||||
|
||||
- include: pre.yaml
|
||||
|
||||
- include: install.yaml
|
||||
|
||||
- include: configure.yaml
|
50
roles/loki/tasks/pre.yaml
Normal file
50
roles/loki/tasks/pre.yaml
Normal file
@ -0,0 +1,50 @@
|
||||
---
|
||||
- name: determine if installed
|
||||
stat:
|
||||
path: "{{ loki_bin_path }}/loki"
|
||||
register: st
|
||||
|
||||
- name: set loki_installed
|
||||
set_fact:
|
||||
loki_installed: "{{ st.stat.exists | bool }}"
|
||||
|
||||
- block:
|
||||
- name: determine latest version
|
||||
uri:
|
||||
url: https://api.github.com/repos/grafana/loki/releases/latest
|
||||
return_content: true
|
||||
body_format: json
|
||||
register: _latest_version
|
||||
until: _latest_version.status == 200
|
||||
retries: 3
|
||||
|
||||
- name: set loki_version
|
||||
set_fact:
|
||||
loki_version: "{{ _latest_version.json['tag_name'] | regex_replace('^v', '') }}"
|
||||
|
||||
- block:
|
||||
- name: determine installed version
|
||||
command: "{{ loki_bin_path }}/loki --version"
|
||||
register: _installed_version_string
|
||||
changed_when: false
|
||||
|
||||
- name: set loki_local_version
|
||||
set_fact:
|
||||
loki_local_version: "{{ _installed_version_string.stdout | regex_search(loki_version_regex, '\\1') | first }}"
|
||||
when: loki_installed
|
||||
|
||||
- name: set loki_local_version to 0
|
||||
set_fact:
|
||||
loki_local_version: "0"
|
||||
when: not loki_installed
|
||||
|
||||
- block:
|
||||
- name: get checksums
|
||||
set_fact:
|
||||
_checksums: "{{ lookup('url', loki_checksum_url, wantlist=True) }}"
|
||||
|
||||
- name: set loki_checksum
|
||||
set_fact:
|
||||
loki_checksum: "sha256:{{ item.split(' ') | first }}"
|
||||
loop: "{{ _checksums }}"
|
||||
when: "loki_release_file in item"
|
Reference in New Issue
Block a user