forked from pedro-r-marques/examples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwordpress.yaml
260 lines (227 loc) · 7.96 KB
/
wordpress.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
257
258
259
#
#
# Based on:
# https://github.com/openstack/heat-templates/blob/master/hot/F20/WordPress_2_Instances.yaml
# https://github.com/openstack/heat-templates/blob/master/hot/servers_in_new_neutron_net.yaml
#
heat_template_version: 2013-05-23
description: >
An example Heat Orchestration Template (HOT).
WordPress is web software you can use to create a beautiful website
or blog. This template installs two instances: one running a
WordPress deployment and the other using a local MySQL database to
store the data.
parameters:
key_name:
type: string
description : Name of a KeyPair to enable SSH access to the instance
default: test_key
instance_type:
type: string
description: Instance type for web and DB servers
default: m1.small
constraints:
- allowed_values: [m1.tiny, m1.small, m1.medium, m1.large, m1.xlarge]
description: instance_type must be a valid instance type
image_id:
type: string
description: >
Name or ID of the image to use for the WordPress server.
Recommended values are fedora-20.i386 or fedora-20.x86_64;
get them from http://cloud.fedoraproject.org/fedora-20.i386.qcow2
or http://cloud.fedoraproject.org/fedora-20.x86_64.qcow2 .
default: fedora-20.x86_64
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]*'
description: >
db_name must begin with a letter and contain only alphanumeric
characters
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]*'
description: >
db_username must begin with a letter and contain only alphanumeric
characters
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
public_net:
type: string
description: ID or name of public network from which floating IP addresses will be allocated
default: Public
public_net_id:
type: string
description: >
Neutron floatingip resource in icehouse does not support
network name. This parameter should be removed for future versions.
frontend_net_name:
type: string
description: Webservers are isolated in this network.
default: wordpress
frontend_net_cidr:
type: string
description: The IP prefixes of the subnets used by the application should be unique.
default: 192.168.0.0/24
database_net_name:
type: string
description: Database server(s) are isolated in this network.
default: database
database_net_cidr:
type: string
description: The IP prefixes of the subnets used by the application should be unique.
default: 192.168.1.0/24
resources:
FrontendNet:
type: OS::Neutron::Net
properties:
name: { get_param: frontend_net_name }
FrontendSubnet:
type: OS::Neutron::Subnet
properties:
network_id: { get_resource: FrontendNet }
cidr: { get_param: frontend_net_cidr }
DatabaseNet:
type: OS::Neutron::Net
properties:
name: { get_param: database_net_name }
DatabaseSubnet:
type: OS::Neutron::Subnet
properties:
network_id: { get_resource: DatabaseNet }
cidr: { get_param: database_net_cidr }
Router:
type: OS::Neutron::Router
properties:
external_gateway_info:
network: { get_param: public_net }
FrontendRouterInterface:
type: OS::Neutron::RouterInterface
properties:
router_id: { get_resource: Router }
subnet_id: { get_resource: FrontendSubnet }
DatabaseRouterInterface:
type: OS::Neutron::RouterInterface
properties:
router_id: { get_resource: Router }
subnet_id: { get_resource: DatabaseSubnet }
DatabaseServer:
type: OS::Nova::Server
properties:
image: { get_param: image_id }
flavor: { get_param: instance_type }
key_name: { get_param: key_name }
user_data:
str_replace:
template: |
#!/bin/bash -v
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 }
networks:
- port: { get_resource: DatabasePort }
DatabasePort:
type: OS::Neutron::Port
properties:
network_id: { get_resource: DatabaseNet }
WebServer:
type: OS::Nova::Server
properties:
image: { get_param: image_id }
flavor: { get_param: instance_type }
key_name: { get_param: key_name }
user_data:
str_replace:
template: |
#!/bin/bash -v
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, first_address ] }
networks:
- port: { get_resource: FrontendPort }
FrontendPort:
type: OS::Neutron::Port
properties:
network_id: { get_resource: FrontendNet }
Member:
type: OS::Neutron::PoolMember
properties:
pool_id: { get_resource: LoadbalancerPool }
address: { get_attr: [WebServer, first_address]}
protocol_port: 80
LoadbalancerPool:
type: OS::Neutron::Pool
properties:
protocol: HTTP
subnet_id: { get_resource: FrontendSubnet }
lb_method: ROUND_ROBIN
vip:
protocol_port: 80
FloatingIp:
type: OS::Neutron::FloatingIP
properties:
floating_network_id: { get_param: public_net_id }
port_id: { "Fn::Select" : [ "port_id", { get_attr: [ LoadbalancerPool , vip ] } ] }
outputs:
WebsiteURL:
description: URL for Wordpress wiki
value:
str_replace:
template: http://host/wordpress
params:
host: { get_attr: [FloatingIp, floating_ip_address] }