diff --git a/OpenStack/heat/heat01.yaml b/OpenStack/heat/heat01.yaml new file mode 100644 index 0000000000000000000000000000000000000000..797b47d85f32e9332929068fd111a75e6a1106aa --- /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 0000000000000000000000000000000000000000..a1a8407920c6d976d80e7dccc1eb1e43dbb11edf --- /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 0000000000000000000000000000000000000000..15bcd64ac437404dc6b898936ea361b626e3a4a2 --- /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 0000000000000000000000000000000000000000..aedbb721cbbbf580d908a85cb9a9d629724756d1 --- /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 0000000000000000000000000000000000000000..02edcb7b51d40b892ff8b1f974cc5c1f4a01b8af --- /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 0000000000000000000000000000000000000000..3657a51b679e2b2d101836152cc26602fa381ae4 --- /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 0000000000000000000000000000000000000000..92be870b9bc542c090380e05d2daefc0ae8f7e83 --- /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 <