---
- block:
    - name: Download kubeclt executable used to compare results
      get_url:
        url: https://dl.k8s.io/release/v1.21.3/bin/linux/amd64/kubectl
        dest: "{{ kubectl_path }}"

    - name: make kubectl executable
      ansible.builtin.file:
        path: "{{ kubectl_path }}"
        mode: "+x"

    # Ensure namespace and create pod to perform tests on
    - name: Ensure namespace exists
      k8s:
        definition:
          apiVersion: v1
          kind: Namespace
          metadata:
            name: "{{ copy_namespace }}"

    - name: Create Pods
      k8s:
        namespace: '{{ copy_namespace }}'
        wait: yes
        template: pods_definition.j2

    - include_tasks: test_copy_errors.yml
    - include_tasks: test_copy_file.yml
    - include_tasks: test_multi_container_pod.yml
    - include_tasks: test_copy_directory.yml
    - include_tasks: test_copy_large_file.yml

  always:
    - name: Remove kubectl executable
      ansible.builtin.file:
        path: "{{ kubectl_path }}"
        state: absent
      ignore_errors: true

    - name: Remove namespace
      k8s:
        kind: Namespace
        name: "{{ copy_namespace }}"
        state: absent
      ignore_errors: true
