mirror of
https://github.com/prometheus-community/ansible
synced 2024-11-22 11:53:12 +00:00
1e4e4c3415
Signed-off-by: gardar <gardar@users.noreply.github.com>
167 lines
4.7 KiB
YAML
167 lines
4.7 KiB
YAML
---
|
|
- name: Configure
|
|
ansible.builtin.include_role:
|
|
name: prometheus.prometheus._common
|
|
tasks_from: configure.yml
|
|
vars:
|
|
_common_system_user: "{{ prometheus_system_user }}"
|
|
_common_system_group: "{{ prometheus_system_group }}"
|
|
_common_config_dir: "{{ prometheus_config_dir }}"
|
|
_common_tls_server_config: "{{ prometheus_web_config.tls_server_config }}"
|
|
_common_http_server_config: "{{ prometheus_web_config.http_server_config }}"
|
|
_common_basic_auth_users: "{{ prometheus_web_config.basic_auth_users }}"
|
|
tags:
|
|
- prometheus
|
|
- configure
|
|
- prometheus_configure
|
|
|
|
- name: Create prometheus data directory
|
|
ansible.builtin.file:
|
|
path: "{{ prometheus_db_dir }}"
|
|
state: directory
|
|
owner: "{{ prometheus_system_user }}"
|
|
group: "{{ prometheus_system_group }}"
|
|
mode: 0755
|
|
become: true
|
|
tags:
|
|
- prometheus
|
|
- configure
|
|
- prometheus_configure
|
|
|
|
- name: Create additional prometheus configuration directories
|
|
ansible.builtin.file:
|
|
path: "{{ item }}"
|
|
state: directory
|
|
owner: "{{ prometheus_system_user }}"
|
|
group: "{{ prometheus_system_group }}"
|
|
mode: 0775
|
|
loop:
|
|
- "{{ prometheus_config_dir }}/rules"
|
|
- "{{ prometheus_config_dir }}/file_sd"
|
|
- "{{ prometheus_config_dir }}/scrapes"
|
|
become: true
|
|
tags:
|
|
- prometheus
|
|
- configure
|
|
- prometheus_configure
|
|
|
|
- name: Propagate official console templates
|
|
ansible.builtin.copy:
|
|
src: "{{ prometheus_local_cache_path }}/{{ item }}"
|
|
dest: "{{ prometheus_config_dir }}"
|
|
mode: 0644
|
|
owner: "{{ prometheus_system_user }}"
|
|
group: "{{ prometheus_system_group }}"
|
|
loop:
|
|
- console_libraries
|
|
- consoles
|
|
notify:
|
|
- restart prometheus
|
|
become: true
|
|
tags:
|
|
- prometheus
|
|
- configure
|
|
- prometheus_configure
|
|
|
|
- name: Alerting rules file
|
|
ansible.builtin.template:
|
|
src: "alert.rules.j2"
|
|
dest: "{{ prometheus_config_dir }}/rules/ansible_managed.rules"
|
|
owner: "{{ prometheus_system_user }}"
|
|
group: "{{ prometheus_system_group }}"
|
|
mode: 0640
|
|
validate: "{{ _prometheus_binary_install_dir }}/promtool check rules %s"
|
|
when:
|
|
- prometheus_alert_rules != []
|
|
- not prometheus_agent_mode
|
|
notify:
|
|
- reload prometheus
|
|
become: true
|
|
tags:
|
|
- prometheus
|
|
- configure
|
|
- prometheus_configure
|
|
|
|
- name: Copy custom alerting rule files
|
|
ansible.builtin.copy:
|
|
src: "{{ item }}"
|
|
dest: "{{ prometheus_config_dir }}/rules/"
|
|
owner: "{{ prometheus_system_user }}"
|
|
group: "{{ prometheus_system_group }}"
|
|
mode: 0640
|
|
validate: "{{ _prometheus_binary_install_dir }}/promtool check rules %s"
|
|
loop: "{{ prometheus_alert_rules_files | map('ansible.builtin.fileglob') | flatten }}"
|
|
when:
|
|
- not prometheus_agent_mode
|
|
notify:
|
|
- reload prometheus
|
|
become: true
|
|
tags:
|
|
- prometheus
|
|
- configure
|
|
- prometheus_configure
|
|
|
|
- name: Configure prometheus
|
|
ansible.builtin.template:
|
|
src: "{{ prometheus_config_file }}"
|
|
dest: "{{ prometheus_config_dir }}/prometheus.yml"
|
|
force: true
|
|
owner: "{{ prometheus_system_user }}"
|
|
group: "{{ prometheus_system_group }}"
|
|
mode: 0640
|
|
validate: "{{ _prometheus_binary_install_dir }}/promtool check config %s"
|
|
no_log: "{{ false if (lookup('env', 'CI')) or (lookup('env', 'MOLECULE_PROVISIONER_NAME')) else true }}"
|
|
notify:
|
|
- reload prometheus
|
|
become: true
|
|
tags:
|
|
- prometheus
|
|
- configure
|
|
- prometheus_configure
|
|
|
|
- name: Configure prometheus static targets
|
|
ansible.builtin.copy:
|
|
content: |
|
|
{{ item.value | to_nice_yaml(indent=2, sort_keys=False) }}
|
|
dest: "{{ prometheus_config_dir }}/file_sd/{{ item.key }}.yml"
|
|
force: true
|
|
owner: "{{ prometheus_system_user }}"
|
|
group: "{{ prometheus_system_group }}"
|
|
mode: 0640
|
|
loop: "{{ prometheus_targets | dict2items }}"
|
|
when: prometheus_targets != {}
|
|
become: true
|
|
tags:
|
|
- prometheus
|
|
- configure
|
|
- prometheus_configure
|
|
|
|
- name: Copy prometheus custom static targets
|
|
ansible.builtin.copy:
|
|
src: "{{ item }}"
|
|
dest: "{{ prometheus_config_dir }}/file_sd/"
|
|
force: true
|
|
owner: "{{ prometheus_system_user }}"
|
|
group: "{{ prometheus_system_group }}"
|
|
mode: 0640
|
|
loop: "{{ prometheus_static_targets_files | map('ansible.builtin.fileglob') | flatten }}"
|
|
become: true
|
|
tags:
|
|
- prometheus
|
|
- configure
|
|
- prometheus_configure
|
|
|
|
- name: Copy prometheus scrape config files
|
|
ansible.builtin.copy:
|
|
src: "{{ item }}"
|
|
dest: "{{ prometheus_config_dir }}/scrapes/"
|
|
force: true
|
|
owner: "{{ prometheus_system_user }}"
|
|
group: "{{ prometheus_system_group }}"
|
|
mode: 0640
|
|
loop: "{{ prometheus_scrape_config_files | map('ansible.builtin.fileglob') | flatten }}"
|
|
become: true
|
|
tags:
|
|
- prometheus
|
|
- configure
|
|
- prometheus_configure
|