2022-09-22 14:38:42 +00:00
|
|
|
---
|
2022-09-23 12:07:54 +00:00
|
|
|
- name: Create prometheus system group
|
|
|
|
ansible.builtin.group:
|
2022-09-22 14:38:42 +00:00
|
|
|
name: prometheus
|
|
|
|
system: true
|
|
|
|
state: present
|
|
|
|
|
2022-09-23 12:07:54 +00:00
|
|
|
- name: Create prometheus system user
|
|
|
|
ansible.builtin.user:
|
2022-09-22 14:38:42 +00:00
|
|
|
name: prometheus
|
|
|
|
system: true
|
|
|
|
shell: "/usr/sbin/nologin"
|
2022-12-08 17:45:42 +00:00
|
|
|
group: prometheus
|
2022-09-22 14:38:42 +00:00
|
|
|
createhome: false
|
|
|
|
home: "{{ prometheus_db_dir }}"
|
|
|
|
|
2022-09-23 12:07:54 +00:00
|
|
|
- name: Create prometheus data directory
|
|
|
|
ansible.builtin.file:
|
2022-09-22 14:38:42 +00:00
|
|
|
path: "{{ prometheus_db_dir }}"
|
|
|
|
state: directory
|
|
|
|
owner: prometheus
|
2022-12-08 17:45:42 +00:00
|
|
|
group: prometheus
|
2022-09-22 14:38:42 +00:00
|
|
|
mode: 0755
|
|
|
|
|
2022-09-23 12:07:54 +00:00
|
|
|
- name: Create prometheus configuration directories
|
|
|
|
ansible.builtin.file:
|
2022-09-22 14:38:42 +00:00
|
|
|
path: "{{ item }}"
|
|
|
|
state: directory
|
|
|
|
owner: root
|
2022-12-08 17:45:42 +00:00
|
|
|
group: prometheus
|
2022-09-22 14:38:42 +00:00
|
|
|
mode: 0770
|
|
|
|
with_items:
|
|
|
|
- "{{ prometheus_config_dir }}"
|
|
|
|
- "{{ prometheus_config_dir }}/rules"
|
|
|
|
- "{{ prometheus_config_dir }}/file_sd"
|
|
|
|
|
2022-11-25 10:37:52 +00:00
|
|
|
- name: Get prometheus binary
|
|
|
|
when:
|
|
|
|
- prometheus_binary_local_dir | length == 0
|
|
|
|
- not prometheus_skip_install
|
|
|
|
block:
|
|
|
|
|
|
|
|
- name: Download prometheus binary to local folder
|
2022-09-22 14:38:42 +00:00
|
|
|
become: false
|
2022-09-23 12:07:54 +00:00
|
|
|
ansible.builtin.get_url:
|
2023-02-22 17:20:00 +00:00
|
|
|
url: "{{ prometheus_binary_url }}"
|
2022-09-22 14:38:42 +00:00
|
|
|
dest: "/tmp/prometheus-{{ prometheus_version }}.linux-{{ go_arch }}.tar.gz"
|
|
|
|
checksum: "sha256:{{ __prometheus_checksum }}"
|
2022-11-25 13:53:37 +00:00
|
|
|
mode: 0644
|
2022-09-22 14:38:42 +00:00
|
|
|
register: _download_archive
|
|
|
|
until: _download_archive is succeeded
|
|
|
|
retries: 5
|
|
|
|
delay: 2
|
|
|
|
# run_once: true # <-- this cannot be set due to multi-arch support
|
|
|
|
delegate_to: localhost
|
|
|
|
check_mode: false
|
|
|
|
|
2022-11-25 10:37:52 +00:00
|
|
|
- name: Unpack prometheus binaries
|
2022-09-22 14:38:42 +00:00
|
|
|
become: false
|
2022-09-23 12:07:54 +00:00
|
|
|
ansible.builtin.unarchive:
|
2022-09-22 14:38:42 +00:00
|
|
|
src: "/tmp/prometheus-{{ prometheus_version }}.linux-{{ go_arch }}.tar.gz"
|
|
|
|
dest: "/tmp"
|
|
|
|
creates: "/tmp/prometheus-{{ prometheus_version }}.linux-{{ go_arch }}/prometheus"
|
|
|
|
delegate_to: localhost
|
|
|
|
check_mode: false
|
|
|
|
|
2022-11-25 10:37:52 +00:00
|
|
|
- name: Propagate official prometheus and promtool binaries
|
2022-09-23 12:07:54 +00:00
|
|
|
ansible.builtin.copy:
|
2022-09-22 14:38:42 +00:00
|
|
|
src: "/tmp/prometheus-{{ prometheus_version }}.linux-{{ go_arch }}/{{ item }}"
|
|
|
|
dest: "{{ _prometheus_binary_install_dir }}/{{ item }}"
|
|
|
|
mode: 0755
|
|
|
|
owner: root
|
2022-12-08 17:45:42 +00:00
|
|
|
group: root
|
2022-09-22 14:38:42 +00:00
|
|
|
with_items:
|
|
|
|
- prometheus
|
|
|
|
- promtool
|
|
|
|
notify:
|
|
|
|
- restart prometheus
|
|
|
|
|
2022-11-25 10:37:52 +00:00
|
|
|
- name: Propagate official console templates
|
2022-09-23 12:07:54 +00:00
|
|
|
ansible.builtin.copy:
|
2022-09-22 14:38:42 +00:00
|
|
|
src: "/tmp/prometheus-{{ prometheus_version }}.linux-{{ go_arch }}/{{ item }}/"
|
|
|
|
dest: "{{ prometheus_config_dir }}/{{ item }}/"
|
|
|
|
mode: 0644
|
|
|
|
owner: root
|
2022-12-08 17:45:42 +00:00
|
|
|
group: root
|
2022-09-22 14:38:42 +00:00
|
|
|
with_items:
|
|
|
|
- console_libraries
|
|
|
|
- consoles
|
|
|
|
notify:
|
|
|
|
- restart prometheus
|
|
|
|
|
2022-11-25 10:37:52 +00:00
|
|
|
- name: Propagate locally distributed prometheus and promtool binaries
|
2022-09-23 12:07:54 +00:00
|
|
|
ansible.builtin.copy:
|
2022-09-22 14:38:42 +00:00
|
|
|
src: "{{ prometheus_binary_local_dir }}/{{ item }}"
|
|
|
|
dest: "{{ _prometheus_binary_install_dir }}/{{ item }}"
|
|
|
|
mode: 0755
|
|
|
|
owner: root
|
2022-12-08 17:45:42 +00:00
|
|
|
group: root
|
2022-09-22 14:38:42 +00:00
|
|
|
with_items:
|
|
|
|
- prometheus
|
|
|
|
- promtool
|
|
|
|
when:
|
|
|
|
- prometheus_binary_local_dir | length > 0
|
|
|
|
- not prometheus_skip_install
|
|
|
|
notify:
|
|
|
|
- restart prometheus
|
|
|
|
|
2022-09-23 12:07:54 +00:00
|
|
|
- name: Create systemd service unit
|
|
|
|
ansible.builtin.template:
|
2022-09-22 14:38:42 +00:00
|
|
|
src: prometheus.service.j2
|
|
|
|
dest: /etc/systemd/system/prometheus.service
|
|
|
|
owner: root
|
2022-12-08 17:45:42 +00:00
|
|
|
group: root
|
2022-09-22 14:38:42 +00:00
|
|
|
mode: 0644
|
|
|
|
notify:
|
|
|
|
- restart prometheus
|
|
|
|
|
|
|
|
- name: Install SELinux dependencies
|
2022-09-23 12:07:54 +00:00
|
|
|
ansible.builtin.package:
|
2022-11-25 10:37:52 +00:00
|
|
|
name: "{{ _prometheus_selinux_packages }}"
|
2022-09-22 14:38:42 +00:00
|
|
|
state: present
|
|
|
|
register: _install_packages
|
|
|
|
until: _install_packages is succeeded
|
|
|
|
retries: 5
|
|
|
|
delay: 2
|
|
|
|
when:
|
|
|
|
- ansible_version.full is version('2.4', '>=')
|
|
|
|
- ansible_selinux.status == "enabled"
|
|
|
|
|
|
|
|
- name: Allow prometheus to bind to port in SELinux
|
2022-12-08 17:55:13 +00:00
|
|
|
community.general.seport:
|
2022-09-22 14:38:42 +00:00
|
|
|
ports: "{{ prometheus_web_listen_address.split(':')[1] }}"
|
|
|
|
proto: tcp
|
|
|
|
setype: http_port_t
|
|
|
|
state: present
|
|
|
|
when:
|
|
|
|
- ansible_version.full is version('2.4', '>=')
|
|
|
|
- ansible_selinux.status == "enabled"
|