Deploy Grafana using Ansible-playbook on Ubuntu 22.04 LTS

Introduction

Grafana is an open-source analytics and visualization platform used to monitor and analyze data from various sources. It provides a flexible and customizable interface for creating and displaying real-time dashboards, graphs, and charts. Grafana supports a wide range of data sources, including databases, time-series databases like Prometheus and InfluxDB, cloud monitoring services, and more.

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 using Ansible-play on ubuntu 22.04 LTS Linux machine.

Step 1: Create an Ansible playbook file

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

To create ansible playbook.

sudo nano deploy_grafana.yml

Paste the following set of tasks.

---
- name: Deploy Grafana
  hosts: your_target_servers
  become: true

  tasks:
    - name: Update apt package cache
      apt:
        update_cache: yes

    - name: Install required packages
      apt:
        name: 
          - software-properties-common
          - apt-transport-https
          - ca-certificates
          - curl
          - gnupg-agent

    - name: Add Grafana APT GPG key
      apt_key:
        url: https://packages.grafana.com/gpg.key

    - name: Add Grafana APT repository
      apt_repository:
        repo: deb https://packages.grafana.com/oss/deb stable main
        state: present

    - name: Install Grafana
      apt:
        name: grafana
        state: present

    - name: Start and enable Grafana service
      service:
        name: grafana-server
        state: started
        enabled: yes

Replace your_target_servers with the target servers or server group where you want to install Grafana and Save the playbook file.

Step 2: Create an Ansible inventory file

Create an Ansible inventory file (e.g., inventory.ini) with the IP addresses or hostnames of your target servers:

[your_target_servers]
server1 ansible_ssh_host=192.168.1.1
server2 ansible_ssh_host=192.168.1.2

Replace the IP addresses with your actual server IP addresses.

Step 3: Run the Ansible playbook

We need to execute the following command in order to deploy the Grafana to our target machine.

ansible-playbook -i inventory.ini deploy_grafana.yml

This playbook will update the package cache, install necessary packages, add the Grafana APT GPG key and repository, install Grafana, and start the Grafana service.

Note: This playbook assumes that you have Ansible installed on your local machine and SSH access to the target servers. Additionally, ensure that the servers have internet access to download Grafana and its dependencies during the installation process.

Conclusion

We have successfully deployed Grafana using Ansible Playbook on Ubuntu 22.04 LTS. If you are still having issues, please leave a comment below.

Author

Deploy Grafana using Ansible-playbook on Ubuntu 22.04 LTS

Leave a Reply

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

Scroll to top