Created
January 2, 2018 14:28
-
-
Save kwa29/f647b234583834f9da65d1a190064942 to your computer and use it in GitHub Desktop.
Prometheus/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: Load specific variable from file | |
include_vars: "vars/{{ansible_hostname}}.yml" | |
- name: Load recording rules from file | |
include_vars: "vars/recording.rules.yml" | |
- name: Install docker-py pip package | |
pip: name=docker-py version="1.7.0" | |
when: | |
- not ansible_check_mode | |
- promcheck is not defined | |
- name: Create directories | |
file: path="{{item}}" state=directory | |
with_items: | |
- "{{prometheus_server_confdir}}" | |
- "{{prometheus_server_confdir}}/rules" | |
- "{{prometheus_server_confdir}}/check-config" | |
- "{{prometheus_server_confdir}}/check-config/rules" | |
- "{{prometheus_server_datadir}}" | |
- set_fact: prometheus_path="/etc/prometheus" | |
when: promcheck is not defined | |
- name: Deploy configuration file | |
template: src="prometheus.yml.j2" dest="{{prometheus_server_confdir}}/prometheus.yml" | |
notify: prometheus_server reload | |
when: promcheck is not defined | |
- name: Deploy alerting rules file | |
template: src="alerting.rules.j2" dest="{{prometheus_server_confdir}}/rules/alerting.rules" | |
notify: prometheus_server reload | |
when: | |
- promcheck is not defined | |
- "'prometheus_master' not in group_names" | |
- name: Deploy recording rules file | |
template: src="recording.rules.j2" dest="{{prometheus_server_confdir}}/rules/recording.rules" | |
notify: prometheus_server reload | |
when: | |
- promcheck is not defined | |
- "'prometheus_master' not in group_names" | |
- name: Deploy file targets | |
template: src="targetfile.yml.j2" dest="{{prometheus_server_confdir}}/{{item.name}}.yml" | |
with_items: "{{prometheus_server_filetargets}}" | |
when: | |
- prometheus_server_filetargets != None | |
- promcheck is not defined | |
- set_fact: prometheus_path="/etc/prometheus/check-config" | |
when: promcheck is defined | |
- name: Deploy configuration file on check config folder | |
template: src="prometheus.yml.j2" dest="{{prometheus_server_confdir}}/check-config/prometheus.yml" | |
when: promcheck is defined | |
- name: Deploy alerting rules file on check config folder | |
template: src="alerting.rules.j2" dest="{{prometheus_server_confdir}}/check-config/rules/alerting.rules" | |
when: promcheck is defined | |
- name: Deploy recording rules file on check config folder | |
template: src="recording.rules.j2" dest="{{prometheus_server_confdir}}/check-config/rules/recording.rules" | |
when: | |
- promcheck is defined | |
- "'prometheus_master' not in group_names" | |
- name: Deploy file targets on check config folder | |
template: src="targetfile.yml.j2" dest="{{prometheus_server_confdir}}/check-config/{{item.name}}.yml" | |
with_items: "{{prometheus_server_filetargets}}" | |
when: | |
- prometheus_server_filetargets != None | |
- promcheck is defined | |
- name: Syntax check of Prometheus config file | |
shell: docker exec prometheus_server promtool check-config /etc/prometheus/check-config/prometheus.yml > /dev/null | |
register: check_cmd | |
changed_when: False | |
failed_when: check_cmd.rc != 0 | |
tags: checkrule | |
when: promcheck is defined | |
- name: Start Prometheus Docker container | |
docker_container: | |
name: prometheus_server | |
image: "{{prometheus_server_image}}" | |
command: "-config.file=/etc/prometheus/prometheus.yml -storage.local.path=/prometheus -web.console.libraries=/usr/share/prometheus/console_libraries -web.console.templates=/usr/share/prometheus/consoles {{prometheus_server_options}}" | |
ports: | |
- "9090:9090" | |
volumes: | |
- "{{prometheus_server_confdir}}:/etc/prometheus" | |
- "{{prometheus_server_datadir}}:/prometheus" | |
etc_hosts: "{{prometheus_etc_hosts}}" | |
when: | |
- not ansible_check_mode | |
- promcheck is not defined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment