Skip to content

Commit

Permalink
prometheus: Add basic Prometheus role
Browse files Browse the repository at this point in the history
  • Loading branch information
Per Lundberg committed Jun 8, 2021
1 parent b51d246 commit 1d9e360
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -13,6 +13,16 @@ Pull requests to fix obvious minor issues are welcome, but it's unlikely that an
- [awstats](roles/awstats) - installs and configures the [AWStats](https://awstats.sourceforge.io/) web server log analyzer
- [bind](roles/bind) - installs and configures the `bind9` DNS server as well as one or more zone files.
- [nginx](roles/nginx) - installs and configures the [nginx](https://nginx.org/) web server
- [prometheus](roles/prometheus) - installs and configures the [Prometheus](https://prometheus.io/) monitoring system & time series database

## Playbooks

The following playbooks executes the above roles:

- [awstats](awstats.yaml)
- [bind.yaml](bind.yaml)
- [nginx.yaml](nginx.yaml)
- [prometheus.yaml](prometheus.yaml)

## Ansible config

Expand Down
12 changes: 12 additions & 0 deletions prometheus.yaml
@@ -0,0 +1,12 @@
- name: Runs the prometheus role
hosts: all

pre_tasks:
- import_tasks: include/common_pre_tasks.yml

roles:
- role: prometheus

module_defaults:
apt:
force_apt_get: yes
7 changes: 7 additions & 0 deletions roles/prometheus/defaults/main.yml
@@ -0,0 +1,7 @@
prometheus_etc_prometheus_path: '{{ inventory_dir }}/overrides/{{ inventory_hostname }}/prometheus/etc/prometheus'

#
# Variables below this line typically do not have to be modified.
#
prometheus_yml_path: '{{ prometheus_etc_prometheus_path }}/prometheus.yml'
prometheus_alerting_rules_yaml_path: '{{ prometheus_etc_prometheus_path }}/alerting_rules.yaml'
6 changes: 6 additions & 0 deletions roles/prometheus/handlers/main.yml
@@ -0,0 +1,6 @@
- name: Reload or start the Prometheus service
systemd:
name: prometheus.service
state: reloaded
listen: reload_prometheus
become: true
29 changes: 29 additions & 0 deletions roles/prometheus/tasks/main.yml
@@ -0,0 +1,29 @@
- name: Install/update Prometheus
ansible.builtin.package:
name:
- prometheus

# Deliberately not using 'state: latest' to avoid unexpected surprises when
# e.g. deploying updated configuration.
state: present
become: true

- name: Copy prometheus.yml to /etc/prometheus
ansible.builtin.copy:
src: '{{ prometheus_yml_path }}'
dest: /etc/prometheus/prometheus.yml
owner: root
group: root
mode: 0644
become: true
notify: reload_prometheus

- name: Copy alerting_rules.yaml to /etc/prometheus
ansible.builtin.copy:
src: '{{ prometheus_alerting_rules_yaml_path }}'
dest: /etc/prometheus/alerting_rules.yaml
owner: root
group: root
mode: 0644
become: true
notify: reload_prometheus

0 comments on commit 1d9e360

Please sign in to comment.