-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuser_data.template
112 lines (105 loc) · 3.75 KB
/
user_data.template
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
heat_template_version: 2013-05-23
description: Template to deploy a single user data instance (MySQL + Apache)
parameters:
key_name:
type: string
description: Name of a KeyPair
image_id:
type: string
label: Image ID
description: ID of the image to be used for compute instance
instance_type:
type: string
label: Instance Type
description: Type of instance (flavor) to be used
default: m1.small
constraints:
- allowed_values: [m1.tiny, m1.small, m1.medium, m1.large]
db_name:
type: string
description: Database name
default: tempdatabase
constraints:
- length: {min: 4, max: 64}
- 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: Database admin account username
default: admin
hidden: true
constraints:
- length: {min: 3, max: 16}
- 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: Database admin account password
default: admin
hidden: true
constraints:
- length: {min: 5, max: 41}
description: admin account password must be between 5 and 41 characters
- allowed_pattern: '[a-zA-Z0-9]*'
description: db_password must contain only alphanumeric characters
shared_net_id:
type: string
description: ID of private sub network into which servers get deployed
db_root_password:
type: string
description: Root password for MySQL
default: admin
hidden: true
constraints:
- length: {min: 4, max: 41}
description: root password must be between 4 and 41 characters
- allowed_pattern: '[a-zA-Z0-9]*'
description: db_password must contain only alphanumeric characters
resources:
user_data_instance:
name: user_data_instance_from_heat
type: OS::Nova::Server
properties:
image: { get_param: image_id }
flavor: { get_param: instance_type }
key_name: { get_param: key_name }
networks:
- port: { get_resource: user_data_instance_port }
user_data:
str_replace:
template: |
#!/bin/bash -v
apt-get update
debconf-set-selections <<< 'mysql-server-5.1 mysql-server/root_password password root'
debconf-set-selections <<< 'mysql-server-5.1 mysql-server/root_password_again password root'
apt-get -y install mysql-server
# 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"@"localhost" IDENTIFIED BY "db_password";
GRANT ALL PRIVILEGES ON db_name.* TO "db_user"@"%" IDENTIFIED BY "db_password";
FLUSH PRIVILEGES;
EXIT
EOF
# Setting bind address to mysql remote access
ed /etc/mysql/my.cnf <<EOF
%s/127.0.0.1/0.0.0.0/
wq
EOF
service mysql restart
# Apache2 installation
apt-get install -y apache2
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 }
user_data_instance_port:
type: OS::Neutron::Port
properties:
network_id: { get_param: shared_net_id }
outputs:
instance_ip:
description: The IP address of the deployed instance
value: { get_attr: [user_data_instance, first_address] }