--- # Уничтожение инфраструктуры универсальной лаборатории # Автор: Сергей Антропов # Сайт: https://devops.org.ru - hosts: localhost gather_facts: false vars_files: - vars.yml tasks: - name: Remove DinD volumes community.docker.docker_volume: name: "{{ item.name }}-docker" state: absent loop: "{{ hosts | selectattr('type','defined') | selectattr('type','equalto','dind') | list }}" loop_control: label: "{{ item.name }}" ignore_errors: true - name: Remove containers community.docker.docker_container: name: "{{ item.name }}" state: absent force_kill: true loop: "{{ hosts }}" loop_control: label: "{{ item.name }}" ignore_errors: true - name: Remove network community.docker.docker_network: name: "{{ docker_network }}" state: absent ignore_errors: true - name: Remove kind clusters community.docker.docker_container_exec: container: ansible-controller command: > bash -lc ' set -e; for n in {{ (kind_clusters | default([]) | map(attribute="name") | list) | map('quote') | join(' ') }}; do if kind get clusters | grep -qx "$$n"; then echo "[kind] deleting $$n"; kind delete cluster --name "$$n" || true; fi done ' when: (kind_clusters | default([])) | length > 0 ignore_errors: true