blob: 8088c498dbf7bef17dcd4f59ced743360f9e88a5 [file] [log] [blame]
Mohammed Naser707e65b2023-01-29 20:22:06 -05001# 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
35 ansible.builtin.shell:
36 openstack endpoint list \
37 --service compute \
38 --interface public \
39 --column Region \
40 --format value
41 environment:
42 OS_CLOUD: atmosphere
43 register: _regions
44
45 - name: Get list of VMs in the project in each region
46 changed_when: false
47 run_once: true
48 ansible.builtin.shell:
49 openstack server list \
50 --no-name-lookup \
51 --project "{{ project_name }}" \
52 --status ACTIVE \
53 --column ID \
54 --format value
55 environment:
56 OS_AUTH_URL: "https://{{ openstack_helm_endpoints_keystone_api_host }}"
57 OS_USERNAME: "admin-{{ openstack_helm_endpoints_region_name }}"
58 OS_PASSWORD: "{{ openstack_helm_endpoints_keystone_admin_password }}"
59 OS_PROJECT_NAME: admin
60 OS_USER_DOMAIN_NAME: Default
61 OS_PROJECT_DOMAIN_NAME: Default
62 OS_REGION_NAME: "{{ item }}"
63 register: _servers
64 loop: "{{ _regions.stdout_lines }}"
65
66 - name: Suspend VMs in each region
67 run_once: true
68 ansible.builtin.shell:
69 openstack server suspend {{ item.1 }}
70 environment:
71 OS_AUTH_URL: "https://{{ openstack_helm_endpoints_keystone_api_host }}"
72 OS_USERNAME: "admin-{{ openstack_helm_endpoints_region_name }}"
73 OS_PASSWORD: "{{ openstack_helm_endpoints_keystone_admin_password }}"
74 OS_PROJECT_NAME: admin
75 OS_USER_DOMAIN_NAME: Default
76 OS_PROJECT_DOMAIN_NAME: Default
77 OS_REGION_NAME: "{{ item.0.item }}"
78 with_subelements:
79 - "{{ _servers.results }}"
80 - stdout_lines
81 loop_control:
82 label: "{{ item.0.item }}/{{ item.1 }}"