---
- import_playbook: ../default/prepare.yml

- name: Prepare operator resources
  hosts: localhost
  connection: local
  vars:
    ansible_python_interpreter: '{{ ansible_playbook_python }}'
    deploy_dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/deploy"
  tasks:
  - name: Create Custom Resource Definition
    k8s:
      definition: "{{ lookup('file', '/'.join([deploy_dir, 'crds/smartgateway_v1alpha1_smartgateway_crd.yaml'])) }}"

  - name: Ensure specified namespace is present
    k8s:
      api_version: v1
      kind: Namespace
      name: '{{ namespace }}'

  - name: Create RBAC resources
    k8s:
      definition: "{{ lookup('template', '/'.join([deploy_dir, item])) }}"
      namespace: '{{ namespace }}'
    with_items:
      - role.yaml
      - role_binding.yaml
      - service_account.yaml
