Introduction
Prometheus is an open-source monitoring and alerting toolkit designed for reliability and scalability of systems and applications. It was originally developed by SoundCloud and later donated to the Cloud Native Computing Foundation (CNCF). Prometheus is widely used in the field of DevOps and system administration for monitoring and observability purposes.
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 Prometheus using Ansible-play on ubuntu 22.04 LTS Linux machine.
Step 1: Create an Ansible playbook file
To deploy Prometheus using Ansible on Ubuntu 22.04 LTS, you can create an Ansible playbook that installs Prometheus and its components. Below is a simple example playbook to get you started. Make sure you have Ansible installed on your control machine before running the playbook.
Create an Ansible playbook file, for example, deploy_prometheus.yml
:
---
- name: Deploy Prometheus
hosts: your_target_servers
become: true
tasks:
- name: Update apt cache
apt:
update_cache: yes
- name: Install prerequisite packages
apt:
name: "{{ item }}"
state: present
loop:
- apt-transport-https
- software-properties-common
- name: Add Prometheus APT repository
apt_repository:
repo: deb https://packages.grafana.com/oss/deb stable main
state: present
update_cache: yes
- name: Import GPG key for Prometheus
apt_key:
url: https://packages.grafana.com/gpg.key
state: present
- name: Install Prometheus
apt:
name: prometheus
state: present
- name: Start Prometheus service
systemd:
name: prometheus
state: started
enabled: yes
Replace your_target_servers with the actual target server(s) where you want to deploy Prometheus.
Step 2: Run the Ansible playbook
We need to execute the ansible playbook by using given command.
ansible-playbook -i your_inventory_file deploy_prometheus.yml
Make sure to replace your_inventory_file
with the path to your Ansible inventory file, which lists the IP addresses or hostnames of your target servers.
This playbook performs the following tasks:
- Updates the APT cache.
- Installs prerequisite packages.
- Adds the Prometheus APT repository.
- Imports the GPG key for the Prometheus repository.
- Installs Prometheus.
- Starts the Prometheus service and enables it to start on boot.
Note: This playbook assumes that Prometheus is available in the Grafana APT repository. If Prometheus is available in the default Ubuntu repositories or a different repository, you may need to adjust the playbook accordingly.
Additionally, you might want to customize the Prometheus configuration based on your specific requirements. The default configuration file is usually located at /etc/prometheus/prometheus.yml
. You can modify this file to suit your monitoring needs.
Conclusion
We have successfully deployed Prometheus using Ansible Playbook on Ubuntu 22.04 LTS. If you are still having issues, please leave a comment below.