---
# Tasks for app-of-apps configuration

# Create container-mom AppProject for hub cluster
- name: Create container-mom AppProject for hub cluster
  kubernetes.core.k8s:
    state: present
    definition:
      apiVersion: argoproj.io/v1alpha1
      kind: AppProject
      metadata:
        name: container-mom
        namespace: argocd
      spec:
        description: Container Mom Applications
        sourceRepos:
        - '*'
        destinations:
        - namespace: '*'
          server: '*'
        clusterResourceWhitelist:
        - group: '*'
          kind: '*'
        namespaceResourceWhitelist:
        - group: '*'
          kind: '*'
    kubeconfig: "{{ k8s_auth_params.kubeconfig }}"
    validate_certs: "{{ k8s_auth_params.validate_certs }}"
  when: is_hub_cluster | bool

# Configure app-of-apps
- name: Configure the Application of Applications (app-of-apps)
  kubernetes.core.k8s:
    state: present
    apply: true
    definition:
      apiVersion: argoproj.io/v1alpha1
      kind: Application
      metadata:
        name: app-of-apps
        namespace: argocd
      spec:
        destination:
          namespace: argocd
          server: https://kubernetes.default.svc
        project: default
        source:
          path: "manifests/00-argocd-app-of-apps-chart"
          repoURL: "{{ github_repo_url }}"
          targetRevision: main
        syncPolicy:
          automated:
            prune: false
            selfHeal: true
    kubeconfig: "{{ k8s_auth_params.kubeconfig }}"
    validate_certs: "{{ k8s_auth_params.validate_certs }}" 