- name: Setup Prometheus User user: name: "{{prometheus_user}}" home: "{{prometheus_home_dir}}" state: present - set_fact: "prometheus_extract_dir=prometheus-{{prometheus_version}}.{{prometheus_os}}-{{prometheus_architecture}}" - name: Create configuration directory file: state: directory dest: "{{prometheus_home_dir}}/conf" mode: '0700' owner: "{{prometheus_user}}" - name: Create Data directory file: state: directory dest: "{{prometheus_data_dir}}" mode: '0700' owner: "{{prometheus_user}}" - name: Download Prometheus get_url: url: "{{prometheus_url}}" dest: "{{prometheus_home_dir}}/prometheus-{{prometheus_version}}.tgz" mode: '0600' owner: "{{prometheus_user}}" checksum: 'sha256:{{prometheus_checksum}}' # There's a bug in become_user that doesn't set permissions on the temp directory # which is asinine when my user has sudo persmissions. - name: Extract Prometheus shell: | #!/bin/sh set -e if ! [ -e "{{prometheus_home_dir}}/{{prometheus_extract_dir}}" ] ; then su - '{{prometheus_user}}' -c 'cd "{{prometheus_home_dir}}"; tar xzf prometheus-{{prometheus_version}}.tgz' exit 50 fi register: res changed_when: res is defined and res.rc == 50 # failed_when: res is defined and ( res.rc != 50 or res.rc != 0 ) ignore_errors: true notify: Restart Prometheus - name: Link prometheus directory file: state: link src: '{{prometheus_extract_dir}}' dest: '{{prometheus_home_dir}}/prometheus' force: yes - name: Link configuration files file: state: link src: '../conf/{{item}}' dest: '{{prometheus_home_dir}}/prometheus/{{item}}' force: yes loop: - prometheus.yml - name: Write prometheus configuration file copy: content: '{{prometheus_config | to_nice_json}}' dest: '{{prometheus_home_dir}}/conf/prometheus.yml' owner: '{{prometheus_user}}' mode: '0600' notify: Restart prometheus tags: - configuration - name: Write prometheus web configuration file copy: content: '{{prometheus_web_config | to_nice_json}}' dest: '{{prometheus_home_dir}}/conf/web_conf.yml' owner: '{{prometheus_user}}' mode: '0600' when: prometheus_web_config is defined notify: Restart prometheus tags: - configuration - name: Write other config files copy: content: '{{item.content}}' dest: '{{prometheus_home_dir}}/conf/{{item.filename}}' owner: '{{prometheus_user}}' mode: '0600' loop: '{{prometheus_other_config | dict2items(key_name="filename", value_name="content")}}' when: prometheus_other_config is defined notify: Restart prometheus tags: - configuration - name: Create Runit Directory file: state: directory dest: /etc/sv/prometheus owner: root mode: '0755' - name: Write runit service template: src: prometheus.runit dest: /etc/sv/prometheus/run owner: root mode: '0755' tags: - configuration - name: Enable Runit service file: state: link src: /etc/sv/prometheus dest: /var/service/prometheus - name: Include Aertmanager tasks include_tasks: file: alertmanager.yml apply: tags: - alertmanager tags: - alertmanager when: alertmanager - name: Include Blackbox Exporter tasks include_tasks: file: blackbox.yml apply: tags: - blackbox tags: - blackbox when: blackbox_exporter - name: Include Discord tasks include_tasks: file: discord.yml apply: tags: - discord tags: - discord when: alertmanager_discord