87 lines
2.1 KiB
YAML
87 lines
2.1 KiB
YAML
---
|
|
- name: Install dependencies
|
|
apt:
|
|
name:
|
|
- wget
|
|
- tar
|
|
- curl
|
|
state: present
|
|
update_cache: yes
|
|
when: ansible_os_family == "Debian"
|
|
|
|
- name: Create prometheus user and group
|
|
user:
|
|
name: "{{ prometheus_user }}"
|
|
group: "{{ prometheus_group }}"
|
|
system: yes
|
|
create_home: no
|
|
|
|
- name: Create required directories
|
|
file:
|
|
path: "{{ item }}"
|
|
state: directory
|
|
owner: "{{ prometheus_user }}"
|
|
group: "{{ prometheus_group }}"
|
|
mode: '0755'
|
|
with_items:
|
|
- "{{ prometheus_install_dir }}"
|
|
- "{{ prometheus_data_dir }}"
|
|
- "{{ prometheus_config_dir }}"
|
|
|
|
- name: Download Prometheus
|
|
get_url:
|
|
url: "https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz"
|
|
dest: "/tmp/prometheus-{{ prometheus_version }}.tar.gz"
|
|
|
|
- name: Extract Prometheus
|
|
unarchive:
|
|
src: "/tmp/prometheus-{{ prometheus_version }}.tar.gz"
|
|
dest: "{{ prometheus_install_dir }}"
|
|
remote_src: yes
|
|
|
|
- name: Move binaries to /usr/local/bin
|
|
command:
|
|
cmd: mv "{{ prometheus_install_dir }}/prometheus-{{ prometheus_version }}.linux-amd64/{{ item }}" /usr/local/bin/
|
|
with_items:
|
|
- "prometheus"
|
|
- "promtool"
|
|
|
|
- name: Set ownership of Prometheus files
|
|
file:
|
|
path: "{{ item }}"
|
|
owner: "{{ prometheus_user }}"
|
|
group: "{{ prometheus_group }}"
|
|
recurse: yes
|
|
with_items:
|
|
- "{{ prometheus_install_dir }}"
|
|
- "{{ prometheus_data_dir }}"
|
|
- "{{ prometheus_config_dir }}"
|
|
|
|
- name: Copy prometheus.yml configuration
|
|
copy:
|
|
src: prometheus.yml
|
|
dest: "{{ prometheus_config_dir }}/prometheus.yml"
|
|
owner: "{{ prometheus_user }}"
|
|
group: "{{ prometheus_group }}"
|
|
mode: '0644'
|
|
notify:
|
|
- restart prometheus
|
|
|
|
- name: Copy systemd service file
|
|
copy:
|
|
src: prometheus.service
|
|
dest: /etc/systemd/system/prometheus.service
|
|
owner: root
|
|
group: root
|
|
mode: '0644'
|
|
|
|
- name: Reload systemd
|
|
systemd:
|
|
daemon_reload: yes
|
|
|
|
- name: Enable Prometheus service
|
|
systemd:
|
|
name: prometheus
|
|
enabled: yes
|
|
state: started
|