Skip to content

Instantly share code, notes, and snippets.

@kwa29
Created January 2, 2018 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwa29/f647b234583834f9da65d1a190064942 to your computer and use it in GitHub Desktop.
Save kwa29/f647b234583834f9da65d1a190064942 to your computer and use it in GitHub Desktop.
Prometheus/tasks/main.yml
- 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