---
- name: 1. yaml file install (sc, pv)
  kubernetes.core.k8s:
    state: present
    namespace: "{{ cmoa_namespace }}"
    src: "{{ role_path }}/files/01-storage/{{ item }}"
    apply: yes
  with_items:
    - 00-storageclass.yaml
    - 01-persistentvolume.yaml

- name: 2. helmchart install (minio)
  kubernetes.core.helm:
    name: "{{item}}"
    release_namespace: "{{ cmoa_namespace }}"
    chart_ref: "{{ role_path }}/files/01-storage/{{item}}"
    create_namespace: yes
    release_state: present
    values_files:
    - "{{ role_path }}/files/01-storage/{{item}}/values.yaml"
    values:
      image:
        repository: "{{ REGISTRY }}/minio"
      mcImage:
        repository: "{{ REGISTRY }}/mc"
  with_items:
    - minio

- name: 3. Change a Minio Api Service (NodePort=minio_nodePort)
  kubernetes.core.k8s:
    state: present
    definition:
      apiVersion: v1
      kind: Service
      metadata:
        name: "{{ minio_service_name }}"
        namespace: "{{ cmoa_namespace }}"
      spec:
        type: NodePort
        ports:
        - protocol: TCP
          port: "{{ minio_service_port }}"
          nodePort: "{{ minio_nodePort }}"
    apply: yes

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

- name: 5. minio setting (minio)
  command: "{{ role_path }}/files/01-storage/cmoa_minio {{ ansible_default_ipv4.address }}:{{ minio_nodePort }} {{ minio_user }} {{ bucket_name }} {{ days }} {{ rule_id }}"
