Writing templates

The two core concepts to get started with Heat are stacks and templates. A stack is a collection of resources related to one another and launched by way of a template. A template is a text document definition of a stack. To launch a Heat stack, a Heat template is launched. Let's look at both of these in more depth, starting with templates.

Before we can launch a stack, we need a template that will define the stack. There are two template formats that you can use to launch a stack in Heat. One is the AWS CloudFormation template format. If you have ever used CloudFormation in Amazon Web Services (AWS), then you will be familiar with this template format. Heat templates are very similar to those used within AWS, and add additional capabilities within OpenStack. The second format is the Heat Orchestration Template (HOT). HOT is a native Heat template format that is written in the YAML Ain't Markup Language syntax. For more examples of both, visit the Heat-templates GitHub repository and browse through the collection of example scripts. The examples used in this chapter were pulled from https://github.com/openstack/heat-templates.

The AWS CloudFormation format

Let's pull an example from the Heat-templates repository to gain some familiarity with the AWS CloudFormation format. Most of these templates are fairly large documents, so their entire contents will not be provided here. This document will be referenced from top to bottom. The document in its entirety is available at https://github.com/openstack/heat-templates/blob/master/cfn/F19/WordPress_NoKey.yaml and is also available in the code resources provided with this book.

Let's take a look at the configuration options used in this template:

  • HeatTemplateFormatVersion: This is just for versioning so that Heat knows which syntax version is being used.
  • Description: This is a description of what the template will launch. This template indicates it will launch a single-instance WordPress installation.
  • Parameters: This is a section that defines what information is needed for this template to be launched. You can see that each of the parameters is defined by its name first and then a set of parameters to help the end user enter the correct information in it. For the template we are looking at, there are InstanceType, which references the flavors in Nova, and the DBName, DBUsername, DBPassword, and DBRootPassword properties that will be used to configure the database that will be created.
  • Mappings: This template only maps flavors with images, so that when you launch a specific flavor, you will get the associated image.
  • Resources: This section defines the resources that will be created in OpenStack. In this template, security group rules and an instance are created. You can see the security group rules to allow ICMP, port 80 (HTTP), and port 22 (SSH) traffic. You can also see the configuration options that will be passed to the instance when it is booted. These include packages to be installed, services to be started, the image to be used to launch the instance, which references the mappings we just looked at, the security group for the instance to reside in, and the user data that cloud-init should execute.
  • Outputs: This section passes data back to Heat from the stack once it has been launched.

Next, let's take a look at the HOT format before we use a template to launch a stack.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.38.92