--- - name: Create group ansible.builtin.group: name: prometheus gid: 305 - name: Create user ansible.builtin.user: name: prometheus comment: Service Prometheus createhome: false group: prometheus home: /var/empty shell: /sbin/nologin uid: 305 - name: Install packages ansible.builtin.package: name: golang-github-prometheus state: installed - name: Create data directory ansible.builtin.file: path: /export/prometheus state: directory mode: "0770" owner: root group: prometheus - name: Link data directory ansible.builtin.file: path: /srv/prometheus src: /export/prometheus state: link owner: root group: "{{ ansible_wheel }}" follow: false - name: Configure startup options ansible.builtin.lineinfile: path: /etc/default/prometheus regexp: "^ARGS=" line: >- ARGS="--config.file=/etc/prometheus/prometheus.yml --log.level=info --storage.tsdb.path=/srv/prometheus --storage.tsdb.retention.time=365d --web.console.libraries=/usr/local/share/prometheus/console_libraries" notify: Restart prometheus - name: Create configuration ansible.builtin.template: dest: /etc/prometheus/prometheus.yml src: prometheus.yml.j2 mode: "0640" owner: root group: prometheus notify: Restart prometheus - name: Create host config directory ansible.builtin.file: path: /etc/prometheus/node.d state: directory mode: "0750" owner: root group: prometheus - name: Create host configs ansible.builtin.template: dest: "/etc/prometheus/node.d/{{ item }}.json" src: node.json.j2 mode: "0640" owner: root group: prometheus notify: Restart prometheus with_items: "{{ groups['all'] }}" - name: Enable service ansible.builtin.service: name: prometheus state: started enabled: true - name: Allow nginx to connect prometheus ansible.posix.seboolean: name: httpd_can_network_connect state: true persistent: true - name: Copy nginx config ansible.builtin.copy: dest: "/etc/nginx/conf.d/{{ inventory_hostname }}/prometheus.conf" content: | location / { proxy_pass http://127.0.0.1:9090; } mode: "0644" owner: root group: "{{ ansible_wheel }}" notify: Restart nginx