mirror of
https://github.com/prometheus-community/ansible
synced 2024-11-26 05:40:18 +00:00
1e4e4c3415
Signed-off-by: gardar <gardar@users.noreply.github.com>
90 lines
3.5 KiB
YAML
90 lines
3.5 KiB
YAML
---
|
|
- name: Common preflight
|
|
ansible.builtin.include_role:
|
|
name: prometheus.prometheus._common
|
|
tasks_from: preflight.yml
|
|
|
|
- name: Assert that used version supports listen address type
|
|
ansible.builtin.assert:
|
|
that:
|
|
- >-
|
|
prometheus_web_listen_address is string
|
|
|
|
- name: Naive assertion of proper listen address
|
|
ansible.builtin.assert:
|
|
that:
|
|
- >-
|
|
[prometheus_web_listen_address] |
|
|
flatten |
|
|
reject('match', '.+:\\d+$') |
|
|
list |
|
|
length == 0
|
|
|
|
- name: Assert no duplicate config flags
|
|
ansible.builtin.assert:
|
|
that:
|
|
- prometheus_config_flags_extra['config.file'] is not defined
|
|
- prometheus_config_flags_extra['storage.tsdb.path'] is not defined
|
|
- prometheus_config_flags_extra['storage.local.path'] is not defined
|
|
- prometheus_config_flags_extra['web.listen-address'] is not defined
|
|
- prometheus_config_flags_extra['web.external-url'] is not defined
|
|
msg: "Detected duplicate configuration entry. Please check your ansible variables and role README.md."
|
|
|
|
- name: Assert external_labels aren't configured twice
|
|
ansible.builtin.assert:
|
|
that: prometheus_global.external_labels is not defined
|
|
msg: "Use prometheus_external_labels to define external labels"
|
|
|
|
- name: Fail when prometheus_config_flags_extra duplicates parameters set by other variables
|
|
ansible.builtin.fail:
|
|
msg: >
|
|
Whooops. You are duplicating configuration. Please look at your prometheus_config_flags_extra
|
|
and check against other variables in defaults/main.yml
|
|
with_items:
|
|
- 'storage.tsdb.retention'
|
|
- 'storage.tsdb.path'
|
|
- 'storage.local.retention'
|
|
- 'storage.local.path'
|
|
- 'config.file'
|
|
- 'web.listen-address'
|
|
- 'web.external-url'
|
|
when: item in prometheus_config_flags_extra.keys()
|
|
|
|
- name: Get all file_sd files from scrape_configs
|
|
ansible.builtin.set_fact:
|
|
file_sd_files: "{{ prometheus_scrape_configs | selectattr('file_sd_configs', 'defined') | map(attribute='file_sd_configs') |
|
|
flatten | map(attribute='files') | flatten }}"
|
|
|
|
- name: Fail when file_sd targets are not defined in scrape_configs
|
|
ansible.builtin.fail:
|
|
msg: >
|
|
Oh, snap! `{{ item.key }}` couldn't be found in your scrape configs. Please ensure you provided
|
|
all targets from prometheus_targets in prometheus_scrape_configs
|
|
when: not prometheus_config_dir + "/file_sd/" + item.key + ".yml" in file_sd_files
|
|
# when: not item | basename | splitext | difference(['.yml']) | join('') in prometheus_targets.keys()
|
|
with_dict: "{{ prometheus_targets }}"
|
|
|
|
- name: Alert when prometheus_alertmanager_config is empty, but prometheus_alert_rules is specified
|
|
ansible.builtin.debug:
|
|
msg: >
|
|
No alertmanager configuration was specified. If you want your alerts to be sent make sure to
|
|
specify a prometheus_alertmanager_config in defaults/main.yml.
|
|
when:
|
|
- prometheus_alertmanager_config == []
|
|
- prometheus_alert_rules != []
|
|
|
|
- name: Discover latest version
|
|
ansible.builtin.set_fact:
|
|
prometheus_version: "{{ (lookup('url', 'https://api.github.com/repos/{{ _prometheus_repo}}/releases/latest', headers=_github_api_headers,
|
|
split_lines=False) | from_json).get('tag_name') | replace('v', '') }}"
|
|
run_once: true
|
|
until: prometheus_version is version('0.0.0', '>=')
|
|
retries: 10
|
|
when:
|
|
- prometheus_version == "latest"
|
|
tags:
|
|
- prometheus
|
|
- install
|
|
- prometheus_install
|
|
- download
|
|
- prometheus_download
|