- name: Create values directory
  file:
    path: "{{ values_dir }}"
    state: directory
    mode: "0755"

- name: Install helm repos
  shell: |
    helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
    helm repo add grafana https://grafana.github.io/helm-charts
    helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
    helm repo update
  args:
    executable: /bin/bash

- name: Copy values files
  copy:
    src: "{{ item.src }}"
    dest: "{{ values_dir }}/{{ item.dest }}"
    mode: "0644"
  with_items:
    - { src: "../../../helm/values/kube-prometheus-stack.values.yaml", dest: "kube-prometheus-stack.values.yaml" }
    - { src: "../../../helm/values/loki.values.yaml", dest: "loki.values.yaml" }
    - { src: "../../../helm/values/otel-collector.values.yaml", dest: "otel-collector.values.yaml" }
    - { src: "../../../helm/mcp-telemetry-bridge/values.yaml", dest: "mcp-telemetry-bridge.values.yaml" }

- name: Deploy kube-prometheus-stack
  shell: |
    helm upgrade --install monitoring prometheus-community/kube-prometheus-stack       -n {{ telemcp_namespace_monitoring }} --create-namespace       -f {{ values_dir }}/kube-prometheus-stack.values.yaml
  args: { executable: /bin/bash }

- name: Deploy Loki
  shell: |
    helm upgrade --install loki grafana/loki       -n {{ telemcp_namespace_logging }} --create-namespace       -f {{ values_dir }}/loki.values.yaml
  args: { executable: /bin/bash }

- name: Deploy Promtail
  shell: |
    helm upgrade --install promtail grafana/promtail       -n {{ telemcp_namespace_logging }} --create-namespace
  args: { executable: /bin/bash }

- name: (Optional) Deploy OpenTelemetry Collector
  shell: |
    helm upgrade --install otel-collector open-telemetry/opentelemetry-collector       -n observability --create-namespace       -f {{ values_dir }}/otel-collector.values.yaml
  args: { executable: /bin/bash }

- name: Deploy MCP Telemetry Bridge
  shell: |
    helm upgrade --install mcp-telemetry {{ playbook_dir }}/../helm/mcp-telemetry-bridge       -n {{ telemcp_namespace_mcp }} --create-namespace       -f {{ values_dir }}/mcp-telemetry-bridge.values.yaml
  args: { executable: /bin/bash }
