initial commit
This commit is contained in:
commit
fba33111d7
13
LICENSE
Normal file
13
LICENSE
Normal file
@ -0,0 +1,13 @@
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2004 Diogenes Pelisson <diogenes.pelisson@gmail.com>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
33
README.md
Normal file
33
README.md
Normal file
@ -0,0 +1,33 @@
|
||||
Role Name
|
||||
=========
|
||||
|
||||
Deploy and configure [Loki/Promtail](https://github.com/grafana/loki) using Ansible.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
- Ansible >= 2.9
|
||||
|
||||
Role Variables
|
||||
--------------
|
||||
|
||||
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
|
||||
|
||||
Example Playbook
|
||||
----------------
|
||||
|
||||
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
|
||||
|
||||
- hosts: servers
|
||||
roles:
|
||||
- { role: username.rolename, x: 42 }
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
WTFPL see [LICENSE](license)
|
||||
|
||||
Author Information
|
||||
------------------
|
||||
|
||||
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
|
36
defaults/main.yml
Normal file
36
defaults/main.yml
Normal file
@ -0,0 +1,36 @@
|
||||
---
|
||||
# loki version to install
|
||||
loki_version: 'latest'
|
||||
|
||||
# loki bins to install
|
||||
loki_bins:
|
||||
- loki
|
||||
- logcli
|
||||
- promtail
|
||||
|
||||
loki_user: loki
|
||||
loki_group: loki
|
||||
loki_config_dir: /etc/loki
|
||||
|
||||
loki_binary_local_dir: ''
|
||||
|
||||
loki_target: all
|
||||
loki_auth_enabled: true
|
||||
|
||||
loki_server_config:
|
||||
http_listen_address: 0.0.0.0
|
||||
http_listen_port: 80
|
||||
grpc_listen_address: 0.0.0.0
|
||||
grpc_listen_port: 9095
|
||||
|
||||
loki_distributor_config: []
|
||||
loki_querier_config: []
|
||||
loki_ingester_client_config: []
|
||||
loki_ingester_config: []
|
||||
loki_storage_config: []
|
||||
loki_chunk_store_config: []
|
||||
loki_schema_config: []
|
||||
loki_limits_config: []
|
||||
loki_frontend_worker_config: []
|
||||
loki_table_manager_config: []
|
||||
loki_runtime_config: []
|
13
handlers/main.yml
Normal file
13
handlers/main.yml
Normal file
@ -0,0 +1,13 @@
|
||||
---
|
||||
- name: restart loki
|
||||
become: true
|
||||
systemd:
|
||||
daemon_reload: true
|
||||
name: loki
|
||||
state: restarted
|
||||
|
||||
- name: reload loki
|
||||
become: true
|
||||
systemd:
|
||||
name: loki
|
||||
state: reloaded
|
25
meta/main.yml
Normal file
25
meta/main.yml
Normal file
@ -0,0 +1,25 @@
|
||||
galaxy_info:
|
||||
author: Diogenes Pelisson
|
||||
description: Deploy and configure Loki and Promtail.
|
||||
company: none
|
||||
issue_tracker_url: https://github.com/diogenxs/ansible-role-loki/issues
|
||||
license: WTFPL
|
||||
min_ansible_version: 2.9
|
||||
platforms:
|
||||
- name: Ubuntu
|
||||
versions:
|
||||
- bionic
|
||||
- xenial
|
||||
- name: Debian
|
||||
versions:
|
||||
- stretch
|
||||
- buster
|
||||
galaxy_tags:
|
||||
- loki
|
||||
- promtail
|
||||
- logging
|
||||
- collector
|
||||
- monitoring
|
||||
- grafana
|
||||
- prometheus
|
||||
dependencies: []
|
80
tasks/install.yml
Normal file
80
tasks/install.yml
Normal file
@ -0,0 +1,80 @@
|
||||
---
|
||||
- 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_db_dir }}"
|
||||
|
||||
# - name: create loki data directory
|
||||
# file:
|
||||
# path: "{{ loki_db_dir }}"
|
||||
# state: directory
|
||||
# owner: loki
|
||||
# group: loki
|
||||
# mode: 0755
|
||||
|
||||
- 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 to local folder
|
||||
become: false
|
||||
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 }}"
|
||||
|
||||
- name: unpack binaries
|
||||
become: false
|
||||
unarchive:
|
||||
src: "/tmp/{{ item }}-{{ loki_version }}-linux-{{ go_arch }}.zip"
|
||||
dest: "/tmp"
|
||||
creates: "/tmp/{{ item }}-{{ loki_version }}-linux-{{ go_arch }}"
|
||||
loop: "{{ loki_bins }}"
|
||||
|
||||
- name: propagate official binaries
|
||||
copy:
|
||||
src: "/tmp/{{ item }}-linux-{{ go_arch }}"
|
||||
dest: "/usr/local/bin/{{ item }}"
|
||||
mode: 0755
|
||||
owner: root
|
||||
group: root
|
||||
loop: "{{ loki_bins }}"
|
||||
notify:
|
||||
- restart loki
|
||||
|
||||
- name: create systemd service unit
|
||||
template:
|
||||
src: loki.service.j2
|
||||
dest: /etc/systemd/system/loki.service
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
notify:
|
||||
- restart loki
|
||||
loop: "{{ loki_bins }}"
|
||||
when:
|
||||
- item == 'loki' or
|
||||
- item == 'loki-canary' or
|
||||
- item == 'promtail'
|
5
tasks/main.yml
Normal file
5
tasks/main.yml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
- include: preflight.yml
|
||||
|
||||
- include: install.yml
|
||||
become: true
|
44
tasks/preflight.yml
Normal file
44
tasks/preflight.yml
Normal file
@ -0,0 +1,44 @@
|
||||
---
|
||||
# - name: Assert usage of systemd as an init system
|
||||
# assert:
|
||||
# that: ansible_service_mgr == 'systemd'
|
||||
# msg: "This module only works with systemd"
|
||||
|
||||
- block:
|
||||
- name: Get latest release
|
||||
uri:
|
||||
url: "https://api.github.com/repos/grafana/loki/releases/latest"
|
||||
method: GET
|
||||
return_content: true
|
||||
status_code: 200
|
||||
body_format: json
|
||||
validate_certs: false
|
||||
user: "{{ lookup('env', 'GH_USER') | default(omit) }}"
|
||||
password: "{{ lookup('env', 'GH_TOKEN') | default(omit) }}"
|
||||
no_log: "{{ not lookup('env', 'ANSIBLE_DEBUG') | bool }}"
|
||||
register: _latest_release
|
||||
until: _latest_release.status == 200
|
||||
retries: 5
|
||||
|
||||
- name: "Set loki version to {{ _latest_release.json.tag_name[1:] }}"
|
||||
set_fact:
|
||||
loki_version: "{{ _latest_release.json.tag_name[1:] }}"
|
||||
when:
|
||||
- loki_version == "latest"
|
||||
- loki_binary_local_dir | length == 0
|
||||
|
||||
- block:
|
||||
- name: "Get checksum list"
|
||||
set_fact:
|
||||
__loki_checksums: "{{ lookup('url', 'https://github.com/grafana/loki/releases/download/v' + loki_version + '/SHA256SUMS', wantlist=True) | list }}"
|
||||
run_once: true
|
||||
|
||||
- name: "Get checksum for {{ item[1] }} in {{ go_arch }} architecture"
|
||||
set_fact:
|
||||
__loki_bins_checksum: "{{ __loki_bins_checksum | default({}) | combine({item[1]: item[0].split()[0]}) }}"
|
||||
loop: "{{ lookup('nested', __loki_checksums, loki_bins, wantlist=True) }}"
|
||||
when:
|
||||
- "(item[1] + '-linux-' + go_arch + '.zip') in item[0].split()[1]"
|
||||
delegate_to: localhost
|
||||
when:
|
||||
- loki_binary_local_dir | length == 0
|
0
templates/loki.service.j2
Normal file
0
templates/loki.service.j2
Normal file
47
templates/loki.yml.j2
Normal file
47
templates/loki.yml.j2
Normal file
@ -0,0 +1,47 @@
|
||||
#jinja2: trim_blocks: True, lstrip_blocks: True
|
||||
{{ ansible_managed | comment }}
|
||||
# https://github.com/grafana/loki/blob/master/docs/configuration/README.md#configuration-file-reference
|
||||
|
||||
{% if loki_target != "" %}
|
||||
target: {{ loki_target }}
|
||||
{% endif %}}
|
||||
|
||||
{% if loki_auth_enabled %}
|
||||
auth_enabled: {{ loki_auth_enabled }}
|
||||
{% endif %}}
|
||||
{% if loki_server_config != [] %}
|
||||
server: {{ loki_server_config }}
|
||||
{% endif %}}
|
||||
{% if loki_distributor_config != [] %}
|
||||
distributor: {{ loki_distributor_config }}
|
||||
{% endif %}}
|
||||
{% if loki_querier_config != [] %}
|
||||
querier: {{ loki_querier_config }}
|
||||
{% endif %}}
|
||||
{% if loki_ingester_client_config != [] %}
|
||||
ingester_client: {{ loki_ingester_client_config }}
|
||||
{% endif %}}
|
||||
{% if loki_ingester_config != [] %}
|
||||
ingester: {{ loki_ingester_config }}
|
||||
{% endif %}}
|
||||
{% if loki_storage_config != [] %}
|
||||
storage_config: {{ loki_storage_config }}
|
||||
{% endif %}}
|
||||
{% if loki_chunk_store_config != [] %}
|
||||
chunk_store_config: {{ loki_chunk_store_config }}
|
||||
{% endif %}}
|
||||
{% if loki_schema_config != [] %}
|
||||
schema_config: {{ loki_schema_config }}
|
||||
{% endif %}}
|
||||
{% if loki_limits_config != [] %}
|
||||
limits_config: {{ loki_limits_config }}
|
||||
{% endif %}}
|
||||
{% if loki_frontend_worker_config != [] %}
|
||||
frontend_worker_config: {{ loki_frontend_worker_config }}
|
||||
{% endif %}}
|
||||
{% if loki_table_manager_config != [] %}
|
||||
table_manager_config: {{ loki_table_manager_config }}
|
||||
{% endif %}}
|
||||
{% if loki_runtime_config != [] %}
|
||||
runtime_config: {{ loki_runtime_config }}
|
||||
{% endif %}}
|
9
vars/main.yml
Normal file
9
vars/main.yml
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
go_arch_map:
|
||||
i386: '386'
|
||||
x86_64: 'amd64'
|
||||
aarch64: 'arm64'
|
||||
armv7l: 'armv7'
|
||||
armv6l: 'armv6'
|
||||
|
||||
go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}"
|
Loading…
Reference in New Issue
Block a user