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 - name: Configure loki
template: ansible.builtin.template:
src: "loki.yml.j2" src: "loki.yml.j2"
dest: "{{ loki_config_dir }}/loki.yml" dest: "{{ loki_config_dir }}/loki.yml"
force: true force: true
owner: root owner: root
group: "{{ loki_user }}" group: "{{ loki_user }}"
mode: 0640 mode: "0640"
notify: notify:
- reload loki - reload loki
when: ('loki' in loki_bins) when: ('loki' in loki_bins)
- name: configure promtail - name: Configure promtail
template: ansible.builtin.template:
src: "promtail.yml.j2" src: "promtail.yml.j2"
dest: "{{ loki_config_dir }}/promtail.yml" dest: "{{ loki_config_dir }}/promtail.yml"
force: true force: true
owner: root owner: root
group: "{{ loki_user }}" group: "{{ loki_user }}"
mode: 0640 mode: "0640"
notify: notify:
- reload promtail - reload promtail
when: ('promtail' in loki_bins) when: ('promtail' in loki_bins)

View File

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

View File

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

View File

@ -1,12 +1,16 @@
--- ---
- name: Assert usage of systemd as an init system - name: Assert usage of systemd as an init system
assert: ansible.builtin.assert:
that: ansible_service_mgr == 'systemd' that: ansible_service_mgr == 'systemd'
msg: "This module only works with 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 - name: Get latest release
uri: ansible.builtin.uri:
url: "https://api.github.com/repos/grafana/loki/releases/latest" url: "https://api.github.com/repos/grafana/loki/releases/latest"
method: GET method: GET
return_content: true return_content: true
@ -21,35 +25,35 @@
retries: 5 retries: 5
- name: Set loki version to {{ _latest_release.json.tag_name[1:] }} - 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:] }}" 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 - 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 }}" __loki_checksums: "{{ lookup('url', 'https://github.com/grafana/loki/releases/download/v' + loki_version + '/SHA256SUMS', wantlist=True) | list }}"
run_once: true run_once: true
- name: Get checksum for bins - 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]}) }}" __loki_bins_checksum: "{{ __loki_bins_checksum | default({}) | combine({item[1]: item[0].split()[0]}) }}"
loop: "{{ lookup('nested', __loki_checksums, loki_bins, wantlist=True) }}" loop: "{{ lookup('nested', __loki_checksums, loki_bins, wantlist=True) }}"
when: when:
- "(item[1] + '-linux-' + go_arch + '.zip') in item[0].split()[1]" - "(item[1] + '-linux-' + go_arch + '.zip') in item[0].split()[1]"
delegate_to: localhost
when:
- loki_binary_local_dir | length == 0
- name: Install unzip - name: Install unzip
apt: ansible.builtin.apt:
name: unzip name: unzip
update_cache: true update_cache: true
- name: Install dnspython - name: Install dnspython
pip: ansible.builtin.pip:
name: name:
- dnspython - dnspython
- docker - docker