Deploy Grafana Loki using Ansible Playbook on Ubuntu

Introduction

Grafana Loki is a logging platform developed by Grafana Labs. It is designed to be a highly scalable, multi-tenant log aggregation system that is easy to use and operate. It is built on top of the popular open-source log aggregation tool, Prometheus, and is compatible with its data model and query language.

Prerequisites

  • Up and running ubuntu 22.04 LTS machine.
  • Basic knowledge in linux commands.
  • Internet connectivity.
  • Ansible should be installed.

We can use the given link to install Ansible on Ubuntu 22.04 LTS Linux machine.

In this post, We will show you how to deploy Grafana Loki using Ansible-play on ubuntu 22.04 LTS Linux machine.

Step 1: Create an Ansible playbook file

To deploy Grafana loki using Ansible on Ubuntu 22.04 LTS, you can create an Ansible playbook that installs Grafana loki and its dependencies. Here’s a simple example playbook to get you started:

To create ansible playbook.

nano deploy_grafana_loki.yml

Paste the following set of tasks.

---
- name: Deploy Loki on Ubuntu 22.04 LTS
  hosts: your_target_server
  become: yes
  gather_facts: yes

  tasks:
    - name: Install dependencies
      apt:
        name: "{{ item }}"
        state: present
      loop:
        - software-properties-common
        - apt-transport-https
        - ca-certificates
        - curl
        - unzip
        - gnupg

    - name: Download Loki Zip file
      get_url:
        url: "https://github.com/grafana/loki/releases/download/v2.7.1/loki-linux-amd64.zip"
        dest: "/tmp/"

    - name: Extracting and moving loki files
      shell: |
        unzip /tmp/loki-linux-amd64.zip
        mv /tmp/loki-linux-amd64 /usr/local/bin/loki
        mkdir /etc/loki
        mkdir -p /data/loki


    - name: Copy Loki configuration file
      copy:
        src: loki-local-config.yaml
        dest: /etc/loki/loki-local-config.yaml
        mode: 0644

    - name: Copy Loki service file
      copy:
        src: loki.service
        dest: /etc/systemd/system/local-config.yaml
        mode: 0644

    - name: Reloading loki daemon
      command: systemctl daemon-reload

    - name: Start Loki service
      systemd:
        name: loki
        enabled: yes
        state: started

Adjust the playbook according to your specific needs, especially the paths, configuration files, and any other customization.

Step 2: Create Loki configuration file

Create a Loki configuration file (e.g., loki-config.yaml) with the necessary configurations for your use case.

auth_enabled: false

server:
  http_listen_port: 3100

ingester:
  lifecycler:
    address: 127.0.0.1
    ring:
      kvstore:
        store: inmemory
      replication_factor: 1
    final_sleep: 0s
  chunk_idle_period: 5m
  chunk_retain_period: 30s
  max_transfer_retries: 0

schema_config:
  configs:
    - from: 2018-04-15
      store: boltdb
      object_store: filesystem
      schema: v11
      index:
        prefix: index_
        period: 168h

storage_config:
  boltdb:
    directory: /data/loki/index

  filesystem:
    directory: /data/loki/chunks

limits_config:
  enforce_metric_name: false
  reject_old_samples: true
  reject_old_samples_max_age: 168h

chunk_store_config:
  max_look_back_period: 0s

table_manager:
  retention_deletes_enabled: false
  retention_period: 0s

save and exit for the nano text editor.

Step 3: Deploying Grafana Loki

Run the Ansible playbook using the following command:

ansible-playbook -i your_inventory_file loki_deploy.yml

Replace your_inventory_file with the path to your Ansible inventory file and ensure it contains the target server’s information.

This is a basic example, and you may need to adjust it based on your specific requirements and the Loki version you want to install. Always refer to the official documentation and release notes for the latest and most accurate information.

Conclusion

We have successfully installed Grafana-loki with Ansible on ubuntu 22.04 LTS server, If you still have questions, please post them in the comments section below.

Author

Deploy Grafana Loki using Ansible Playbook on Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top