Mohammed Naser | 707e65b | 2023-01-29 20:22:06 -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: Suspend project |
| 16 | hosts: controllers |
| 17 | become: true |
| 18 | gather_facts: false |
| 19 | vars_prompt: |
| 20 | - name: project_name |
| 21 | prompt: "Project name" |
| 22 | private: false |
| 23 | tasks: |
| 24 | - name: Disable the project |
| 25 | run_once: true |
| 26 | openstack.cloud.project: |
| 27 | cloud: atmosphere |
| 28 | name: "{{ project_name }}" |
| 29 | enabled: false |
| 30 | register: _project |
| 31 | |
| 32 | - name: Get list of regions with compute service |
| 33 | changed_when: false |
| 34 | run_once: true |
Tadas Sutkaitis | 7a28658 | 2024-05-01 02:12:08 +0300 | [diff] [blame] | 35 | ansible.builtin.shell: | |
| 36 | set -o posix |
| 37 | source /etc/profile.d/atmosphere.sh |
Mohammed Naser | 707e65b | 2023-01-29 20:22:06 -0500 | [diff] [blame] | 38 | openstack endpoint list \ |
| 39 | --service compute \ |
| 40 | --interface public \ |
| 41 | --column Region \ |
| 42 | --format value |
Tadas Sutkaitis | 7a28658 | 2024-05-01 02:12:08 +0300 | [diff] [blame] | 43 | args: |
| 44 | executable: /bin/bash |
Mohammed Naser | 707e65b | 2023-01-29 20:22:06 -0500 | [diff] [blame] | 45 | environment: |
| 46 | OS_CLOUD: atmosphere |
| 47 | register: _regions |
| 48 | |
| 49 | - name: Get list of VMs in the project in each region |
| 50 | changed_when: false |
| 51 | run_once: true |
Tadas Sutkaitis | 7a28658 | 2024-05-01 02:12:08 +0300 | [diff] [blame] | 52 | ansible.builtin.shell: | |
| 53 | set -o posix |
| 54 | source /etc/profile.d/atmosphere.sh |
Mohammed Naser | 707e65b | 2023-01-29 20:22:06 -0500 | [diff] [blame] | 55 | openstack server list \ |
| 56 | --no-name-lookup \ |
| 57 | --project "{{ project_name }}" \ |
| 58 | --status ACTIVE \ |
| 59 | --column ID \ |
| 60 | --format value |
Tadas Sutkaitis | 7a28658 | 2024-05-01 02:12:08 +0300 | [diff] [blame] | 61 | args: |
| 62 | executable: /bin/bash |
Mohammed Naser | 707e65b | 2023-01-29 20:22:06 -0500 | [diff] [blame] | 63 | environment: |
| 64 | OS_AUTH_URL: "https://{{ openstack_helm_endpoints_keystone_api_host }}" |
| 65 | OS_USERNAME: "admin-{{ openstack_helm_endpoints_region_name }}" |
| 66 | OS_PASSWORD: "{{ openstack_helm_endpoints_keystone_admin_password }}" |
| 67 | OS_PROJECT_NAME: admin |
| 68 | OS_USER_DOMAIN_NAME: Default |
| 69 | OS_PROJECT_DOMAIN_NAME: Default |
| 70 | OS_REGION_NAME: "{{ item }}" |
| 71 | register: _servers |
| 72 | loop: "{{ _regions.stdout_lines }}" |
| 73 | |
| 74 | - name: Suspend VMs in each region |
| 75 | run_once: true |
Tadas Sutkaitis | 7a28658 | 2024-05-01 02:12:08 +0300 | [diff] [blame] | 76 | ansible.builtin.shell: | |
| 77 | set -o posix |
| 78 | source /etc/profile.d/atmosphere.sh |
Mohammed Naser | 707e65b | 2023-01-29 20:22:06 -0500 | [diff] [blame] | 79 | openstack server suspend {{ item.1 }} |
Tadas Sutkaitis | 7a28658 | 2024-05-01 02:12:08 +0300 | [diff] [blame] | 80 | args: |
| 81 | executable: /bin/bash |
Mohammed Naser | 707e65b | 2023-01-29 20:22:06 -0500 | [diff] [blame] | 82 | environment: |
| 83 | OS_AUTH_URL: "https://{{ openstack_helm_endpoints_keystone_api_host }}" |
| 84 | OS_USERNAME: "admin-{{ openstack_helm_endpoints_region_name }}" |
| 85 | OS_PASSWORD: "{{ openstack_helm_endpoints_keystone_admin_password }}" |
| 86 | OS_PROJECT_NAME: admin |
| 87 | OS_USER_DOMAIN_NAME: Default |
| 88 | OS_PROJECT_DOMAIN_NAME: Default |
| 89 | OS_REGION_NAME: "{{ item.0.item }}" |
| 90 | with_subelements: |
| 91 | - "{{ _servers.results }}" |
| 92 | - stdout_lines |
| 93 | loop_control: |
| 94 | label: "{{ item.0.item }}/{{ item.1 }}" |