Files

93 lines
2.3 KiB
YAML

- name: Download and verify the prometheus archive
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 }}.linux-amd64.tar.gz"
checksum: "sha256:{{ prometheus_sha256 }}"
register: download_result
- name: Unarchive prometheus binary
unarchive:
src: "{{ download_result.dest }}"
dest: /tmp
remote_src: true # Indicates the source file is on the remote host
owner: root
group: root
mode: 0755
- name: Copy prometheus binary to /usr/local/bin
copy:
src: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64/prometheus"
dest: "/usr/local/bin/prometheus-{{ prometheus_version }}"
owner: root
group: root
mode: '0755'
remote_src: yes
- name: Create prometheus binary symlink
file:
src: "/usr/local/bin/prometheus-{{ prometheus_version }}"
dest: "/usr/local/bin/prometheus"
state: link
owner: root
group: root
mode: '0755' # Permissions for the target file
force: yes
- name: Create a prometheus group
group:
name: prometheus
state: present
gid: 1051
- name: Create a prometheus user
user:
name: prometheus
uid: 1051
group: 1051
comment: "prometheus user"
shell: /bin/bash
state: present
create_home: no
- name: Create prometheus data and config directories
file:
path: "{{ item }}"
state: directory
mode: 0750
owner: prometheus
group: prometheus
loop:
- /var/lib/prometheus
- /etc/prometheus
- name: Install prometheus config
template:
src: templates/prometheus.yml.j2
dest: /etc/prometheus/prometheus.yml
owner: prometheus
group: prometheus
mode: '0640'
notify: Restart prometheus
- name: Install prometheus service
template:
src: templates/prometheus.service.j2
dest: /etc/systemd/system/prometheus.service
owner: root
group: root
mode: 0640
register: prometheus_service
notify: Restart prometheus
- name: systemctl daemon-reload to pickup prometheus service changes
systemd_service:
daemon_reload: true
when: prometheus_service.changed
notify: Restart prometheus
- name: Start and enable prometheus
service:
name: prometheus
state: started
enabled: true