# NOTE: be aware that if the API version changes for the ServiceTelemetry
# object that it'll need to be updated here
- name: Create default ServiceTelemetry manifest
  set_fact:
    service_telemetry_manifest: |
      apiVersion: infra.watch/v1beta1
      kind: ServiceTelemetry
      metadata:
        name: default
        namespace: "{{ namespace }}"
      spec:
        alerting:
          alertmanager:
            storage:
              strategy: {{ "ephemeral" if __service_telemetry_storage_ephemeral_enabled else "persistent" }}
            receivers:
              snmpTraps:
                enabled: {{ __service_telemetry_snmptraps_enabled }}
        backends:
          events:
            elasticsearch:
              enabled: {{ __service_telemetry_events_enabled }}
              storage:
                strategy: {{ "ephemeral" if __service_telemetry_storage_ephemeral_enabled else "persistent" }}
          metrics:
            prometheus:
              enabled: {{ __service_telemetry_metrics_enabled }}
              storage:
                strategy: {{ "ephemeral" if __service_telemetry_storage_ephemeral_enabled else "persistent" }}
        highAvailability:
          enabled: {{ __service_telemetry_high_availability_enabled }}
  when: service_telemetry_manifest is not defined

- name: Show ServiceTelemetry manifest
  debug:
    var: service_telemetry_manifest | from_yaml

- name: Create ServiceTelemetry instance
  k8s:
    definition:
      '{{ service_telemetry_manifest }}'
