xoxys.scan2mail/molecule/centos7/destroy.yml

55 lines
1.5 KiB
YAML
Raw Normal View History

2019-08-25 18:18:43 +00:00
---
- name: Destroy
hosts: localhost
connection: local
gather_facts: false
2019-10-18 12:50:04 +00:00
no_log: "{{ molecule_no_log }}"
2019-08-25 18:18:43 +00:00
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: Destroy molecule instance(s)
2019-10-18 12:50:04 +00:00
digital_ocean_droplet:
name: "{{ item.instance }}"
id: "{{ item.droplet_id }}"
2019-08-25 18:18:43 +00:00
state: absent
register: server
2019-10-18 12:50:04 +00:00
loop: "{{ instance_conf | flatten(levels=1) }}"
2019-08-25 18:18:43 +00:00
when: not skip_instances
async: 7200
poll: 0
- name: Wait for instance(s) deletion to complete
async_status:
jid: "{{ item.ansible_job_id }}"
2019-10-18 12:50:04 +00:00
register: digitalocean_jobs
until: digitalocean_jobs.finished
2019-08-25 18:18:43 +00:00
retries: 300
2019-10-18 12:50:04 +00:00
loop: "{{ server.results }}"
- name: Delete remote keypair
digital_ocean_sshkey:
fingerprint: "{{ item.ssh_key_id }}"
state: absent
loop: "{{ instance_conf | flatten(levels=1) }}"
2019-08-25 18:18:43 +00:00
# Mandatory configuration for Molecule to function.
- name: Populate instance config
set_fact:
instance_conf: {}
- name: Dump instance config
copy:
2019-10-18 12:50:04 +00:00
content: "{{ instance_conf | molecule_to_yaml | molecule_header }}"
2019-08-25 18:18:43 +00:00
dest: "{{ molecule_instance_config }}"
when: server.changed | bool