--- - name: Prepare base folder file: path: "{{ prometheus_base_dir }}" state: directory owner: "{{ prometheus_user }}" group: "{{ prometheus_user }}" mode: 0750 become: True become_user: root - block: - name: Prepare folder structure file: path: "{{ item }}" state: directory mode: 0750 loop: - "{{ prometheus_config_dir }}" - "{{ prometheus_rules_dir }}" - "{{ prometheus_data_dir }}" - "{{ prometheus_file_sd_dir }}" - name: Download and extract Prometheus tarball unarchive: src: "https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz" dest: "{{ prometheus_base_dir }}" extra_opts: - --strip-components=1 remote_src: yes exclude: - prometheus-{{ prometheus_version }}.linux-amd64/LICENSE - prometheus-{{ prometheus_version }}.linux-amd64/NOTICE - prometheus-{{ prometheus_version }}.linux-amd64/prometheus.yml notify: __prometheus_restart when: prometheus_version is version(prometheus_current_version, ">") or prometheus_current_version is version('0.0.0', "=") become: True become_user: "{{ prometheus_user }}" - block: - name: Copy prometheus config file template: src: "conf/prometheus.yml.j2" dest: "{{ prometheus_config_dir }}/prometheus.yml" owner: "{{ prometheus_user }}" group: "{{ prometheus_user }}" mode: 0600 validate: "{{ prometheus_base_dir }}/promtool check config %s" notify: __prometheus_reload - name: Copy prometheus web config file template: src: "conf/web.yml.j2" dest: "{{ prometheus_config_dir }}/web.yml" owner: "{{ prometheus_user }}" group: "{{ prometheus_user }}" mode: 0640 validate: "{{ prometheus_base_dir }}/promtool check web-config %s" - name: Configure prometheus static targets template: src: "conf/file_sd/sd.yml.j2" dest: "{{ prometheus_file_sd_dir }}/{{ item.name }}.yml" owner: "{{ prometheus_user }}" group: "{{ prometheus_user }}" mode: 0640 loop: "{{ prometheus_targets }}" loop_control: label: "{{ item.name }}" - name: Copy prometheus custom static targets copy: src: "{{ item }}" dest: "{{ prometheus_file_sd_dir }}" owner: "{{ prometheus_user }}" group: "{{ prometheus_user }}" mode: 0640 with_fileglob: "{{ prometheus_static_targets_files }}" - name: Configure prometheus alerting rules template: src: "conf/rules/alert.rules.j2" dest: "{{ prometheus_rules_dir }}/default.rules" owner: "{{ prometheus_user }}" group: "{{ prometheus_user }}" mode: 0640 validate: "{{ prometheus_base_dir }}/promtool check rules %s" when: (prometheus_alert_rules + prometheus_alert_rules_extra) | length > 0 notify: __prometheus_reload - name: Copy custom alerting rule files copy: src: "{{ item }}" dest: "{{ prometheus_rules_dir }}/" owner: "{{ prometheus_user }}" group: "{{ prometheus_user }}" mode: 0640 validate: "{{ prometheus_base_dir }}/promtool check rules %s" with_fileglob: "{{ prometheus_alert_rules_files }}" notify: __prometheus_reload - name: Copy systemd unit file template: src: "etc/systemd/system/prometheus.service.j2" dest: "/etc/systemd/system/prometheus.service" mode: 0640 notify: __prometheus_restart - name: Ensure prometheus service is up and running systemd: name: prometheus daemon_reload: yes enabled: yes state: started - name: Set current version to custom fact template: src: etc/ansible/facts.d/prometheus.fact.j2 dest: /etc/ansible/facts.d/prometheus.fact mode: 0644 owner: root group: root when: prometheus_version is version(prometheus_current_version, ">") or prometheus_current_version is version('0.0.0', "=") become: True become_user: root