- name: Set up Prometheus hosts: lotus-land-story vars_files: - vars.yml tasks: - name: Install host exporters ansible.builtin.apt: pkg: - prometheus-node-exporter - prometheus-postgres-exporter state: present # /usr/share/doc/prometheus-postgres-exporter/README.Debian - name: Configure postgres-exporter ansible.builtin.lineinfile: dest: /etc/default/prometheus-postgres-exporter regexp: '^DATA_SOURCE_NAME=' line: "DATA_SOURCE_NAME='user=prometheus host=/run/postgresql dbname=postgres'" state: present - name: Create Prometheus dir ansible.builtin.file: path: /mnt/lotus-land-story/prometheus state: directory owner: prometheus group: prometheus mode: "0755" - name: Prometheus config ansible.builtin.template: dest: /mnt/lotus-land-story/prometheus/prometheus.yml src: templates/prometheus.yml owner: prometheus group: prometheus mode: "0600" - name: Create Prometheus volume community.docker.docker_volume: name: prometheus - name: Get prometheus user info ansible.builtin.user: name: prometheus register: prometheus_user - name: Run Prometheus community.docker.docker_container: # recreate: true # restart: true name: prometheus image: prom/prometheus:v2.43.0 user: "{{ prometheus_user.uid }}" groups: "{{ prometheus_user.group }}" volumes: - /mnt/lotus-land-story/prometheus:/etc/prometheus - prometheus:/prometheus restart_policy: unless-stopped networks: - name: lotus_land_story etc_hosts: host.docker.internal: host-gateway # vim: ft=yaml.ansible