Fix deprecate and some lint

This commit is contained in:
SebClem 2023-05-20 15:28:15 +02:00
parent c320498f68
commit 8c0ed55dad
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
4 changed files with 52 additions and 59 deletions

View File

@ -1,24 +1,24 @@
---
- name: configure loki
template:
- name: Configure loki
ansible.builtin.template:
src: "loki.yml.j2"
dest: "{{ loki_config_dir }}/loki.yml"
force: true
owner: root
group: "{{ loki_user }}"
mode: 0640
mode: "0640"
notify:
- reload loki
when: ('loki' in loki_bins)
- name: configure promtail
template:
- name: Configure promtail
ansible.builtin.template:
src: "promtail.yml.j2"
dest: "{{ loki_config_dir }}/promtail.yml"
force: true
owner: root
group: "{{ loki_user }}"
mode: 0640
mode: "0640"
notify:
- reload promtail
when: ('promtail' in loki_bins)

View File

@ -1,12 +1,12 @@
---
- name: create {{ loki_group }} system group
group:
- name: Create system group {{ loki_group }}
ansible.builtin.group:
name: "{{ loki_group }}"
system: true
state: present
- name: create {{ loki_user }} system user
user:
- name: Create system user {{ loki_user }}
ansible.builtin.user:
name: "{{ loki_user }}"
system: true
shell: "/usr/sbin/nologin"
@ -14,13 +14,13 @@
createhome: false
home: "{{ loki_storage_dir }}"
- name: create loki data directory
file:
- name: Create loki data directory
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: loki
group: loki
mode: 0755
mode: "0755"
with_items:
- "{{ loki_storage_dir }}"
- "{{ loki_storage_dir }}/index"
@ -28,42 +28,30 @@
when: ('loki' in loki_bins)
- name: Create loki configuration directories
file:
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: root
group: "{{ loki_group }}"
mode: 0770
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: Download bin
block:
- name: Unpack binaries
unarchive:
ansible.builtin.unarchive:
remote_src: true
src: "/tmp/{{ item }}-{{ loki_version }}-linux-{{ go_arch }}.zip"
src: "https://github.com/grafana/loki/releases/download/v{{ loki_version }}/{{ item }}-linux-{{ go_arch }}.zip"
dest: "/tmp"
loop: "{{ loki_bins }}"
check_mode: false
when: _download_archive is changed
- name: Copy binaries
copy:
ansible.builtin.copy:
src: "/tmp/{{ item }}-linux-{{ go_arch }}"
dest: "/usr/local/bin/{{ item }}"
mode: 0755
mode: "0755"
owner: root
group: root
remote_src: true
@ -73,25 +61,25 @@
when: _download_archive is changed
- name: Clean binaries
file:
ansible.builtin.file:
path: "/tmp/{{ item }}-linux-{{ go_arch }}"
state: absent
loop: "{{ loki_bins }}"
when: _download_archive is changed
- name: Create systemd service unit
template:
ansible.builtin.template:
src: "{{ item }}.service.j2"
dest: "/etc/systemd/system/{{ item }}.service"
owner: root
group: root
mode: 0644
mode: "0644"
notify: "restart {{ item }}"
loop: "{{ loki_bins }}"
when: item == 'loki' or item == 'promtail'
- name: Find temps files to del
find:
ansible.builtin.find:
paths: /tmp
file_type: file
patterns: "loki-*-linux-{{ go_arch }}.zip,promtail-*-linux-{{ go_arch }}.zip"
@ -99,7 +87,7 @@
register: to_del
- name: Clean temp files
file:
ansible.builtin.file:
path: "{{ item.path }}"
state: absent
loop: "{{ to_del.files }}"

View File

@ -1,20 +1,21 @@
---
- include: preflight.yml
- name: Loki Preflight
ansible.builtin.import_tasks: preflight.yml
tags:
- loki_pre_install
- include: install.yml
become: true
- name: Install loki
ansible.builtin.import_tasks: install.yml
tags:
- loki_configure
- include: configure.yml
become: true
- name: Configure Loki
ansible.builtin.import_tasks: configure.yml
tags:
- loki_configure
- name: Install docker driver
ansible.builtin.include_tasks: docker_driver.yml
ansible.builtin.import_tasks: docker_driver.yml
when: loki_docker_driver
tags:
- loki_configure

View File

@ -1,12 +1,16 @@
---
- 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 version
when:
- loki_version == "latest"
- loki_binary_local_dir | length == 0
block:
- name: Get latest release
uri:
ansible.builtin.uri:
url: "https://api.github.com/repos/grafana/loki/releases/latest"
method: GET
return_content: true
@ -21,35 +25,35 @@
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: Get checksums
delegate_to: localhost
when:
- loki_binary_local_dir | length == 0
block:
- name: Get checksum list
set_fact:
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:
- "(item[1] + '-linux-' + go_arch + '.zip') in item[0].split()[1]"
delegate_to: localhost
when:
- loki_binary_local_dir | length == 0
- name: Install unzip
apt:
ansible.builtin.apt:
name: unzip
update_cache: true
- name: Install dnspython
pip:
ansible.builtin.pip:
name:
- dnspython
- docker