ovh_instance_playbooks/roles/role_delete_openstack_instance/tasks/main.yml
2024-10-23 21:14:03 +02:00

56 lines
1.6 KiB
YAML

---
# tasks file for role_delete_openstack_instance
- name: install python modules
ansible.builtin.pip:
name:
- openstacksdk==0.61.0
- ovh==1.1.0
- name: delete instance
openstack.cloud.server:
name: "{{ target_name }}"
state: absent
region_name: "{{ OS_REGION_NAME }}"
environment:
OS_AUTH_URL: "{{ OS_AUTH_URL }}"
OS_USERNAME: "{{ OS_USERNAME }}"
OS_PASSWORD: "{{ OS_PASSWORD }}"
OS_USER_DOMAIN_NAME: "{{ OS_USER_DOMAIN_NAME }}"
register: openstack_output
- name: Find {{ target_name }} volumes
openstack.cloud.volume_info:
register: volumes_info
environment:
OS_AUTH_URL: "{{ OS_AUTH_URL }}"
OS_USERNAME: "{{ OS_USERNAME }}"
OS_PASSWORD: "{{ OS_PASSWORD }}"
OS_USER_DOMAIN_NAME: "{{ OS_USER_DOMAIN_NAME }}"
OS_REGION_NAME: "{{ OS_REGION_NAME }}"
- name: remove {{ target_name }} volumes
openstack.cloud.volume:
state: absent
name: "{{ item }}"
with_items: "{{ volumes_info.volumes|json_query('[].[name]') }}"
when: item is search('^' ~ target_name.split('.')[0] ~ '-')
environment:
OS_AUTH_URL: "{{ OS_AUTH_URL }}"
OS_USERNAME: "{{ OS_USERNAME }}"
OS_PASSWORD: "{{ OS_PASSWORD }}"
OS_USER_DOMAIN_NAME: "{{ OS_USER_DOMAIN_NAME }}"
OS_REGION_NAME: "{{ OS_REGION_NAME }}"
- name: Remove A server record
ovh_dns:
state: absent
domain: "{{ DOMAIN }}"
name: "{{ target_name.split('.')[0] }}"
type: A
environment:
OVH_ENDPOINT: ovh-eu
OVH_APPLICATION_KEY: "{{ OVH_APPLICATION_KEY }}"
OVH_APPLICATION_SECRET: "{{ OVH_APPLICATION_SECRET }}"
OVH_CONSUMER_KEY: "{{ OVH_DNS_CONSUMER_KEY }}"