--- # Configure Prometheus to monitor Nginx - name: Create Nginx scrape configuration copy: content: | # Nginx metrics from stub_status - job_name: 'nginx' scrape_interval: 15s scrape_timeout: 10s metrics_path: /status static_configs: - targets: ['192.168.0.110:80'] labels: instance: 'app1-nginx' service: 'web-server' environment: 'test' metric_relabel_configs: - source_labels: [__address__] target_label: instance - source_labels: [__address__] regex: '([^:]+)(?::\d+)?' replacement: '${1}' target_label: hostname dest: /etc/prometheus/nginx.yml owner: root group: root mode: '0644' notify: reload prometheus - name: Include Nginx config in main prometheus.yml lineinfile: path: /etc/prometheus/prometheus.yml line: ' - "nginx.yml"' insertafter: 'rule_files:' state: present notify: reload prometheus