Mohammed Naser | 388aaaa | 2023-02-03 12:55:31 -0500 | [diff] [blame] | 1 | # Copyright (c) 2022 VEXXHOST, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | - name: Terminate project |
| 16 | hosts: controllers |
| 17 | become: true |
| 18 | gather_facts: false |
| 19 | vars_prompt: |
| 20 | - name: project_id |
| 21 | prompt: "Project name" |
| 22 | private: false |
| 23 | pre_tasks: |
| 24 | - name: Ensure that `ospurge` is installed |
| 25 | run_once: true |
| 26 | ansible.builtin.pip: |
| 27 | # https://review.opendev.org/c/x/ospurge/+/872665 |
| 28 | name: git+https://opendev.org/x/ospurge.git@fef70ecd8b51694d28a16d56fe95139043d972c1#egg=ospurge |
| 29 | state: present |
| 30 | tasks: |
| 31 | - name: Get list of regions with compute service |
| 32 | changed_when: false |
| 33 | run_once: true |
Tadas Sutkaitis | 7a28658 | 2024-05-01 02:12:08 +0300 | [diff] [blame] | 34 | ansible.builtin.shell: | |
| 35 | set -o posix |
| 36 | source /etc/profile.d/atmosphere.sh |
Mohammed Naser | 388aaaa | 2023-02-03 12:55:31 -0500 | [diff] [blame] | 37 | openstack endpoint list \ |
| 38 | --service compute \ |
| 39 | --interface public \ |
| 40 | --column Region \ |
| 41 | --format value |
Tadas Sutkaitis | 7a28658 | 2024-05-01 02:12:08 +0300 | [diff] [blame] | 42 | args: |
| 43 | executable: /bin/bash |
Mohammed Naser | 388aaaa | 2023-02-03 12:55:31 -0500 | [diff] [blame] | 44 | environment: |
| 45 | OS_CLOUD: atmosphere |
| 46 | register: _regions |
| 47 | |
| 48 | - name: Run a dry run of ospurge |
| 49 | run_once: true |
| 50 | ansible.builtin.command: |
| 51 | ospurge \ |
| 52 | --admin-role-name member \ |
| 53 | --verbose \ |
| 54 | --purge-project {{ project_id }} \ |
| 55 | --dry-run |
| 56 | environment: |
| 57 | OS_AUTH_URL: "https://{{ openstack_helm_endpoints_keystone_api_host }}" |
| 58 | OS_USERNAME: "admin-{{ openstack_helm_endpoints_region_name }}" |
| 59 | OS_PASSWORD: "{{ openstack_helm_endpoints_keystone_admin_password }}" |
| 60 | OS_PROJECT_NAME: admin |
| 61 | OS_USER_DOMAIN_NAME: Default |
| 62 | OS_PROJECT_DOMAIN_NAME: Default |
| 63 | OS_REGION_NAME: "{{ item }}" |
| 64 | loop: "{{ _regions.stdout_lines }}" |
| 65 | async: 60 |
| 66 | poll: 0 |
| 67 | register: _ospurge_dryrun |
| 68 | |
| 69 | - name: Wait for the async task to finish |
| 70 | run_once: true |
| 71 | ansible.builtin.async_status: |
| 72 | jid: "{{ item.ansible_job_id }}" |
| 73 | loop: "{{ _ospurge_dryrun.results }}" |
| 74 | register: job_result |
| 75 | until: job_result.finished |
| 76 | retries: 60 |
| 77 | delay: 1 |
| 78 | |
| 79 | - name: Confirm purge, press enter to continue |
| 80 | ansible.builtin.pause: |
| 81 | prompt: |- |
| 82 | {% for region in job_result.results %} |
| 83 | {{ region.item.item }}: |
| 84 | {{ region.stderr }} |
| 85 | |
| 86 | {% endfor %} |
| 87 | Press enter to continue or CTRL+C to cancel |
| 88 | |
| 89 | - name: Run ospurge |
| 90 | run_once: true |
| 91 | ansible.builtin.command: |
| 92 | ospurge \ |
| 93 | --admin-role-name member \ |
| 94 | --verbose \ |
| 95 | --purge-project {{ project_id }} \ |
| 96 | environment: |
| 97 | OS_AUTH_URL: "https://{{ openstack_helm_endpoints_keystone_api_host }}" |
| 98 | OS_USERNAME: "admin-{{ openstack_helm_endpoints_region_name }}" |
| 99 | OS_PASSWORD: "{{ openstack_helm_endpoints_keystone_admin_password }}" |
| 100 | OS_PROJECT_NAME: admin |
| 101 | OS_USER_DOMAIN_NAME: Default |
| 102 | OS_PROJECT_DOMAIN_NAME: Default |
| 103 | OS_REGION_NAME: "{{ item }}" |
| 104 | loop: "{{ _regions.stdout_lines }}" |
| 105 | async: 600 |
| 106 | poll: 0 |
| 107 | register: _ospurge |
| 108 | |
| 109 | - name: Wait for the async task to finish |
| 110 | run_once: true |
| 111 | ansible.builtin.async_status: |
| 112 | jid: "{{ item.ansible_job_id }}" |
| 113 | loop: "{{ _ospurge.results }}" |
| 114 | loop_control: |
| 115 | label: "{{ item.item }}" |
| 116 | register: job_result |
| 117 | until: job_result.finished |
| 118 | retries: 600 |
| 119 | delay: 1 |
| 120 | |
| 121 | - name: Print ospurge output |
| 122 | run_once: true |
| 123 | ansible.builtin.debug: |
Mohammed Naser | c14fd11 | 2023-02-03 13:30:09 -0500 | [diff] [blame] | 124 | msg: "{{ item.stderr_lines }}" |
Mohammed Naser | 388aaaa | 2023-02-03 12:55:31 -0500 | [diff] [blame] | 125 | loop: "{{ job_result.results }}" |
Mohammed Naser | c14fd11 | 2023-02-03 13:30:09 -0500 | [diff] [blame] | 126 | loop_control: |
| 127 | label: "{{ item.item.item }}" |
Mohammed Naser | 388aaaa | 2023-02-03 12:55:31 -0500 | [diff] [blame] | 128 | |
| 129 | - name: Delete the OpenStack project |
| 130 | run_once: true |
| 131 | openstack.cloud.project: |
| 132 | name: "{{ project_id }}" |
| 133 | state: absent |