Last active
August 29, 2015 14:09
-
-
Save miguelgrinberg/be18b34fba05f28f9eda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
heat_template_version: 2013-05-23 | |
description: Template that installs a wordpress server and supporting MySQL database running on separate servers | |
parameters: | |
image: | |
type: string | |
label: Image name or ID | |
description: Image to be used for server. Please use an Ubuntu based image. | |
default: trusty-server-cloudimg-amd64 | |
flavor: | |
type: string | |
label: Flavor | |
description: Type of instance (flavor) to be used on the compute instance. | |
default: m1.small | |
key: | |
type: string | |
label: Key name | |
description: Name of key-pair to be installed on the compute instance. | |
default: my_key | |
public_network: | |
type: string | |
label: Public network name or ID | |
description: Public network to attach server to. | |
default: public | |
resources: | |
network: | |
type: https://raw.githubusercontent.com/miguelgrinberg/heat-tutorial/master/lib/private_network.yaml | |
properties: | |
public_network: { get_param: public_network } | |
mysql: | |
type: https://raw.githubusercontent.com/miguelgrinberg/heat-tutorial/master/lib/mysql.yaml | |
properties: | |
image: { get_param: image } | |
flavor: { get_param: flavor } | |
key: { get_param: key } | |
private_network: { get_attr: [network, name] } | |
database_name: wordpress | |
database_user: wordpress_user | |
wordpress: | |
type: https://raw.githubusercontent.com/miguelgrinberg/heat-tutorial/master/lib/wordpress.yaml | |
depends_on: mysql | |
properties: | |
image: { get_param: image } | |
flavor: { get_param: flavor } | |
key: { get_param: key } | |
private_network: { get_attr: [network, name] } | |
mysql_server: { get_attr: [mysql, ip] } | |
database_name: wordpress | |
database_user: wordpress_user | |
database_password: { get_attr: [mysql, database_password] } | |
floating_ip: | |
type: https://raw.githubusercontent.com/miguelgrinberg/heat-tutorial/master/lib/floating_ip.yaml | |
properties: | |
port: { get_attr: [wordpress, port] } | |
public_network: { get_param: public_network } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
heat_template_version: 2013-05-23 | |
description: Template that installs a MySQL server with a database | |
parameters: | |
image: | |
type: string | |
label: Image name or ID | |
description: Image to be used for server. Please use an Ubuntu based image. | |
default: trusty-server-cloudimg-amd64 | |
flavor: | |
type: string | |
label: Flavor | |
description: Type of instance (flavor) to be used on the compute instance. | |
default: m1.small | |
key: | |
type: string | |
label: Key name | |
description: Name of key-pair to be installed on the compute instance. | |
default: my_key | |
private_network: | |
type: string | |
label: Private network name or ID | |
description: Network to attach server to. | |
default: private | |
database_name: | |
type: string | |
label: Database name | |
description: Name of the application database. | |
database_user: | |
type: string | |
label: Database username | |
description: Name of the database user. | |
resources: | |
wait_condition: | |
type: OS::Heat::WaitCondition | |
properties: | |
handle: { get_resource: wait_handle } | |
count: 1 | |
timeout: 600 | |
wait_handle: | |
type: OS::Heat::WaitConditionHandle | |
mysql_root_password: | |
type: OS::Heat::RandomString | |
properties: | |
length: 32 | |
sequence: lettersdigits | |
database_password: | |
type: OS::Heat::RandomString | |
properties: | |
length: 32 | |
sequence: lettersdigits | |
mysql_security_group: | |
type: OS::Neutron::SecurityGroup | |
properties: | |
name: db_server_security_group | |
rules: | |
- protocol: tcp | |
port_range_min: 3306 | |
port_range_max: 3306 | |
mysql_instance: | |
type: OS::Nova::Server | |
properties: | |
image: { get_param: image } | |
flavor: { get_param: flavor } | |
key_name: { get_param: key } | |
networks: | |
- network: { get_param: private_network } | |
security_groups: | |
- { get_resource: mysql_security_group } | |
user_data_format: RAW | |
user_data: | |
str_replace: | |
params: | |
__mysql_root_password__: { get_attr: [mysql_root_password, value] } | |
__database_name__: { get_param: database_name } | |
__database_user__: { get_param: database_user } | |
__database_password__: { get_attr: [database_password, value] } | |
wc_notify: { get_attr: ['wait_handle', 'curl_cli'] } | |
template: | | |
#!/bin/bash | |
# install MySQL | |
apt-get update | |
export DEBIAN_FRONTEND=noninteractive | |
apt-get install -y mysql-server | |
# configure MySQL root password | |
mysqladmin -u root password "__mysql_root_password__" | |
# listen on all network interfaces | |
sed -i "s/bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf | |
# restart service | |
service mysql restart | |
# create wordpress database | |
mysql -u root --password="__mysql_root_password__" <<EOF | |
CREATE DATABASE __database_name__; | |
CREATE USER '__database_user__'@'localhost'; | |
SET PASSWORD FOR '__database_user__'@'localhost'=PASSWORD("__database_password__"); | |
GRANT ALL PRIVILEGES ON __database_name__.* TO '__database_user__'@'localhost' IDENTIFIED BY '__database_password__'; | |
CREATE USER '__database_user__'@'%'; | |
SET PASSWORD FOR '__database_user__'@'%'=PASSWORD("__database_password__"); | |
GRANT ALL PRIVILEGES ON __database_name__.* TO '__database_user__'@'%' IDENTIFIED BY '__database_password__'; | |
FLUSH PRIVILEGES; | |
EOF | |
# notify heat that we are done here | |
wc_notify --data-binary '{"status": "SUCCESS"}' | |
outputs: | |
mysql_instance_name: | |
description: Name of the MySQL instance | |
value: { get_attr: [mysql_instance, name] } | |
mysql_instance_ip: | |
description: The IP address of the MySQL instance | |
value: { get_attr: [mysql_instance, first_address] } | |
database_password: | |
description: The MySQL database password | |
value: { get_attr: [database_password, value] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
heat_template_version: 2013-05-23 | |
description: Template that installs a wordpress server | |
parameters: | |
image: | |
type: string | |
label: Image name or ID | |
description: Image to be used for server. Please use an Ubuntu based image. | |
default: trusty-server-cloudimg-amd64 | |
flavor: | |
type: string | |
label: Flavor | |
description: Type of instance (flavor) to be used on the compute instance. | |
default: m1.small | |
key: | |
type: string | |
label: Key name | |
description: Name of key-pair to be installed on the compute instance. | |
default: my_key | |
private_network: | |
type: string | |
label: Private network name or ID | |
description: Network to attach server to. | |
default: private | |
mysql_server: | |
type: string | |
label: MySQL database server | |
description: IP address of the MySQL database server. | |
database_name: | |
type: string | |
label: Database name | |
description: Name of the application database. | |
database_user: | |
type: string | |
label: Database user | |
description: Name of the database user. | |
database_password: | |
type: string | |
label: Database password | |
hidden: true | |
description: Password to access the database. | |
resources: | |
wait_condition: | |
type: OS::Heat::WaitCondition | |
properties: | |
handle: { get_resource: wait_handle } | |
count: 1 | |
timeout: 600 | |
wait_handle: | |
type: OS::Heat::WaitConditionHandle | |
wordpress_security_group: | |
type: OS::Neutron::SecurityGroup | |
properties: | |
name: web_server_security_group | |
rules: | |
- protocol: tcp | |
port_range_min: 80 | |
port_range_max: 80 | |
wordpress_instance: | |
type: OS::Nova::Server | |
properties: | |
image: { get_param: image } | |
flavor: { get_param: flavor } | |
key_name: { get_param: key } | |
networks: | |
- network: { get_param: private_network } | |
security_groups: | |
- { get_resource: wordpress_security_group } | |
user_data_format: RAW | |
user_data: | |
str_replace: | |
params: | |
__mysql_ip__: { get_param: mysql_server } | |
__database_name__: { get_param: database_name } | |
__database_user__: { get_param: database_user } | |
__database_password__: { get_param: database_password } | |
wc_notify: { get_attr: ['wait_handle', 'curl_cli'] } | |
template: | | |
#!/bin/bash -ex | |
# install dependencies | |
apt-get update | |
apt-get -y install apache2 php5 libapache2-mod-php5 php5-mysql php5-gd mysql-client | |
# download wordpress | |
wget http://wordpress.org/latest.tar.gz | |
tar -xzf latest.tar.gz | |
# configure wordpress | |
cp wordpress/wp-config-sample.php wordpress/wp-config.php | |
sed -i 's/database_name_here/__database_name__/' wordpress/wp-config.php | |
sed -i 's/username_here/__database_user__/' wordpress/wp-config.php | |
sed -i 's/password_here/__database_password__/' wordpress/wp-config.php | |
sed -i 's/localhost/__mysql_ip__/' wordpress/wp-config.php | |
# install a copy of the configured wordpress into apache's www directory | |
rm /var/www/html/index.html | |
cp -R wordpress/* /var/www/html/ | |
# give apache ownership of the application files | |
chown -R www-data:www-data /var/www/html/ | |
chmod -R g+w /var/www/html/ | |
# notify heat that we are done here | |
wc_notify --data-binary '{"status": "SUCCESS"}' | |
outputs: | |
wordpress_instance_name: | |
description: Name of the wordpress instance | |
value: { get_attr: [wordpress_instance, name] } | |
wordpress_instance_ip: | |
description: The IP address of the wordpress instance | |
value: { get_attr: [wordpress_instance, first_address] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment