Skip to content

Instantly share code, notes, and snippets.

@spareslant
Created September 20, 2016 19:46
Show Gist options
  • Save spareslant/1979934d3a421093882852b485559657 to your computer and use it in GitHub Desktop.
Save spareslant/1979934d3a421093882852b485559657 to your computer and use it in GitHub Desktop.
heat_template_version: 2015-10-15
description: Apache Web server installation template.
parameters:
flavor_name:
type: string
description: Instance type for server
default: m1.small
image_name:
type: string
description: Name or ID of the image to use for the WebServer.
constraints:
- allowed_pattern: "fedora[A-Za-z0-9]*|ubuntu[A-Za-z0-9]*|centos[A-Za-z0-9]*"
description: A name of image can be ubuntu* centos* or fedora* only.
private_network_name:
type: string
description: Name or ID of the network to use for the WebServer.
default: private_network
public_network_name:
type: string
description: Name or ID of the network to use for the WebServer.
default: public_network
keypair_name:
type: string
description: Name of the keyPair to be used.
default: node1_key
resources:
webserver_instance:
type: OS::Nova::Server
properties:
image:
get_param: image_name
flavor:
get_param: flavor_name
key_name:
get_param: keypair_name
networks:
- port:
get_resource: port_on_private_network
user_data_format: RAW
user_data: |
#! /bin/bash -ex
echo "nameserver 10.250.1.10" >> /etc/resolv.conf
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
if which apt-get > /dev/null 2>&1
then
apt-get update
apt-get -y install apache2
systemctl start apache2
elif which yum > /dev/null 2>&1
then
yum -y install httpd
systemctl start httpd
elif which dnf > /dev/null 2>&1
then
dnf -y install httpd
systemctl start httpd
else
echo "ERROR: Unrecognized OS distribution"
fi
web_server_security_group:
type: OS::Neutron::SecurityGroup
properties:
name: web_server_security_group
rules:
- protocol: tcp
direction: ingress
remote_ip_prefix: 0.0.0.0/0
port_range_min: 80
port_range_max: 80
- protocol: tcp
direction: egress
port_range_min: 1
port_range_max: 65535
- protocol: udp
direction: egress
port_range_min: 1
port_range_max: 65535
- protocol: icmp
remote_ip_prefix: 0.0.0.0/0
- protocol: tcp
direction: ingress
remote_ip_prefix: 0.0.0.0/0
port_range_min: 22
port_range_max: 22
port_on_private_network:
type: OS::Neutron::Port
properties:
network:
get_param: private_network_name
security_groups:
- get_resource: web_server_security_group
free_floating_ip:
type: OS::Neutron::FloatingIP
properties:
floating_network:
get_param: public_network_name
assign_floatingIP_to_port:
type: OS::Neutron::FloatingIPAssociation
properties:
floatingip_id:
get_resource: free_floating_ip
port_id:
get_resource: port_on_private_network
outputs:
webserver_info:
description: Information about webServer
value:
get_attr:
- webserver_instance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment