--- - name: "Include OS-specific variables" ansible.builtin.include_vars: "{{ ansible_facts['os_family'] | lower }}.yml" - name: "Create prometheus group" become: true ansible.builtin.group: name: "prometheus" system: true - name: "Create prometheus user" become: true ansible.builtin.user: name: "prometheus" group: "prometheus" system: true shell: "/usr/sbin/nologin" create_home: false - name: "Create prometheus directories" become: true ansible.builtin.file: path: "{{ item }}" state: "directory" owner: "prometheus" group: "prometheus" mode: "0755" loop: - "/etc/prometheus" - "/var/lib/prometheus" - name: "Install prometheus" become: true ansible.builtin.package: name: "prometheus" state: "present" - name: "Create prometheus configuration" become: true ansible.builtin.template: src: "prometheus.yml.j2" dest: "/etc/prometheus/prometheus.yml" owner: "prometheus" group: "prometheus" mode: "0644" notify: "Restart prometheus" # NOTE: show systemd configurations using: systemctl cat prometheus - name: "Configure prometheus host/port via environment file" become: true ansible.builtin.copy: content: | PROMETHEUS_ARGS="--web.listen-address={{ prometheus_host }}:{{ prometheus_port }}" dest: "{{ prometheus_env_file }}" mode: "0644" notify: "Restart prometheus" - name: "Start and enable prometheus" become: true ansible.builtin.systemd_service: name: "prometheus" state: "started" enabled: true - name: "Create prometheus nginx vhost configuration" become: true when: proxy_type == "nginx" and prometheus_hostname | length > 0 ansible.builtin.template: src: "prometheus.nginx.conf.j2" dest: "/etc/nginx/conf.d/prometheus.conf" owner: "root" group: "root" mode: "0644" backup: true validate: > bash -c 'echo "events { worker_connections 64; } http { include %s; }" > /tmp/nginx-vhost.conf; sudo nginx -T -c /tmp/nginx-vhost.conf; ec=$?; rm -f /tmp/nginx-vhost.conf; exit $ec' notify: "Restart proxy" - name: "Create prometheus caddy configuration" become: true when: proxy_type == "caddy" and prometheus_hostname | length > 0 ansible.builtin.template: src: "prometheus.caddy.j2" dest: "/etc/caddy/sites/prometheus.caddy" owner: "root" group: "caddy" mode: "0640" notify: "Restart proxy"