xoxys.smb/molecule/centos7/destroy.yml

72 lines
2.1 KiB
YAML
Raw Normal View History

2020-01-25 23:09:27 +00:00
---
- name: Destroy
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
tasks:
- block:
- name: Populate instance config
set_fact:
instance_conf: "{{ lookup('file', molecule_instance_config) | molecule_from_yaml }}"
skip_instances: false
rescue:
- name: Populate instance config when file missing
set_fact:
instance_conf: {}
skip_instances: true
- name: Detach block storage from instance
digital_ocean_block_storage:
state: absent
command: attach
volume_name: "{{ item.instance }}-blk"
region: "{{ item.droplet_region }}"
droplet_id: "{{ item.droplet_id }}"
loop: "{{ instance_conf | flatten(levels=1) }}"
- name: Destroy molecule instance(s)
digital_ocean_droplet:
name: "{{ item.instance }}"
id: "{{ item.droplet_id }}"
state: absent
register: server
loop: "{{ instance_conf | flatten(levels=1) }}"
when: not skip_instances
async: 7200
poll: 0
- name: Wait for instance(s) deletion to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: digitalocean_jobs
until: digitalocean_jobs.finished
retries: 300
loop: "{{ server.results }}"
- name: Delete block storage
digital_ocean_block_storage:
state: absent
command: create
region: "{{ item.droplet_region }}"
volume_name: "{{ item.instance }}-blk"
loop: "{{ instance_conf | flatten(levels=1) }}"
- name: Delete remote keypair
digital_ocean_sshkey:
fingerprint: "{{ item.ssh_key_id }}"
state: absent
loop: "{{ instance_conf | flatten(levels=1) }}"
# Mandatory configuration for Molecule to function.
- name: Populate instance config
set_fact:
instance_conf: {}
- name: Dump instance config
copy:
content: "{{ instance_conf | molecule_to_yaml | molecule_header }}"
dest: "{{ molecule_instance_config }}"
when: server.changed | bool