From 2ffce5b676ebb01e2cd6ef4a6c4955d2c5e91c3a Mon Sep 17 00:00:00 2001 From: Giuliano Taffoni Date: Thu, 22 Nov 2018 17:34:24 +0100 Subject: [PATCH] heat --- OpenStack/heat/heat01.yaml | 47 ++++ OpenStack/heat/tutorial/heat_1a.yaml | 13 + OpenStack/heat/tutorial/heat_1b.yaml | 40 +++ OpenStack/heat/tutorial/heat_2a.yaml | 47 ++++ OpenStack/heat/tutorial/heat_2b.yaml | 145 +++++++++++ OpenStack/heat/tutorial/heat_2b2.yaml | 184 ++++++++++++++ OpenStack/heat/tutorial/heat_2c.yaml | 202 +++++++++++++++ OpenStack/heat/tutorial/heat_2d.yaml | 214 ++++++++++++++++ OpenStack/heat/tutorial/heat_3a.yaml | 48 ++++ OpenStack/heat/tutorial/heat_3b.yaml | 53 ++++ OpenStack/heat/tutorial/heat_3c.yaml | 64 +++++ OpenStack/heat/tutorial/heat_3d.yaml | 64 +++++ OpenStack/heat/tutorial/heat_4a.yaml | 50 ++++ OpenStack/heat/tutorial/heat_4b.yaml | 68 +++++ "OpenStack/heat/tutorial/lib/Icon\r" | 0 OpenStack/heat/tutorial/lib/env.yaml | 9 + OpenStack/heat/tutorial/lib/flasky.yaml | 187 ++++++++++++++ OpenStack/heat/tutorial/lib/floating_ip.yaml | 32 +++ OpenStack/heat/tutorial/lib/haproxy.yaml | 154 ++++++++++++ OpenStack/heat/tutorial/lib/keypair.yaml | 37 +++ OpenStack/heat/tutorial/lib/mysql.yaml | 135 ++++++++++ .../heat/tutorial/lib/private_network.yaml | 48 ++++ OpenStack/heat/tutorial/lib/tiny.yaml | 151 ++++++++++++ OpenStack/heat/tutorial/lib/wordpress.yaml | 126 ++++++++++ OpenStack/heat/tutorial/wordpress03.yaml | 232 ++++++++++++++++++ 25 files changed, 2350 insertions(+) create mode 100644 OpenStack/heat/heat01.yaml create mode 100644 OpenStack/heat/tutorial/heat_1a.yaml create mode 100644 OpenStack/heat/tutorial/heat_1b.yaml create mode 100644 OpenStack/heat/tutorial/heat_2a.yaml create mode 100644 OpenStack/heat/tutorial/heat_2b.yaml create mode 100644 OpenStack/heat/tutorial/heat_2b2.yaml create mode 100644 OpenStack/heat/tutorial/heat_2c.yaml create mode 100644 OpenStack/heat/tutorial/heat_2d.yaml create mode 100644 OpenStack/heat/tutorial/heat_3a.yaml create mode 100644 OpenStack/heat/tutorial/heat_3b.yaml create mode 100644 OpenStack/heat/tutorial/heat_3c.yaml create mode 100644 OpenStack/heat/tutorial/heat_3d.yaml create mode 100644 OpenStack/heat/tutorial/heat_4a.yaml create mode 100644 OpenStack/heat/tutorial/heat_4b.yaml create mode 100644 "OpenStack/heat/tutorial/lib/Icon\r" create mode 100644 OpenStack/heat/tutorial/lib/env.yaml create mode 100644 OpenStack/heat/tutorial/lib/flasky.yaml create mode 100644 OpenStack/heat/tutorial/lib/floating_ip.yaml create mode 100644 OpenStack/heat/tutorial/lib/haproxy.yaml create mode 100644 OpenStack/heat/tutorial/lib/keypair.yaml create mode 100644 OpenStack/heat/tutorial/lib/mysql.yaml create mode 100644 OpenStack/heat/tutorial/lib/private_network.yaml create mode 100644 OpenStack/heat/tutorial/lib/tiny.yaml create mode 100644 OpenStack/heat/tutorial/lib/wordpress.yaml create mode 100644 OpenStack/heat/tutorial/wordpress03.yaml diff --git a/OpenStack/heat/heat01.yaml b/OpenStack/heat/heat01.yaml new file mode 100644 index 0000000..797b47d --- /dev/null +++ b/OpenStack/heat/heat01.yaml @@ -0,0 +1,47 @@ +heat_template_version: 2013-05-23 + +description: Simple template to deploy a single compute instance + +parameters: + image: + type: string + label: Image name or ID + description: Image to be used for compute instance + default: CentOS 7.4 x86_64 + flavor: + type: string + label: Flavor + description: Type of instance (flavor) to be used + default: m1.medium + key: + type: string + label: Key name + description: Name of key-pair to be used for compute instance + default: taffoni_rsa + private_network: + type: string + label: Private network name or ID + description: Network to attach instance to. + default: oats_net + +resources: + my_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 } + user_data: | + #!/bin/sh + echo "Hello, World!" + user_data_format: RAW + +outputs: + instance_name: + description: Name of the instance + value: { get_attr: [my_instance, name] } + instance_ip: + description: IP address of the instance + value: { get_attr: [my_instance, first_address] } diff --git a/OpenStack/heat/tutorial/heat_1a.yaml b/OpenStack/heat/tutorial/heat_1a.yaml new file mode 100644 index 0000000..a1a8407 --- /dev/null +++ b/OpenStack/heat/tutorial/heat_1a.yaml @@ -0,0 +1,13 @@ +heat_template_version: 2013-05-23 + +description: Simple template to deploy a single compute instance + +resources: + my_instance: + type: OS::Nova::Server + properties: + image: cirros-0.3.3-x86_64 + flavor: m1.small + key_name: my_key + networks: + - network: private-net diff --git a/OpenStack/heat/tutorial/heat_1b.yaml b/OpenStack/heat/tutorial/heat_1b.yaml new file mode 100644 index 0000000..15bcd64 --- /dev/null +++ b/OpenStack/heat/tutorial/heat_1b.yaml @@ -0,0 +1,40 @@ +heat_template_version: 2013-05-23 + +description: Simple template to deploy a single compute instance + +parameters: + image: + type: string + label: Image name or ID + description: Image to be used for compute instance + default: cirros-0.3.3-x86_64 + flavor: + type: string + label: Flavor + description: Type of instance (flavor) to be used + default: m1.small + key: + type: string + label: Key name + description: Name of key-pair to be used for compute instance + default: my_key + private_network: + type: string + label: Private network name or ID + description: Network to attach instance to. + default: private-net + +resources: + my_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 } + +outputs: + instance_ip: + description: IP address of the instance + value: { get_attr: [my_instance, first_address] } diff --git a/OpenStack/heat/tutorial/heat_2a.yaml b/OpenStack/heat/tutorial/heat_2a.yaml new file mode 100644 index 0000000..aedbb72 --- /dev/null +++ b/OpenStack/heat/tutorial/heat_2a.yaml @@ -0,0 +1,47 @@ +heat_template_version: 2013-05-23 + +description: Simple template to deploy a single compute instance + +parameters: + image: + type: string + label: Image name or ID + description: Image to be used for compute instance + default: cirros-0.3.3-x86_64 + flavor: + type: string + label: Flavor + description: Type of instance (flavor) to be used + default: m1.small + key: + type: string + label: Key name + description: Name of key-pair to be used for compute instance + default: my_key + private_network: + type: string + label: Private network name or ID + description: Network to attach instance to. + default: private-net + +resources: + my_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 } + user_data: | + #!/bin/sh + echo "Hello, World!" + user_data_format: RAW + +outputs: + instance_name: + description: Name of the instance + value: { get_attr: [my_instance, name] } + instance_ip: + description: IP address of the instance + value: { get_attr: [my_instance, first_address] } diff --git a/OpenStack/heat/tutorial/heat_2b.yaml b/OpenStack/heat/tutorial/heat_2b.yaml new file mode 100644 index 0000000..02edcb7 --- /dev/null +++ b/OpenStack/heat/tutorial/heat_2b.yaml @@ -0,0 +1,145 @@ +heat_template_version: 2013-05-23 + +description: This template deploys a Flasky single instance server with a SQLite database. + +parameters: + image: + type: string + label: Image name or ID + description: Image to be used for the 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: Private network to attach server to. + default: private-net + gmail_username: + type: string + label: Gmail account username + description: Username of the Gmail account to use for notifications. + gmail_password: + type: string + label: Gmail account password + description: Password of the Gmail account to use for notifications. + hidden: true + +resources: + flask_secret_key: + type: OS::Heat::RandomString + properties: + length: 32 + sequence: lettersdigits + + flasky_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 } + user_data_format: RAW + user_data: + str_replace: + params: + __gmail_username__: { get_param: gmail_username } + __gmail_password__: { get_param: gmail_password } + __flask_secret_key__: { get_attr: [flask_secret_key, value] } + template: | + #!/bin/bash -ex + + # install dependencies + apt-get update + apt-get -y install build-essential python python-dev python-virtualenv nginx supervisor git + + # create a flasky user to run the server process + adduser --disabled-password --gecos "" flasky + + # clone flasky from github + cd /home/flasky + git clone https://github.com/miguelgrinberg/flasky-first-edition.git + mv flasky-first-edition flasky + cd flasky + + # Write configuration file + cat >.env </etc/supervisor/conf.d/flasky.conf </etc/nginx/sites-available/flasky <.env </etc/supervisor/conf.d/flasky.conf </etc/nginx/sites-available/flasky <.env </etc/supervisor/conf.d/flasky.conf </etc/nginx/sites-available/flasky <.env </etc/supervisor/conf.d/flasky.conf </etc/nginx/sites-available/flasky <.env </etc/supervisor/conf.d/flasky.conf </etc/nginx/sites-available/flasky <>/etc/haproxy/servers.json <>/etc/haproxy/update.py <_crontab || true + echo "* * * * * curl -s http://169.254.169.254/openstack/latest/meta_data.json | python /etc/haproxy/update.py | /usr/bin/logger -t haproxy_update" >>_crontab + crontab <_crontab + rm _crontab + + # let Heat know that we are done here + wc_notify --data-binary '{"status": "SUCCESS"}' + +outputs: + name: + description: Name of the HAProxy instance. + value: { get_attr: [haproxy_instance, name] } + ip: + description: The IP address of the HAProxy instance. + value: { get_attr: [haproxy_instance, first_address] } + port: + description: The network port of the HAProxy instance. + value: { get_resource: port } diff --git a/OpenStack/heat/tutorial/lib/keypair.yaml b/OpenStack/heat/tutorial/lib/keypair.yaml new file mode 100644 index 0000000..3657a51 --- /dev/null +++ b/OpenStack/heat/tutorial/lib/keypair.yaml @@ -0,0 +1,37 @@ +heat_template_version: 2013-05-23 + +description: Template that creates a keypair. + +parameters: + prefix: + type: string + label: Name prefix + description: The prefix to use for the keypair name. + +resources: + keypair: + type: OS::Nova::KeyPair + properties: + name: + str_replace: + params: + __prefix__: { get_param: prefix } + __id__: { get_param: "OS::stack_name" } + template: __prefix__-__id__ + save_private_key: true + +outputs: + name: + description: The name of the keypair. + value: + str_replace: + params: + __prefix__: { get_param: prefix } + __id__: { get_param: "OS::stack_name" } + template: __prefix__-__id__ + public_key: + description: The public key of the keypair. + value: { get_attr: [keypair, public_key] } + private_key: + description: The private key of the keypair. + value: { get_attr: [keypair, private_key] } diff --git a/OpenStack/heat/tutorial/lib/mysql.yaml b/OpenStack/heat/tutorial/lib/mysql.yaml new file mode 100644 index 0000000..92be870 --- /dev/null +++ b/OpenStack/heat/tutorial/lib/mysql.yaml @@ -0,0 +1,135 @@ +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 + + security_group: + type: OS::Neutron::SecurityGroup + properties: + name: db_server_security_group + rules: + - protocol: tcp + port_range_min: 3306 + port_range_max: 3306 + + port: + type: OS::Neutron::Port + properties: + network: { get_param: private_network } + security_groups: + - { get_resource: security_group } + + mysql_instance: + type: OS::Nova::Server + properties: + image: { get_param: image } + flavor: { get_param: flavor } + key_name: { get_param: key } + networks: + - port: { get_resource: port } + 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__" <app.py </etc/supervisor/conf.d/tiny.conf </etc/nginx/sites-available/tiny <