--- - name: "Delete minikube cluster" ansible.builtin.command: argv: - "{{ minikube_binary }}" - -p - "{{ item.key }}" - delete register: delete_test_res changed_when: False loop: "{{ minikube_profiles | dict2items }}" loop_control: label: "{{ item.key }}" when: (item.value.destroy | bool ) and not ( item.value.create | bool) - name: "Cleanup kubeconfig files" ansible.builtin.file: path: "{{ playbook_dir }}/.kube/{{ item.key }}.kubeconfig" state: absent loop: "{{ minikube_profiles | dict2items }}" loop_control: label: "{{ item.key }}" when: (item.value.destroy | bool ) and not ( item.value.create | bool) register: kubeconfig_cleanup - name: "Debug Delete Cluster" debug: var: delete_test_res when: kubeconfig_cleanup.changed - name: "Fail when not cleaned" fail: msg: "Error while deleting minikube resources" when: delete_test_res.changed and item.rc != 0 loop: "{{ delete_test_res.results }}" loop_control: label: "{{ item.item.key }}"