ovh_instance_playbooks/roles/role_delete_openstack_instance/tasks/main.yml

56 lines
1.6 KiB
YAML
Raw Normal View History

2024-03-22 20:46:39 +00:00
---
# tasks file for role_delete_openstack_instance
2024-10-23 19:14:03 +00:00
- name: install python modules
ansible.builtin.pip:
2024-03-22 20:46:39 +00:00
name:
2024-10-23 19:14:03 +00:00
- openstacksdk==0.61.0
- ovh==1.1.0
2024-03-22 20:46:39 +00:00
- 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 }}"