# Required Python packages:
#
# ansible
# openstackclient
# openstacksdk

- ansible.builtin.import_playbook: common.yaml

- hosts: all
  gather_facts: no

  tasks:
  - name: 'List the containers associated with the cluster'
    ansible.builtin.command:
      cmd: "openstack container list --prefix {{ os_infra_id }} -f value -c Name"
    register: container_list

  - name: 'Delete the containers associated with the cluster'
    ansible.builtin.command:
      cmd: "openstack container delete -r {{ container_list.stdout }}"
    when: container_list.stdout|length > 0
