Skip to content

Commit

Permalink
Merge pull request #3 from weakcamel/update_github_actions_and_fix_lint
Browse files Browse the repository at this point in the history
fix Github actions
  • Loading branch information
weakcamel authored Jun 10, 2022
2 parents cbb4427 + 98d3ceb commit 0e57631
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Lint Ansible Playbook
uses: ansible/ansible-lint-action@master
uses: ansible/ansible-lint-action@main
30 changes: 15 additions & 15 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ loki_chunk_store_config:

loki_schema_config:
configs:
- from: 2020-01-01
store: boltdb
object_store: filesystem
schema: v11
index:
prefix: index_
period: 168h

chunks:
prefix: index_
period: 168h
row_shards: 16
- from: 2020-01-01
store: boltdb
object_store: filesystem
schema: v11
index:
prefix: index_
period: 168h

chunks:
prefix: index_
period: 168h
row_shards: 16

loki_limits_config:
enforce_metric_name: false
Expand Down Expand Up @@ -94,9 +94,9 @@ promtail_scrape_config:
host: "{{ ansible_hostname }}"
max_age: 12h
relabel_configs:
- source_labels:
- __journal__systemd_unit
target_label: unit
- source_labels:
- __journal__systemd_unit
target_label: unit

promtail_target_config: []
promtail_positions_config:
Expand Down
10 changes: 5 additions & 5 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
---
- name: restart loki
become: true
systemd:
ansible.builtin.systemd:
daemon_reload: true
name: loki
state: restarted
when: ('loki' in loki_bins)

- name: reload loki
become: true
systemd:
ansible.builtin.systemd:
name: loki
state: reloaded
when: ('loki' in loki_bins)

- name: restart promtail
become: true
systemd:
ansible.builtin.systemd:
daemon_reload: true
name: promtail
state: restarted
when: ('promtail' in loki_bins)

- name: reload promtail
become: true
systemd:
ansible.builtin.systemd:
name: promtail
state: reloaded
when: ('promtail' in loki_bins)
when: ('promtail' in loki_bins)
2 changes: 1 addition & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ galaxy_info:
description: Deploy and configure Loki and Promtail.
issue_tracker_url: https://github.com/weakcamel/ansible-role-loki/issues
license: WTFPL
min_ansible_version: 2.9
min_ansible_version: "2.9"
platforms:
- name: Ubuntu
versions:
Expand Down
6 changes: 3 additions & 3 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: configure loki
template:
ansible.builtin.template:
src: "loki.yml.j2"
dest: "{{ loki_config_dir }}/loki.yml"
force: true
Expand All @@ -12,7 +12,7 @@
when: ('loki' in loki_bins)

- name: configure promtail
template:
ansible.builtin.template:
src: "promtail.yml.j2"
dest: "{{ loki_config_dir }}/promtail.yml"
force: true
Expand All @@ -21,4 +21,4 @@
mode: 0640
notify:
- reload promtail
when: ('promtail' in loki_bins)
when: ('promtail' in loki_bins)
20 changes: 11 additions & 9 deletions tasks/install.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
- name: create {{ loki_group }} system group
group:
ansible.builtin.group:
name: "{{ loki_group }}"
system: true
state: present

- name: create {{ loki_user }} system user
user:
ansible.builtin.user:
name: "{{ loki_user }}"
system: true
shell: "/usr/sbin/nologin"
Expand All @@ -15,7 +15,7 @@
home: "{{ loki_storage_dir }}"

- name: create loki data directory
file:
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: loki
Expand All @@ -28,7 +28,7 @@
when: ('loki' in loki_bins)

- name: create loki configuration directories
file:
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: root
Expand All @@ -37,13 +37,15 @@
with_items:
- "{{ loki_config_dir }}"

- block:
- name: retrieve Loki binaries
block:
- name: download binaries to a temporary folder
become: false
get_url:
ansible.builtin.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] }}"
mode: 0644
register: _download_archive
until: _download_archive is succeeded
retries: 5
Expand All @@ -53,7 +55,7 @@

- name: unpack binaries
become: false
unarchive:
ansible.builtin.unarchive:
src: "/tmp/{{ item }}-{{ loki_version }}-linux-{{ go_arch }}.zip"
dest: "/tmp"
creates: "/tmp/{{ item }}-{{ loki_version }}-linux-{{ go_arch }}"
Expand All @@ -62,7 +64,7 @@
check_mode: false

- name: propagate official binaries
copy:
ansible.builtin.copy:
src: "/tmp/{{ item }}-linux-{{ go_arch }}"
dest: "/usr/local/bin/{{ item }}"
mode: 0755
Expand All @@ -74,7 +76,7 @@
- restart loki

- name: create systemd service unit
template:
ansible.builtin.template:
src: "{{ item }}.service.j2"
dest: "/etc/systemd/system/{{ item }}.service"
owner: root
Expand Down
20 changes: 12 additions & 8 deletions tasks/preflight.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
---
- name: Assert usage of systemd as an init system
assert:
ansible.builtin.assert:
that: ansible_service_mgr == 'systemd'
msg: "This module only works with systemd"

- block:
- name: Get loki latest release
block:
- name: Get latest release
uri:
ansible.builtin.uri:
url: "https://api.github.com/repos/grafana/loki/releases/latest"
method: GET
return_content: true
Expand All @@ -21,20 +22,23 @@
retries: 5

- name: Set loki version to {{ _latest_release.json.tag_name[1:] }}
set_fact:
ansible.builtin.set_fact:
loki_version: "{{ _latest_release.json.tag_name[1:] }}"
when:
- loki_version == "latest"
- loki_binary_local_dir | length == 0

- block:
- name: Load loki checksums
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 }}"
ansible.builtin.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 bins
set_fact:
ansible.builtin.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:
Expand Down

0 comments on commit 0e57631

Please sign in to comment.