-
Notifications
You must be signed in to change notification settings - Fork 0
/
hf.yaml
256 lines (215 loc) · 7.59 KB
/
hf.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
heat_template_version: 2013-05-23
description: >
HEAT template for homework assignment.
parameters:
key_name_server:
type: string
default: generated key name for server
key_name_db:
type: string
default: generated key name for db
net1:
type: string
description: (existing) network for the server to be created
default: private-net1
constraints:
- custom_constraint: neutron.network
image:
type: string
label: Image name or ID
description: image to be used
default: fedora-20.x86_64
flavor:
type: string
label: Flavor
description: Type of flavor to be used
default: m1.small
private_net_id:
type: string
description: ID of private network into which servers get deployed
default: private-net
private_net_cidr:
type: string
description: Private network address (CIDR notation)
default: 10.0.10.0/24
private_net_pool_start:
type: string
description: Start of private network IP address allocation pool
default: 10.0.10.2
private_net_pool_end:
type: string
description: End of private network IP address allocation pool
default: 10.0.10.50
db_name:
type: string
description: WordPress database name
default: wordpress
constraints:
- length: { min: 1, max: 64 }
description: db_name must be between 1 and 64 characters
- allowed_pattern: '[a-zA-Z][a-zA-Z0-9]*'
db_username:
type: string
description: The WordPress database admin account username
default: admin
hidden: true
constraints:
- length: { min: 1, max: 16 }
description: db_username must be between 1 and 16 characters
- allowed_pattern: '[a-zA-Z][a-zA-Z0-9]*'
db_password:
type: string
description: The WordPress database admin account password
default: admin
hidden: true
constraints:
- length: { min: 1, max: 41 }
description: db_password must be between 1 and 41 characters
- allowed_pattern: '[a-zA-Z0-9]*'
description: db_password must contain only alphanumeric characters
db_root_password:
type: string
description: Root password for MySQL
default: admin
hidden: true
constraints:
- length: { min: 1, max: 41 }
description: db_root_password must be between 1 and 41 characters
- allowed_pattern: '[a-zA-Z0-9]*'
description: db_root_password must contain only alphanumeric characters
resources:
private_net:
type: OS::Neutron::Net
properties:
name: {get_param: private_net_id}
private_subnet:
type: OS::Neutron::Subnet
properties:
name: {get_param: private_net_id}
network: {get_resource: private_net}
cidr: {get_param: private_net_cidr}
dns_nameservers: ["8.8.8.8"]
allocation_pools:
- start: { get_param: private_net_pool_start }
end: { get_param: private_net_pool_end }
router:
type: OS::Neutron::Router
properties:
external_gateway_info:
network: {get_param: net1}
router_interface:
type: OS::Neutron::RouterInterface
properties:
router_id: { get_resource: router }
subnet_id: { get_resource: private_subnet }
generated_key_pair_db:
type: OS::Nova::KeyPair
properties:
name: {get_param: key_name_db}
save_private_key: True
generated_key_pair_server:
type: OS::Nova::KeyPair
properties:
name: {get_param: key_name_server}
save_private_key: True
DatabaseServer:
type: OS::Nova::Server
properties:
image: { get_param: image }
flavor: { get_param: flavor }
key_name: { get_resource: generated_key_pair_server }
networks:
- port: {get_resource: DatabaseServer_port}
user_data:
str_replace:
template: |
#!/bin/bash -v
sed -i "s/metalink=https/metalink=http/" /etc/yum.repos.d/*
yum -y install mariadb mariadb-server
touch /var/log/mariadb/mariadb.log
chown mysql.mysql /var/log/mariadb/mariadb.log
systemctl start mariadb.service
# Setup MySQL root password and create a user
mysqladmin -u root password db_rootpassword
cat << EOF | mysql -u root --password=db_rootpassword
CREATE DATABASE db_name;
GRANT ALL PRIVILEGES ON db_name.* TO "db_user"@"%"
IDENTIFIED BY "db_password";
FLUSH PRIVILEGES;
EXIT
EOF
params:
db_rootpassword: { get_param: db_root_password }
db_name: { get_param: db_name }
db_user: { get_param: db_username }
db_password: { get_param: db_password }
DatabaseServer_port:
type: OS::Neutron::Port
properties:
network: {get_resource: private_net}
fixed_ips:
- subnet_id: {get_resource: private_subnet}
security_groups: [{ get_resource: db_security_group }]
WebServer:
type: OS::Nova::Server
properties:
image: { get_param: image }
flavor: { get_param: flavor }
key_name: { get_resource: generated_key_pair_server }
networks:
- port: {get_resource: WebServer_port}
user_data:
str_replace:
template: '#!/bin/bash -v
sed -i "s/metalink=https/metalink=http/" /etc/yum.repos.d/*
yum -y install httpd wordpress
sed -i "/Deny from All/d" /etc/httpd/conf.d/wordpress.conf
sed -i "s/Require local/Require all granted/" /etc/httpd/conf.d/wordpress.conf
sed -i s/database_name_here/db_name/ /etc/wordpress/wp-config.php
sed -i s/username_here/db_user/ /etc/wordpress/wp-config.php
sed -i s/password_here/db_password/ /etc/wordpress/wp-config.php
sed -i s/localhost/db_ipaddr/ /etc/wordpress/wp-config.php
setenforce 0 # Otherwise net traffic with DB is disabled
systemctl start httpd.service
'
params:
db_rootpassword: { get_param: db_root_password }
db_name: { get_param: db_name }
db_user: { get_param: db_username }
db_password: { get_param: db_password }
db_ipaddr: { get_attr: [DatabaseServer, networks, private-net, 0] }
WebServer_port:
type: OS::Neutron::Port
properties:
network: { get_resource: private_net }
fixed_ips:
- subnet_id: { get_resource: private_subnet }
security_groups: [{ get_resource: server_security_group }]
server_floating_ip:
type: OS::Neutron::FloatingIP
properties:
floating_network_id: { get_param: net1 }
port_id: { get_resource: WebServer_port }
server_security_group:
type: OS::Neutron::SecurityGroup
properties:
description: Add security group rules for server
name: security-group
rules:
- {port_range_max: 22, port_range_min: 22, protocol: tcp, remote_ip_prefix: 0.0.0.0/0}
- {port_range_max: 80, port_range_min: 80, protocol: tcp, remote_ip_prefix: 0.0.0.0/0}
- {protocol: icmp, remote_ip_prefix: 0.0.0.0/0}
db_security_group:
type: OS::Neutron::SecurityGroup
properties:
name: sec-group-db
rules:
- {port_range_max: 3306, port_range_min: 3306, protocol: tcp,remote_ip_prefix: 10.0.10.0/24}
outputs:
WebsiteURL:
description: URL for Wordpress wiki
value:
str_replace:
template: http://host/wordpress
params:
host: { get_attr: [server_floating_ip, floating_ip_address] }