ansible-collection-prometheus/roles/prometheus/tasks/preflight.yml
gardar e99b807340
fix(lint): fatal lint errors
Signed-off-by: gardar <gardar@users.noreply.github.com>
2022-11-25 15:39:17 +00:00

114 lines
4.5 KiB
YAML

---
- name: Assert usage of systemd as an init system
ansible.builtin.assert:
that: ansible_service_mgr == 'systemd'
msg: "This module only works with systemd"
- name: Get systemd version
ansible.builtin.command: systemctl --version
changed_when: false
check_mode: false
register: __systemd_version
tags:
- skip_ansible_lint
- name: Set systemd version fact
ansible.builtin.set_fact:
prometheus_systemd_version: "{{ __systemd_version.stdout_lines[0].split(' ')[-1] }}"
- 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: Set prometheus external metrics path
ansible.builtin.set_fact:
prometheus_metrics_path: "/{{ (prometheus_web_external_url + '/metrics') | regex_replace('^(.*://)?(.*?)/') }}"
- 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 | json_query('[*][].file_sd_configs[*][].files[]') }}"
- 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 != []
- block:
- name: Get latest release
ansible.builtin.uri:
url: "https://api.github.com/repos/prometheus/prometheus/releases/latest"
method: GET
return_content: true
status_code: 200
body_format: json
validate_certs: false
ansible.builtin.user: "{{ lookup('env', 'GH_USER') | default(omit) }}"
password: "{{ lookup('env', 'GH_TOKEN') | default(omit) }}"
no_log: "{{ not lookup('env', 'ANSIBLE_DEBUG') | bool }}"
register: _latest_release
until: _latest_release.status == 200
retries: 5
- name: "Set prometheus version to {{ _latest_release.json.tag_name[1:] }}"
ansible.builtin.set_fact:
prometheus_version: "{{ _latest_release.json.tag_name[1:] }}"
when:
- prometheus_version == "latest"
- prometheus_binary_local_dir | length == 0
- not prometheus_skip_install
- block:
- name: "Get checksum list"
ansible.builtin.set_fact:
__prometheus_checksums: "{{ lookup('url', 'https://github.com/prometheus/prometheus/releases/download/v' + prometheus_version + '/sha256sums.txt', wantlist=True) | list }}"
run_once: true
- name: "Get checksum for {{ go_arch }}"
ansible.builtin.set_fact:
__prometheus_checksum: "{{ item.split(' ')[0] }}"
with_items: "{{ __prometheus_checksums }}"
when:
- "('linux-' + go_arch + '.tar.gz') in item"
delegate_to: localhost
when:
- prometheus_binary_local_dir | length == 0
- not prometheus_skip_install