Help build the future of open source observability software Open positions

Check out the open source projects we support Downloads

Grot cannot remember your choice unless you click the consent notice at the bottom.

How to set up Grafana Mimir using Ansible

How to set up Grafana Mimir using Ansible

2024-07-23 5 min

Gerard van Engelen is a seasoned DevOps engineer who ensures the quality of products by drawing parallels between complex issues and simpler, everyday scenarios. This approach helps in delivering value, ensuring that products are not only built correctly but also offer the right functionalities.

Ansible is popular with system administrators and DevOps professionals who use it for automating IT tasks such as configuration management, application deployment, and orchestration.

Since 2022, Grafana Labs has supported Ansible users through its Grafana Ansible collection. With Grafana, OpenTelemetry Collector, Grafana Alloy, and modules for provisioning Grafana resources, the Ansible collection is there to help Grafana Administrators. And now we’ve added Grafana Mimir deployments to support Mimir configurations as well.

In this guide we’ll walk you through how to use the mimir role with the Grafana Ansible collection to deploy and manage Mimir across multiple Linux hosts. We’ll then show you how to explore your data in Grafana.

Before you begin

To get started, you should have the following:

  • 3 Linux hosts with SSH access and sufficient permissions
  • Ansible installed on your base system

Install the Grafana Ansible collection

The Mimir role is available in the Grafana Ansible collection as of the 5.0.0 release.

To install the Grafana Ansible collection, run this command:

ansible-galaxy collection install grafana.grafana:4.0.0

Create an Ansible inventory file

Next, you will set up your hosts and create an inventory file.

  1. Create an Ansible inventory file.

An Ansible inventory, which resides in a file named inventory, lists each host IP on a separate line, like this (3 hosts shown):

146.190.208.216    # hostname = mimir-01
146.190.208.190    # hostname = mimir-02
146.190.208.190    # hostname = mimir-03

Note: If you are copying the above file, remove the comments (#).

  1. Create an ansible.cfg file within the same directory as inventory, with the following values:
[defaults]
inventory = inventory  # Path to the inventory file
private_key_file = ~/.ssh/id_rsa   # Path to my private SSH Key
remote_user=root

Use the Mimir Ansible role

Next you will create an Ansible playbook that calls the mimir role from the grafana.grafana Ansible collection.

To use the Mimir Ansible role:

First, create a file named deploy-mimir.yml in the same directory as ansible.cfg and inventory and add the configuration below.

Just like other roles, Mimir is now available via Ansible Galaxy. You can install the collection using the command below:

ansible-galaxy collection install grafana.grafana

After the collection is installed, you can use the mimir role in your playbook like this:

- hosts: all
  roles:
   - role: grafana.grafana.mimir

This way, Ansible knows to look for the mimir role within the grafana.grafana collection. Ensure your Ansible configuration and version support collections, as this feature was introduced in Ansible 2.9.

Configuring Mimir using the Ansible collection

The Mimir role is highly configurable due to the config templating. If you want to run Mimir in HA, just add the following vars to your playbook:

- name: Install Mimir
 hosts: all
 become: true

tasks:
  - name: Install Mimir
    ansible.builtin.include_role:
      name: grafana.grafana.mimir
    vars:
      mimir_storage:
   # You can use different object store backends, use Minio for local development
        storage:
          backend: s3
          s3:
            endpoint: {{ endpoint }}
            access_key_id: {{ acces_key_id }}
            secret_access_key: {{ secret_acces_key }}
            insecure: true # False when using https
            bucket_name: mimir


          # Blocks storage requires a prefix when using a common object storage bucket.
          mimir_blocks_storage:
          storage_prefix: blocks
          tsdb:
              dir: "{{ mimir_working_path}}/ingester"


          # Use memberlist, a gossip-based protocol, to enable the 3 Mimir replicas   to communicate
          mimir_memberlist:
            join_members:
            - mimir-01:7946
            - mimir-02:7946
            - mimir-03::7946

The playbook calls the mimir role from the grafana.grafana Ansible collection. The Mimir configuration in this playbook installs Mimir on three hosts, makes sure the hosts communicate with each other, and enables use of the object storage backend.

Refer to the Grafana Ansible documentation to understand the other variables you can pass to the mimir role.

To run the playbook, run this command:

ansible-playbook deploy-mimir.yml

Note: You can place the deploy-mimir.yml, ansible.cfg, and inventory files in different directories based on your needs.

Check that metrics are available in Mimir

Since we’re running Mimir in HA by replication, you’ll need to set up your own load balancing to be able to use Mimir to its full potential. If you’ve set up load balancing, you’ll be able to add your datasource in Grafana using your selected hostname.

To check metrics:

  1. Find the Explore section. Look for the Explore icon (it looks like a compass) on the left-side vertical navigation bar in Grafana and click it.
  2. Select Your Prometheus data source. At the top of the page, there’s a dropdown menu. Use it to pick the Prometheus data source you’ve added.
  3. Run a test query. Type in the query{name="mimir-01"}.
  4. Check metrics. After running the query, if you see a graph and a table with data (similar to the example shown in the image below), it means your metrics are correctly being fetched and displayed.
  5. Explore additional metrics. Explore other metrics—like CPU load, memory usage, disk I/O, network bandwidth—and create dashboards to gain insights into your system’s performance.

If you don’t see any data, it could mean that metrics aren’t being collected as expected. To troubleshoot, check the status of your Mimir service by running this command:

sudo systemctl status mimir.service

If the Mimir service isn’t running, there might be an issue with the configuration syntax, or you might need to debug further. For help with this, take a look at the documentation available on configuring Mimir correctly.