00_core.ymlΒΆ

---
- include_tasks: utils/once/flag.yml

- name: "πŸ”Œ Stage the MCP adapter instance for {{ application_id }}"
  ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/svc-ai-mcp-adapter/tasks/instance.yml') }}"
  vars:
    mcp_adapter_instance_dir: "{{ PROMETHEUS_MCP_INSTANCE_DIR }}"
  when: PROMETHEUS_MCP_ENABLED | bool

- name: "🧩 Load the container CLI the data root probe calls"
  include_role:
    name: sys-svc-container
    public: false
  when: run_once_sys_svc_container is not defined

- name: "πŸ”Ž Read the docker data root cAdvisor has to bind"
  ansible.builtin.command: container info --format '{{ "{{" }}.DockerRootDir{{ "}}" }}'
  register: prometheus_docker_info
  changed_when: false
  delegate_to: "{{ STACK_HOST }}"

- name: "🧩 load docker and proxy for '{{ application_id }}'"
  include_role:
    name: sys-stk-backend
  vars:
    compose_handlers_flush: false

- name: "πŸ“ Ensure the node-exporter textfile directory exists"
  ansible.builtin.file:
    path: "{{ DIR_METRICS_TEXTFILE }}"
    state: directory
    mode: "0755"

- name: "πŸ“„ Render Prometheus config files (local + swarm peers)"
  ansible.builtin.include_tasks:
    file: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/render_replicated_templates.yml') }}"
  vars:
    role_templates:
      - src: "configuration/prometheus.yml.j2"
        dest: "{{ PROMETHEUS_CONFIG_HOST }}"
        mode: "0644"
      - src: "configuration/blackbox.yml.j2"
        dest: "{{ BLACKBOX_CONFIG_HOST }}"
        mode: "0644"
      - src: "configuration/alertmanager.yml.j2"
        dest: "{{ ALERTMANAGER_CONFIG_HOST }}"
        mode: "0644"
      - src: "configuration/alert_rules.yml.j2"
        dest: "{{ ALERT_RULES_CONFIG_HOST }}"
        mode: "0644"

- name: "πŸ“ Pre-create native-metrics docker networks (idempotent)"
  include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/network/create.yml') }}"
  vars:
    network_role_id: "{{ metrics_app }}"
  loop: "{{ lookup('native_metrics_apps') }}"
  loop_control:
    loop_var: metrics_app

- name: "🚿 flush handlers for '{{ application_id }}'"
  meta: flush_handlers

- name: "πŸ“‚ Include role sys-stk-front-proxy for '{{ application_id }}'"
  include_role:
    name: sys-stk-front-proxy
  vars:
    domain: "{{ lookup('domain', application_id) }}"
    http_port: "{{ lookup('config', application_id, 'services.prometheus.ports.local.http') }}"

- name: "πŸš€ Deploy prometheus nginx http-block config"
  stack_host_template:
    src: "roles/web-app-prometheus/templates/nginx/prometheus.conf.j2"
    dest: "{{ [ lookup('nginx','directories.configuration.global'), 'prometheus.conf' ] | path_join }}"
  notify: reload-openresty

- name: "🧱 Rebuild the MCP adapter of {{ application_id }}"
  ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/svc-ai-mcp-adapter/tasks/rebuild.yml') }}"
  when: PROMETHEUS_MCP_ENABLED | bool

- name: "🚿 Flush compose handlers for {{ application_id }}"
  ansible.builtin.meta: flush_handlers