---
# Checking user defined variables
- import_tasks: pre-check.yaml

- name: Creating kubernetes namespaces
  shell: |
    kubectl create ns {{ item }} --dry-run=client -o yaml | kubectl apply -f -
  with_items:
    - "app"
    - "db"
    - "nginx-ingress"

- name: Creating docker secrets
  shell: |
    kubectl delete -n app secret aws-registry || true
    kubectl create secret -n app docker-registry aws-registry \
                  --docker-server="{{ docker_registry_url }}" \
                  --docker-username="{{ docker_registry_username }}" \
                  --docker-password="{{ docker_registry_password }}" \
                  --docker-email=no@email.local
  when: docker_registry_username|length != 0 and docker_registry_password|length != 0

# Creating helm override files.
- name: Creating override files
  template:
    dest: "/tmp/{{ item|basename }}"
    src: "{{ item }}"
  with_fileglob:
    - templates/*.yaml
  tags:
    - app
    - template

# Installing and initializing dbs
- import_tasks: install-dbs.yaml

# Installing and initializing apps
- import_tasks: install-apps.yaml
