---
- name: Clone Openstack Virtual Baremetal repo if it does not exist
  git:
    repo: https://git.openstack.org/openstack/openstack-virtual-baremetal.git
    dest: "{{ local_working_dir }}/openstack-virtual-baremetal"
    version: "{{ ovb_repo_version }}"

- name: copy clouds.yaml file
  template:
    src: clouds.yaml.j2
    dest: "{{ local_working_dir }}/clouds.yaml"
    mode: 0755

- name: Remove stack
  os_stack:
    name: "{{ stack_name }}"
    cloud: "{{ cloud_name }}"
    state: absent
  environment:
    OS_CLIENT_CONFIG_FILE: "{{ local_working_dir }}/clouds.yaml"
  ignore_errors: true

- name: Remove associated keypair
  shell: >
      export OS_USERNAME="{{ os_username }}";
      export OS_PASSWORD="{{ os_password }}";
      export OS_TENANT_NAME="{{ os_tenant_name }}";
      export OS_AUTH_URL="{{ os_auth_url }}";
      nova keypair-delete key-{{ idnum }}
  ignore_errors: true
  no_log: true

- name: remove clouds.yaml file
  file:
    path: "{{ local_working_dir }}/clouds.yaml"
    state: absent
