2017-12-05 05:58:34 +01:00
|
|
|
# Install Prometheus server.
|
|
|
|
#
|
|
|
|
# @see http://prometheus.io/docs/introduction/getting_started/
|
|
|
|
#
|
|
|
|
|
|
|
|
- name: set internal variables for convenience
|
|
|
|
set_fact:
|
|
|
|
prometheus_daemon_dir: "{{ prometheus_install_path }}/prometheus-{{ prometheus_version }}.linux-amd64"
|
|
|
|
prometheus_tarball_url: "https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz"
|
|
|
|
|
|
|
|
- name: set prometheus default options
|
|
|
|
set_fact:
|
|
|
|
prometheus_default_opts: "{{ prometheus_default_opts }} --web.console.templates={{ prometheus_daemon_dir }}/consoles --web.console.libraries={{ prometheus_daemon_dir }}/console_libraries"
|
|
|
|
|
|
|
|
- name: download and untar prometheus tarball
|
|
|
|
unarchive:
|
|
|
|
src: "{{ prometheus_tarball_url }}"
|
|
|
|
dest: "{{ prometheus_install_path }}"
|
|
|
|
copy: no
|
|
|
|
creates: "{{ prometheus_daemon_dir }}"
|
|
|
|
|
|
|
|
- name: create prometheus /usr/local/bin links
|
|
|
|
file:
|
|
|
|
src: "{{ prometheus_daemon_dir }}/{{ item }}"
|
|
|
|
dest: "/usr/local/bin/{{ item }}"
|
|
|
|
state: link
|
|
|
|
with_items:
|
|
|
|
- "prometheus"
|
|
|
|
- "promtool"
|
|
|
|
|
|
|
|
- name: mkdir for config and data
|
|
|
|
file:
|
|
|
|
path: "{{ item }}"
|
|
|
|
state: directory
|
|
|
|
owner: "{{ prometheus_user }}"
|
|
|
|
group: "{{ prometheus_group }}"
|
|
|
|
mode: "u=rwx,g=rx,o="
|
|
|
|
with_items:
|
|
|
|
- "{{ prometheus_rule_path }}"
|
|
|
|
- "{{ prometheus_file_sd_config_path }}"
|
|
|
|
- "{{ prometheus_db_path }}"
|
|
|
|
|
|
|
|
- name: copy prometheus systemd config
|
|
|
|
template:
|
|
|
|
src: "prometheus.service.j2"
|
|
|
|
dest: "/lib/systemd/system/prometheus.service"
|
2018-09-11 14:11:20 +02:00
|
|
|
notify:
|
|
|
|
- reload systemd
|
|
|
|
- restart prometheus
|
2017-12-05 05:58:34 +01:00
|
|
|
|
|
|
|
- name: copy rule files from playbook's, if any
|
|
|
|
copy:
|
|
|
|
src: "{{ playbook_dir }}/{{ item.value.src }}"
|
|
|
|
dest: "{{ prometheus_rule_path }}/{{ item.value.dest }}"
|
|
|
|
validate: "{{ prometheus_daemon_dir }}/promtool check rules %s"
|
|
|
|
with_dict: '{{ prometheus_rule_files | default({}) }}'
|
|
|
|
notify:
|
2018-09-11 14:11:20 +02:00
|
|
|
- restart prometheus
|
2017-12-05 05:58:34 +01:00
|
|
|
|
|
|
|
- name: copy prometheus main config file from role's default, if necessary
|
|
|
|
template:
|
|
|
|
src: "prometheus.yml.j2"
|
|
|
|
dest: "{{ prometheus_config_path }}/prometheus.yml"
|
|
|
|
validate: "{{ prometheus_daemon_dir }}/promtool check config %s"
|
|
|
|
when: prometheus_conf_main is not defined
|
|
|
|
notify:
|
2018-09-11 14:11:20 +02:00
|
|
|
- restart prometheus
|
2017-12-05 05:58:34 +01:00
|
|
|
|
|
|
|
- name: copy prometheus main config file from playbook's, if any
|
|
|
|
template:
|
|
|
|
src: "{{ playbook_dir }}/{{ prometheus_conf_main }}"
|
|
|
|
dest: "{{ prometheus_config_path }}/prometheus.yml"
|
|
|
|
validate: "{{ prometheus_daemon_dir }}/promtool check config %s"
|
|
|
|
when: prometheus_conf_main is defined
|
|
|
|
notify:
|
2018-09-11 14:11:20 +02:00
|
|
|
- restart prometheus
|
2017-12-05 05:58:34 +01:00
|
|
|
|
|
|
|
- name: enable prometheus service
|
|
|
|
service:
|
|
|
|
name: prometheus
|
|
|
|
enabled: yes
|
|
|
|
state: started
|