Deploy Alert Manager using Ansible-playbook on Ubuntu 22.04 LTS

Introduction

Prometheus Alertmanager is a component of the Prometheus monitoring and alerting toolkit. Its primary purpose is to handle alerts generated by Prometheus and manage their routing, grouping, and notification.

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

Step 1: Create an Ansible playbook

To deploy Alertmanager using Ansible on Ubuntu 22.04 LTS, you can create an Ansible playbook that installs and configures Alertmanager. Alertmanager is a component of the Prometheus monitoring system and is used for handling alerts.

To create ansible playbook file.

sudo nano deploy_alertmanager.yml

Paste the fallowing tasks.

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

  tasks:
    - name: Create Alertmanager user
      user:
        name: alertmanager
        system: yes
        shell: /bin/false

    - name: Download and extract Alertmanager
      get_url:
        url: "https://github.com/prometheus/alertmanager/releases/download/v0.24.0/alertmanager-0.24.0.linux-amd64.tar.gz"
        dest: "/tmp/alertmanager.tar.gz"

    - name: Extract Alertmanager
      ansible.builtin.unarchive:
        src: "/tmp/alertmanager.tar.gz"
        dest: "/opt/"

    - name: Set permissions and ownership
      file:
        path: "/opt/alertmanager-0.24.0.linux-amd64/alertmanager"
        mode: "0755"
        owner: "alertmanager"
        group: "alertmanager"

    - name: Create Alertmanager configuration directory
      file:
        path: "/etc/alertmanager"
        state: directory
        mode: "0755"
        owner: "alertmanager"
        group: "alertmanager"

    - name: Copy Alertmanager configuration file
      copy:
        src: "alertmanager.yml"
        dest: "/etc/alertmanager/alertmanager.yml"
        owner: "alertmanager"
        group: "alertmanager"
        mode: "0644"

    - name: Create Alertmanager systemd service
      systemd:
        name: alertmanager
        enabled: yes
        state: started
        daemon_reload: yes
        daemon_reexec: yes
        scope: user
        user: alertmanager
        exec_start: "/opt/alertmanager-0.24.0.linux-amd64/alertmanager --config.file=/etc/alertmanager/alertmanager.yml"

This playbook does the following:

  • Creates a user named alertmanager for running Alertmanager.
  • Downloads the Alertmanager binary from the official GitHub release page.
  • Extracts the Alertmanager tarball to the /opt/ directory.
  • Sets the necessary permissions and ownership for the Alertmanager binary.
  • Creates the Alertmanager configuration directory and copies the configuration file (alertmanager.yml) to the appropriate location.
  • Creates a systemd service for Alertmanager and starts it.

Make sure to replace your_target_servers with the target servers or server group where you want to install Alertmanager.

Create an Ansible inventory file (e.g., inventory.ini) with the IP addresses or hostnames of your target servers and save exit form the nano editor.

Step 2: Run the Ansible playbook

We need to execute the following command to deploy the Ansible playbook.

ansible-playbook -i inventory.ini deploy_alertmanager.yml

Adjust the version number in the URL to the latest version available on the Alertmanager GitHub releases page. Additionally, provide a valid alertmanager.yml configuration file suitable for your environment.

Conclusion

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

Author

Deploy Alert Manager 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