4
4
hosts : localhost
5
5
vars :
6
6
prefix : rds-
7
- volume_type : " ultrahigh"
7
+ test_router_name : " apimon-test-rds-router"
8
+ test_network_name : " apimon-test-rds-network"
9
+ test_subnet_name : " apimon-test-rds-subnet"
10
+ test_security_group_name : " apimon-test-rds-sg"
8
11
9
12
tasks :
10
- # Random selection between MySQL and PostgreSQL db engine
11
- - name : Random selection of DB type
12
- set_fact :
13
- db_type : " {{ ['mysql', 'postgresql'] | random }}"
14
-
15
- # Query all present versions of previously selected DB engine
16
- - name : Get datastore info
17
- opentelekomcloud.cloud.rds_datastore_info :
18
- datastore : " {{ db_type }}"
19
- register : versions
20
-
21
- - name : debug datastores
22
- debug :
23
- var : versions.rds_datastores
24
-
25
- - name : Run Python script to find the latest version
26
- script : " latest_rds_version.py '{{ versions.rds_datastores | to_nice_json }}'"
27
- args :
28
- executable : python3
29
- register : latest_version_output
30
-
31
- - name : Get the latest version of DB
32
- set_fact :
33
- db_version : " {{ latest_version_output.stdout }}"
34
-
35
- - debug :
36
- msg : " DB type is {{ db_type }} version {{ db_version }}"
37
-
38
13
# Set random ID of the run
39
14
- name : Set random ID of the run
40
15
set_fact :
48
23
# Set all neccessary names combine with prefix
49
24
- set_fact :
50
25
test_rds_name : " {{ prefix }}"
51
- test_router_name : " {{ ('vpc_'+ prefix + '-router')}}"
52
- test_subnet_name : " {{ ('vpc_'+ prefix + '-subnet')}}"
53
- test_network_name : " {{ ('vpc_'+ prefix + '-network')}}"
54
- test_security_group_name : " {{ (prefix + '-sg') }}"
55
26
password : " {{ ('Test8*' + prefix)[:20] }}" # Ensure the password is within 20 characters
56
27
28
+ # Query all available Availability zones
29
+ - name : Get Availability zones
30
+ opentelekomcloud.cloud.availability_zone_info :
31
+ register : azs
32
+
33
+ # Random selection of AZ
34
+ - name : Get a random availability zone name
35
+ set_fact :
36
+ random_az : " {{ azs.availability_zones | map(attribute='name') | list | random }}"
37
+
38
+ # Random selection between MySQL and PostgreSQL db engine
39
+ - name : Random selection of DB type
40
+ set_fact :
41
+ db_type : " {{ ['mysql', 'postgresql'] | random }}"
42
+
43
+ # Query all present versions of previously selected DB engine
44
+ - name : Get datastore info
45
+ opentelekomcloud.cloud.rds_datastore_info :
46
+ datastore : " {{ db_type }}"
47
+ register : versions
57
48
58
49
# Query all flavoers for specific DB engine
59
50
- name : Get info about choosen type of DB
60
51
opentelekomcloud.cloud.rds_flavor_info :
61
- datastore : " {{ db_type }}"
62
- instance_mode : " ha "
52
+ datastore : " {{ db_type }}"
53
+ instance_mode : " single "
63
54
register : rds_flavors
64
55
65
- # Print the first flavor in the query
66
- - name : debug
67
- ansible.builtin.debug :
68
- msg : " {{ rds_flavors.rds_flavors[0].name }}"
69
-
70
- - debug :
71
- msg : " Using prefix {{ prefix }}"
72
-
56
+ # Run python script to get Region, Storage type and Latest version of DB engine
57
+ - name : Run Python script to find the latest version
58
+ script : >
59
+ {{ playbook_dir }}/files/rds_preconditions.py
60
+ '{{ db_type }}'
61
+ '{{ versions.rds_datastores | to_nice_json }}'
62
+ '{{ rds_flavors.rds_flavors | to_nice_json }}'
63
+ '{{ random_az }}'
64
+ args :
65
+ executable : python3
66
+ register : script_output
67
+
68
+ - name : Parse JSON output from script
69
+ set_fact :
70
+ script_vars : " {{ script_output.stdout | from_json }}"
73
71
72
+ - name : Set region, storage_type, and latest_version
73
+ set_fact :
74
+ region : " {{ script_vars.region }}"
75
+ storage_type : " {{ script_vars.storage_type }}"
76
+ latest_version : " {{ script_vars.latest_version }}"
77
+ smallest_flavor : " {{ script_vars.smallest_flavor }}"
78
+
79
+ - name : Display region and storage_type
80
+ debug :
81
+ msg :
82
+ - " Prefix: {{ prefix }}"
83
+ - " Region: {{ region }}"
84
+ - " AZ " : " {{ random_az }}"
85
+ - " Storage Type: {{ storage_type }}"
86
+ - " DB Type: {{ db_type }}"
87
+ - " Latest vesion: {{ latest_version }}"
88
+ - " Smallest flavor: {{ smallest_flavor }}"
89
+
90
+
74
91
- block :
75
- # Create VPC and SUBNET
76
- - name : Create VPC (Router + Net + Subnet)
92
+ # Check if the VPC (Router + Network + Subnet) exists
93
+ - name : Check if Network exists
94
+ openstack.cloud.networks_info :
95
+ name : " {{ test_network_name }}"
96
+ register : network_check
97
+
98
+ # Create VPC and Subnet only if the network doesn't exist
99
+ - name : Create VPC (Router + Net + Subnet) if it doesn't exist
77
100
include_role :
78
101
name : opentelekomcloud.vpc
79
102
vars :
82
105
subnet_name : " {{ test_subnet_name }}"
83
106
state : present
84
107
85
- # Create Security Group
86
- - name : Create SecurityGroup
108
+ # Check if the Security Group exists
109
+ - name : Check if Security Group exists
110
+ openstack.cloud.security_group_info :
111
+ name : " {{ test_security_group_name }}"
112
+ register : sg_check
113
+
114
+ # Create Security Group only if it doesn't exist
115
+ - name : Create Security Group if it doesn't exist
87
116
openstack.cloud.security_group :
88
117
name : " {{ test_security_group_name }}"
89
118
description : RDS test SG created by APImon
90
119
91
- # Query all available Availability zones
92
- - name : Get Availability zones
93
- opentelekomcloud.cloud.availability_zone_info :
94
- # name: "{{ region }}"
95
- register : azs
96
-
97
120
# Create RDS instance MySQL
98
121
- name : Create RDS instance MySQL
99
122
when : db_type == "mysql"
100
123
opentelekomcloud.cloud.rds_instance :
101
124
name : " {{ test_rds_name }}"
102
125
state : present
103
- availability_zone : " {{ azs['availability_zones'][0]['name'] }},{{ azs['availability_zones'][1]['name'] }}"
126
+ availability_zone : " {{ random_az }}"
104
127
datastore_type : " {{ db_type }}"
105
- datastore_version : " {{ db_version }}"
106
- flavor : " {{ rds_flavors.rds_flavors[0].name }}"
107
- ha_mode : " async"
128
+ datastore_version : " {{ latest_version }}"
129
+ flavor : " {{ smallest_flavor }}"
108
130
router : " {{ test_router_name }}"
109
131
network : " {{ test_network_name }}"
110
132
security_group : " {{ test_security_group_name }}"
111
133
password : " {{ password }}"
112
- volume_type : " {{ volume_type }}"
134
+ volume_type : " {{ storage_type }}"
135
+ region : " {{ region }}"
113
136
volume_size : 40
114
- backup_keepdays : 1
115
- backup_timeframe : " 02:00-03:00"
137
+ backup_keepdays : 0
138
+ # backup_timeframe: "02:00-03:00"
116
139
wait : true
117
140
timeout : 777
118
141
register : rds_mysql
130
153
opentelekomcloud.cloud.rds_instance :
131
154
name : " {{ test_rds_name }}"
132
155
state : present
133
- availability_zone : " {{ azs['availability_zones'][0]['name'] }},{{ azs['availability_zones'][1]['name'] }}"
156
+ availability_zone : " {{ random_az }}"
134
157
datastore_type : " {{ db_type }}"
135
- datastore_version : " {{ db_version }}"
136
- flavor : " {{ rds_flavors.rds_flavors[0].name }}"
137
- ha_mode : " async"
158
+ datastore_version : " {{ latest_version }}"
159
+ flavor : " {{ smallest_flavor }}"
138
160
router : " {{ test_router_name }}"
139
161
network : " {{ test_network_name }}"
140
162
security_group : " {{ test_security_group_name }}"
141
163
password : " {{ password }}"
142
- volume_type : " {{ volume_type }}"
164
+ volume_type : " {{ storage_type }}"
165
+ region : " {{ region }}"
143
166
volume_size : 40
144
- backup_keepdays : 1
145
- backup_timeframe : " 02:00-03:00"
167
+ backup_keepdays : 0
168
+ # backup_timeframe: "02:00-03:00"
146
169
wait : true
147
170
timeout : 777
148
171
register : rds_pg
165
188
name : " {{ rds.instance.id }}"
166
189
167
190
168
- # Querying RDS backup info. You can use any of specified attributes, together or separately.
191
+ # Querying RDS backup info
169
192
- name : Get RDS backup info
170
193
opentelekomcloud.cloud.rds_backup_info :
171
194
instance : " {{ rds.instance.id }}"
194
217
tags :
195
218
- ' service=rds'
196
219
- " metric=delete_rds_mysql"
197
-
198
- # Delete VPC and SUBNET
199
- - name : Delete VPC
200
- include_role :
201
- name : opentelekomcloud.vpc
202
- vars :
203
- router_name : " {{ test_router_name }}"
204
- network_name : " {{ test_network_name }}"
205
- subnet_name : " {{ test_subnet_name }}"
206
- state : absent
207
-
208
- # Delete Security Group
209
- - name : Delete SecurityGroup
210
- openstack.cloud.security_group :
211
- state : " absent"
212
- name : " {{ test_security_group_name }}"
213
-
214
- ignore_errors : true
220
+
221
+ ignore_errors : true
0 commit comments