From 35cea5918d5ceb04766e7e254c1567158372f0b3 Mon Sep 17 00:00:00 2001 From: Waldek Maleska Date: Fri, 10 Jun 2022 15:47:40 +0100 Subject: [PATCH 1/3] fix Github actions - part1 - update lint action's Github branch to main - fix FQCN findings --- .github/workflows/lint.yml | 2 +- defaults/main.yml | 30 +++++++++++++++--------------- handlers/main.yml | 10 +++++----- meta/main.yml | 2 +- tasks/configure.yml | 6 +++--- tasks/install.yml | 16 ++++++++-------- tasks/preflight.yml | 14 ++++++++------ 7 files changed, 41 insertions(+), 39 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b343972..03aa9ab 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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 diff --git a/defaults/main.yml b/defaults/main.yml index 412dca2..dcde76c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 @@ -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: diff --git a/handlers/main.yml b/handlers/main.yml index a3c4fcf..da0548c 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,7 +1,7 @@ --- - name: restart loki become: true - systemd: + ansible.builtin.systemd: daemon_reload: true name: loki state: restarted @@ -9,14 +9,14 @@ - 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 @@ -24,7 +24,7 @@ - name: reload promtail become: true - systemd: + ansible.builtin.systemd: name: promtail state: reloaded - when: ('promtail' in loki_bins) \ No newline at end of file + when: ('promtail' in loki_bins) diff --git a/meta/main.yml b/meta/main.yml index fcefe74..2174161 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -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: diff --git a/tasks/configure.yml b/tasks/configure.yml index 7cdc08e..b0d5127 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -1,6 +1,6 @@ --- - name: configure loki - template: + ansible.builtin.template: src: "loki.yml.j2" dest: "{{ loki_config_dir }}/loki.yml" force: true @@ -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 @@ -21,4 +21,4 @@ mode: 0640 notify: - reload promtail - when: ('promtail' in loki_bins) \ No newline at end of file + when: ('promtail' in loki_bins) diff --git a/tasks/install.yml b/tasks/install.yml index 7312f5e..641e793 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -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" @@ -15,7 +15,7 @@ home: "{{ loki_storage_dir }}" - name: create loki data directory - file: + ansible.builtin.file: path: "{{ item }}" state: directory owner: loki @@ -28,7 +28,7 @@ when: ('loki' in loki_bins) - name: create loki configuration directories - file: + ansible.builtin.file: path: "{{ item }}" state: directory owner: root @@ -40,7 +40,7 @@ - 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] }}" @@ -53,7 +53,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 }}" @@ -62,7 +62,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 @@ -74,7 +74,7 @@ - restart loki - name: create systemd service unit - template: + ansible.builtin.template: src: "{{ item }}.service.j2" dest: "/etc/systemd/system/{{ item }}.service" owner: root diff --git a/tasks/preflight.yml b/tasks/preflight.yml index 549e34b..a69c15e 100644 --- a/tasks/preflight.yml +++ b/tasks/preflight.yml @@ -1,12 +1,12 @@ --- - 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 latest release - uri: + ansible.builtin.uri: url: "https://api.github.com/repos/grafana/loki/releases/latest" method: GET return_content: true @@ -21,7 +21,7 @@ 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" @@ -29,12 +29,14 @@ - 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: From 9dd9a794793cee876eac760ec79d87da02e47634 Mon Sep 17 00:00:00 2001 From: Waldek Maleska Date: Fri, 10 Jun 2022 15:56:56 +0100 Subject: [PATCH 2/3] add required task names to blocks --- tasks/install.yml | 3 ++- tasks/preflight.yml | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tasks/install.yml b/tasks/install.yml index 641e793..e7da13e 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -37,7 +37,8 @@ with_items: - "{{ loki_config_dir }}" -- block: +- name: retrieve Loki binaries + block: - name: download binaries to a temporary folder become: false ansible.builtin.get_url: diff --git a/tasks/preflight.yml b/tasks/preflight.yml index a69c15e..8ec037d 100644 --- a/tasks/preflight.yml +++ b/tasks/preflight.yml @@ -4,7 +4,8 @@ that: ansible_service_mgr == 'systemd' msg: "This module only works with systemd" -- block: +- name: Get loki latest release + block: - name: Get latest release ansible.builtin.uri: url: "https://api.github.com/repos/grafana/loki/releases/latest" @@ -27,7 +28,8 @@ - loki_version == "latest" - loki_binary_local_dir | length == 0 -- block: +- name: Load loki checksums + block: - name: Get checksum list ansible.builtin.set_fact: __loki_checksums: >- From 98d3cebb8cfa3514f20850af8cd543ff13897dcd Mon Sep 17 00:00:00 2001 From: Waldek Maleska Date: Fri, 10 Jun 2022 15:59:01 +0100 Subject: [PATCH 3/3] install: fix file permissions (lint finding) --- tasks/install.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tasks/install.yml b/tasks/install.yml index e7da13e..cffa40b 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -45,6 +45,7 @@ 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