Fix loki install

This commit is contained in:
SebClem 2023-05-23 19:02:58 +02:00
parent 8c0ed55dad
commit 7f95e05fbf
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
3 changed files with 18 additions and 35 deletions

View File

@ -5,5 +5,6 @@
"*.yml": "ansible" "*.yml": "ansible"
}, },
"ansible.ansible.useFullyQualifiedCollectionNames": true, "ansible.ansible.useFullyQualifiedCollectionNames": true,
"editor.formatOnSave": true "editor.formatOnSave": true,
"ansible.python.interpreterPath": "/bin/python3"
} }

View File

@ -27,6 +27,14 @@
- "{{ loki_storage_dir }}/chunks" - "{{ loki_storage_dir }}/chunks"
when: ('loki' in loki_bins) when: ('loki' in loki_bins)
- name: Create Bin directories
ansible.builtin.file:
path: "/opt/loki"
state: directory
owner: root
group: root
mode: "0755"
- name: Create loki configuration directories - name: Create loki configuration directories
ansible.builtin.file: ansible.builtin.file:
path: "{{ item }}" path: "{{ item }}"
@ -37,35 +45,28 @@
with_items: with_items:
- "{{ loki_config_dir }}" - "{{ loki_config_dir }}"
- name: Download bin - name: Install bin
block: block:
- name: Unpack binaries - name: Unpack binaries
ansible.builtin.unarchive: ansible.builtin.unarchive:
remote_src: true remote_src: true
src: "https://github.com/grafana/loki/releases/download/v{{ loki_version }}/{{ item }}-linux-{{ go_arch }}.zip" src: "https://github.com/grafana/loki/releases/download/v{{ loki_version }}/{{ item }}-linux-{{ go_arch }}.zip"
dest: "/tmp" dest: "/opt/loki/"
loop: "{{ loki_bins }}"
check_mode: false
- name: Copy binaries
ansible.builtin.copy:
src: "/tmp/{{ item }}-linux-{{ go_arch }}"
dest: "/usr/local/bin/{{ item }}"
mode: "0755" mode: "0755"
owner: root owner: root
group: root group: root
remote_src: true
loop: "{{ loki_bins }}" loop: "{{ loki_bins }}"
notify: notify:
- restart loki - restart loki
when: _download_archive is changed
- name: Clean binaries - name: Create bin symlink
ansible.builtin.file: ansible.builtin.file:
path: "/tmp/{{ item }}-linux-{{ go_arch }}" src: "/opt/loki/{{ item }}-linux-{{ go_arch }}"
state: absent dest: "/usr/local/bin/{{ item }}"
state: link
loop: "{{ loki_bins }}" loop: "{{ loki_bins }}"
when: _download_archive is changed notify:
- restart loki
- name: Create systemd service unit - name: Create systemd service unit
ansible.builtin.template: ansible.builtin.template:

View File

@ -28,25 +28,6 @@
ansible.builtin.set_fact: ansible.builtin.set_fact:
loki_version: "{{ _latest_release.json.tag_name[1:] }}" loki_version: "{{ _latest_release.json.tag_name[1:] }}"
- name: Get checksums
delegate_to: localhost
when:
- loki_binary_local_dir | length == 0
block:
- name: Get checksum 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
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]"
- name: Install unzip - name: Install unzip
ansible.builtin.apt: ansible.builtin.apt:
name: unzip name: unzip