---
- name: Dependencies installed
  community.general.pkgng:
    name: gtar
    state: latest

- name: Loki fetched
  get_url:
    url: https://github.com/grafana/loki/releases/download/v2.4.1/loki-freebsd-amd64.zip
    dest: /usr/local/bin/loki.zip

- name: Loki binary unpacked
  command: "unzip -o /usr/local/bin/loki.zip"
  args:
    chdir: /usr/local/bin
    warn: false

- name: Loki rc file installed
  ansible.builtin.copy:
    src: loki.rc
    dest: /usr/local/etc/rc.d/loki
    mode: a+x

- name: Loki enabled
  shell: sysrc loki_enable="YES"

- name: Loki config file installed
  template:
    src: loki.config.yml.j2
    dest: /usr/local/etc/loki.config.yml
    owner: root
    mode: 0644
  notify: Loki restarted

- name: Loki started
  service: name=loki state=started
