fix setup issues and cleanup vars
This commit is contained in:
parent
95b4b9e747
commit
689580de5f
@ -12,8 +12,10 @@ prometheus_config_dir: "{{ prometheus_base_dir }}/conf"
|
|||||||
prometheus_rules_dir: "{{ prometheus_config_dir }}/rules"
|
prometheus_rules_dir: "{{ prometheus_config_dir }}/rules"
|
||||||
prometheus_file_sd_dir: "{{ prometheus_config_dir }}/file_sd"
|
prometheus_file_sd_dir: "{{ prometheus_config_dir }}/file_sd"
|
||||||
prometheus_data_dir: "{{ prometheus_base_dir }}/data"
|
prometheus_data_dir: "{{ prometheus_base_dir }}/data"
|
||||||
|
prometheus_read_only_dirs: []
|
||||||
|
|
||||||
prometheus_web_listen_address: "0.0.0.0:9090"
|
prometheus_web_bind_ip: 127.0.0.1
|
||||||
|
prometheus_web_bind_port: 9090
|
||||||
prometheus_web_external_url: ""
|
prometheus_web_external_url: ""
|
||||||
|
|
||||||
# @var prometheus_web_config:description: See official [documentation](https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md).
|
# @var prometheus_web_config:description: See official [documentation](https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md).
|
||||||
@ -98,7 +100,7 @@ prometheus_scrape_configs:
|
|||||||
- "{{ ansible_fqdn | default(ansible_host) | default('localhost') }}:9090"
|
- "{{ ansible_fqdn | default(ansible_host) | default('localhost') }}:9090"
|
||||||
|
|
||||||
prometheus_alert_rules_files:
|
prometheus_alert_rules_files:
|
||||||
- "{{ prometheus_rules_dir }}/*.rules"
|
- "prometheus/rules/*.rules"
|
||||||
|
|
||||||
prometheus_static_targets_files:
|
prometheus_static_targets_files:
|
||||||
- prometheus/targets/*.yml
|
- prometheus/targets/*.yml
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
- name: Destroy
|
- name: Destroy
|
||||||
hosts: localhost
|
hosts: localhost
|
||||||
@ -74,7 +73,6 @@
|
|||||||
content: |
|
content: |
|
||||||
# Molecule managed
|
# Molecule managed
|
||||||
|
|
||||||
{{ instance_conf | to_json | from_json | to_yaml }}
|
{{ instance_conf | to_nice_yaml(indent=2) }}
|
||||||
dest: "{{ molecule_instance_config }}"
|
dest: "{{ molecule_instance_config }}"
|
||||||
when: server.changed | bool
|
when: server.changed | bool
|
||||||
|
|
||||||
|
@ -1,11 +1,20 @@
|
|||||||
import os
|
import os
|
||||||
|
import warnings
|
||||||
|
|
||||||
import testinfra.utils.ansible_runner
|
import testinfra.utils.ansible_runner
|
||||||
|
|
||||||
import warnings
|
|
||||||
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||||
|
|
||||||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||||
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
os.environ["MOLECULE_INVENTORY_FILE"]).get_hosts("all")
|
||||||
|
|
||||||
|
|
||||||
|
def test_prometheus_running_and_enabled(host):
|
||||||
|
prometheus = host.service("prometheus")
|
||||||
|
assert prometheus.is_running
|
||||||
|
assert prometheus.is_enabled
|
||||||
|
|
||||||
|
|
||||||
|
def test_prometheus_socket(host):
|
||||||
|
# Verify the socket is listening for HTTP traffic
|
||||||
|
assert host.socket("tcp://127.0.0.1:61000").is_listening
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
- block:
|
- block:
|
||||||
- name: Allow prometheus to bind to port in SELinux
|
- name: Allow prometheus to bind to port in SELinux
|
||||||
seport:
|
seport:
|
||||||
ports: "{{ prometheus_web_listen_address.split(':')[1] }}"
|
ports: "{{ prometheus_web_bind_port }}"
|
||||||
proto: tcp
|
proto: tcp
|
||||||
setype: http_port_t
|
setype: http_port_t
|
||||||
state: present
|
state: present
|
||||||
|
@ -24,18 +24,25 @@
|
|||||||
unarchive:
|
unarchive:
|
||||||
src: "https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz"
|
src: "https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz"
|
||||||
dest: "{{ prometheus_base_dir }}"
|
dest: "{{ prometheus_base_dir }}"
|
||||||
|
extra_opts:
|
||||||
|
- --strip-components=1
|
||||||
remote_src: yes
|
remote_src: yes
|
||||||
# include:
|
include:
|
||||||
# - consoles/
|
- prometheus-{{ prometheus_version }}.linux-amd64/consoles/
|
||||||
# - console_libraries/
|
- prometheus-{{ prometheus_version }}.linux-amd64/console_libraries/
|
||||||
# - prometheus
|
- prometheus-{{ prometheus_version }}.linux-amd64/prometheus
|
||||||
# - promtool
|
- prometheus-{{ prometheus_version }}.linux-amd64/promtool
|
||||||
notify: __prometheus_restart
|
notify: __prometheus_restart
|
||||||
|
become: True
|
||||||
|
become_user: "{{ prometheus_user }}"
|
||||||
|
|
||||||
|
- block:
|
||||||
- name: Copy prometheus config file
|
- name: Copy prometheus config file
|
||||||
template:
|
template:
|
||||||
src: "conf/prometheus.yml.j2"
|
src: "conf/prometheus.yml.j2"
|
||||||
dest: "{{ prometheus_config_dir }}/prometheus.yml"
|
dest: "{{ prometheus_config_dir }}/prometheus.yml"
|
||||||
|
owner: "{{ prometheus_user }}"
|
||||||
|
group: "{{ prometheus_user }}"
|
||||||
mode: 0640
|
mode: 0640
|
||||||
validate: "{{ prometheus_base_dir }}/promtool check config %s"
|
validate: "{{ prometheus_base_dir }}/promtool check config %s"
|
||||||
notify: __prometheus_reload
|
notify: __prometheus_reload
|
||||||
@ -44,12 +51,16 @@
|
|||||||
copy:
|
copy:
|
||||||
content: "{{ prometheus_web_config | to_nice_yaml(indent=2) }}"
|
content: "{{ prometheus_web_config | to_nice_yaml(indent=2) }}"
|
||||||
dest: "{{ prometheus_config_dir }}/web.yml"
|
dest: "{{ prometheus_config_dir }}/web.yml"
|
||||||
|
owner: "{{ prometheus_user }}"
|
||||||
|
group: "{{ prometheus_user }}"
|
||||||
mode: 0640
|
mode: 0640
|
||||||
|
|
||||||
- name: Configure prometheus static targets
|
- name: Configure prometheus static targets
|
||||||
template:
|
template:
|
||||||
src: "conf/file_sd/sd.yml.j2"
|
src: "conf/file_sd/sd.yml.j2"
|
||||||
dest: "{{ prometheus_file_sd_dir }}/{{ item.name }}.yml"
|
dest: "{{ prometheus_file_sd_dir }}/{{ item.name }}.yml"
|
||||||
|
owner: "{{ prometheus_user }}"
|
||||||
|
group: "{{ prometheus_user }}"
|
||||||
mode: 0640
|
mode: 0640
|
||||||
loop: "{{ prometheus_targets }}"
|
loop: "{{ prometheus_targets }}"
|
||||||
|
|
||||||
@ -57,6 +68,8 @@
|
|||||||
copy:
|
copy:
|
||||||
src: "{{ item }}"
|
src: "{{ item }}"
|
||||||
dest: "{{ prometheus_file_sd_dir }}"
|
dest: "{{ prometheus_file_sd_dir }}"
|
||||||
|
owner: "{{ prometheus_user }}"
|
||||||
|
group: "{{ prometheus_user }}"
|
||||||
mode: 0640
|
mode: 0640
|
||||||
with_fileglob: "{{ prometheus_static_targets_files }}"
|
with_fileglob: "{{ prometheus_static_targets_files }}"
|
||||||
|
|
||||||
@ -64,23 +77,24 @@
|
|||||||
template:
|
template:
|
||||||
src: "conf/rules/alert.rules.j2"
|
src: "conf/rules/alert.rules.j2"
|
||||||
dest: "{{ prometheus_rules_dir }}/default.rules"
|
dest: "{{ prometheus_rules_dir }}/default.rules"
|
||||||
|
owner: "{{ prometheus_user }}"
|
||||||
|
group: "{{ prometheus_user }}"
|
||||||
mode: 0640
|
mode: 0640
|
||||||
validate: "{{ prometheus_base_dir }}/promtool check rules %s"
|
validate: "{{ prometheus_base_dir }}/promtool check rules %s"
|
||||||
when: prometheus_alert_rules + prometheus_alert_rules_extra | length > 0
|
when: (prometheus_alert_rules + prometheus_alert_rules_extra) | length > 0
|
||||||
notify: __prometheus_reload
|
notify: __prometheus_reload
|
||||||
|
|
||||||
- name: Copy custom alerting rule files
|
- name: Copy custom alerting rule files
|
||||||
copy:
|
copy:
|
||||||
src: "{{ item }}"
|
src: "{{ item }}"
|
||||||
dest: "{{ prometheus_rules_dir }}/"
|
dest: "{{ prometheus_rules_dir }}/"
|
||||||
|
owner: "{{ prometheus_user }}"
|
||||||
|
group: "{{ prometheus_user }}"
|
||||||
mode: 0640
|
mode: 0640
|
||||||
validate: "{{ prometheus_base_dir }}/promtool check rules %s"
|
validate: "{{ prometheus_base_dir }}/promtool check rules %s"
|
||||||
with_fileglob: "{{ prometheus_alert_rules_files }}"
|
with_fileglob: "{{ prometheus_alert_rules_files }}"
|
||||||
notify: __prometheus_reload
|
notify: __prometheus_reload
|
||||||
become: True
|
|
||||||
become_user: "{{ prometheus_user }}"
|
|
||||||
|
|
||||||
- block:
|
|
||||||
- name: Copy systemd unit file
|
- name: Copy systemd unit file
|
||||||
template:
|
template:
|
||||||
src: "etc/systemd/system/prometheus.service.j2"
|
src: "etc/systemd/system/prometheus.service.j2"
|
||||||
|
@ -4,4 +4,4 @@
|
|||||||
groups:
|
groups:
|
||||||
- name: Ansible managed alert rules
|
- name: Ansible managed alert rules
|
||||||
rules:
|
rules:
|
||||||
{{ prometheus_alert_rules + prometheus_alert_rules_extra | to_nice_yaml(indent=2) | indent(2,False) }}
|
{{ (prometheus_alert_rules + prometheus_alert_rules_extra) | to_nice_yaml(indent=2) | indent(2, False) }}
|
||||||
|
@ -19,7 +19,7 @@ ExecStart={{ prometheus_base_dir }}/prometheus \
|
|||||||
--web.config.file={{ prometheus_config_dir }}/web.yml \
|
--web.config.file={{ prometheus_config_dir }}/web.yml \
|
||||||
--web.console.libraries={{ prometheus_base_dir }}/console_libraries \
|
--web.console.libraries={{ prometheus_base_dir }}/console_libraries \
|
||||||
--web.console.templates={{ prometheus_base_dir }}/consoles \
|
--web.console.templates={{ prometheus_base_dir }}/consoles \
|
||||||
--web.listen-address={{ prometheus_web_listen_address }} \
|
--web.listen-address={{ prometheus_web_bind_ip }}:{{ prometheus_web_bind_port }} \
|
||||||
--web.external-url={{ prometheus_web_external_url }} \
|
--web.external-url={{ prometheus_web_external_url }} \
|
||||||
{% for flag in prometheus_config_flags_extra %}
|
{% for flag in prometheus_config_flags_extra %}
|
||||||
{% if flag.value is not defined %}
|
{% if flag.value is not defined %}
|
||||||
|
Loading…
Reference in New Issue
Block a user