---
- name: 1. kafka broker config apply (base)
  kubernetes.core.k8s:
    state: present
    namespace: "{{ cmoa_namespace }}"
    src: "{{ role_path }}/files/02-base/{{ item }}"
    apply: yes
  with_items:
    - 00-kafka-broker-config.yaml

- name: 2. coredns config apply (base)
  kubernetes.core.k8s:
    state: present
    namespace: default
    src: "{{ role_path }}/files/02-base/{{ item }}"
    apply: yes
  with_items:
    - 01-coredns.yaml

- name: 3. helmchart install (base)
  kubernetes.core.helm:
    name: "{{item}}"
    release_name: "{{item}}"
    release_namespace: "{{ cmoa_namespace }}"
    chart_ref: "{{ role_path }}/files/02-base/{{item}}"
    create_namespace: yes
    release_state: present
    values_files:
    - "{{ role_path }}/files/02-base/{{item}}/values.yaml"
    values:
      global:
        IMXC_IN_REGISTRY: "{{ REGISTRY }}/cmoa3"
        rabbitmq:
          image:
            registry: "{{ REGISTRY }}/cmoa3"
  with_items:
    - base

- name: 4. Check Kubernetes Pods (base)
  command: "{{ role_path }}/files/k8s_status {{ cmoa_namespace }} alertmanage"

- name: 5. Change a Elasticsearch Service (NodePort=elasticsearch_nodePort)
  kubernetes.core.k8s:
    state: present
    definition:
      apiVersion: v1
      kind: Service
      metadata:
        name: "{{ elasticsearch_service_name }}"
        namespace: "{{ cmoa_namespace }}"
      spec:
        type: NodePort
        ports:
        - protocol: TCP
          port: "{{ elasticsearch_service_port }}"
          nodePort: "{{ elasticsearch_nodePort }}"
    apply: yes

- name: 6. Change a Postgres Service (NodePort=postgres_nodePort)
  kubernetes.core.k8s:
    state: present
    definition:
      apiVersion: v1
      kind: Service
      metadata:
        name: "{{ postgres_service_name }}"
        namespace: "{{ cmoa_namespace }}"
      spec:
        type: NodePort
        ports:
        - protocol: TCP
          port: "{{ postgres_service_port }}"
          nodePort: "{{ postgres_nodePort }}"
    apply: yes
