- name: set prometheus_cfg set_fact: prometheus_cfg: "{{ prometheus_default_config | d({}) | combine(prometheus_config | d({}), recursive=true) }}" - name: install dependencies include_tasks: tasks/install_packages.yml vars: package: - prometheus - prometheus-snmp-exporter - name: create user and group include_tasks: tasks/create_user.yml vars: user: name: "{{ prometheus_user }}" group: "{{ prometheus_group }}" - name: create directories file: path: "{{ item }}" state: directory mode: 0750 owner: "{{ prometheus_user }}" group: "{{ prometheus_group }}" loop: - "{{ prometheus_conf_dir }}" - "{{ prometheus_data_dir }}" - name: check if config file exists stat: path: "{{ prometheus_conf_file }}" register: file_exists - name: slurp existing config file slurp: src: "{{ prometheus_conf_file }}" register: existing_config when: file_exists.stat.exists no_log: yes - name: template prometheus config template: src: config.j2 dest: "{{ prometheus_conf_file }}" force: yes mode: 0600 owner: "{{ prometheus_user }}" group: "{{ prometheus_group }}" notify: restart prometheus when: not file_exists.stat.exists or (existing_config is defined and not (existing_config.content | b64decode) is search('managed by ansible')) - name: edit prometheus init config lineinfile: path: /etc/conf.d/prometheus regexp: '^{{ item.name }}=' line: '{{ item.name }}={{ item.value | quote }}' notify: restart prometheus loop: - { name: "prometheus_config_file", value: "{{ prometheus_conf_file }}" } - { name: "prometheus_storage_path", value: "{{ prometheus_data_dir }}" } - { name: "prometheus_retention_time", value: "{{ prometheus_retention_time | d('15d') }}" } - name: remove log entries from prometheus init config lineinfile: path: /etc/conf.d/prometheus regexp: '^{{ item }}=' state: absent notify: restart prometheus loop: - output_log - error_log - name: template prometheus init script template: src: init.j2 dest: /etc/init.d/prometheus force: yes mode: "+x" notify: restart prometheus - name: remove snmp-exporter init config file: path: /etc/conf.d/snmp-exporter state: absent notify: restart snmp-exporter - name: template snmp-exporter init script template: src: snmp_init.j2 dest: /etc/init.d/snmp-exporter force: yes mode: "+x" notify: restart snmp-exporter - name: add prometheus metric target include_role: name: prometheus vars: function: add_target target: name: self url: /metrics use_ip: yes ip: 127.0.0.1 port: "{{ prometheus_port }}" - name: install and configure nginx include_role: name: nginx vars: nginx: servers: - conf: nginx_server certs: "{{ host_tls }}" - name: flush handlers meta: flush_handlers - name: add directories to backup plan include_role: name: backup vars: function: add backup_items: - "{{ prometheus_conf_dir }}" - name: enable and start services service: name: "{{ item }}" enabled: yes state: started loop: - snmp-exporter - prometheus