Este conteúdo não está disponível no idioma selecionado.
Chapter 2. Understanding Heat Templates
The custom configurations in this guide use Heat templates and environment files to define certain aspects of the Overcloud. This chapter provides a basic introduction to Heat templates so that you can understand the structure and format of these templates in the context of the Red Hat OpenStack Platform director.
2.1. Heat Templates Copiar o linkLink copiado para a área de transferência!
Red Hat OpenStack Platform (RHOSP) director uses Heat Orchestration Templates (HOT) as a template format for its overcloud deployment plan. Templates in HOT format are usually expressed in YAML format. The purpose of a template is to define and create a stack, which is a collection of resources that heat creates, and the configuration of the resources. Resources are objects in RHOSP and can include compute resources, network configuration, security groups, scaling rules, and custom resources.
For RHOSP to use the heat template file as a custom template resource, the file extension must be either .yaml or .template.
Heat templates have three main sections:
- Parameters
-
These are settings passed to heat to customize a stack. You can also use heat parameters to customize default values. These settings are defined in the
parameterssection of a template. - Resources
-
These are the specific objects to create and configure as part of a stack. Red Hat OpenStack Platform (RHOSP) contains a set of core resources that span across all components. These are defined in the
resourcessection of a template. - Output
-
These are values passed from heat after the creation of the stack. You can access these values either through the heat API or client tools. These are defined in the
outputsection of a template.
Here is an example of a basic heat template:
This template uses the resource type type: OS::Nova::Server to create an instance called my_instance with a particular flavor, image, and key. The stack can return the value of instance_name, which is called My Cirros Instance.
When Heat processes a template it creates a stack for the template and a set of child stacks for resource templates. This creates a hierarchy of stacks that descend from the main stack you define with your template. You can view the stack hierarchy using this following command:
openstack stack list --nested
$ openstack stack list --nested
2.2. Environment Files Copiar o linkLink copiado para a área de transferência!
An environment file is a special type of template that provides customization for your heat templates. This includes three key parts:
- Resource Registry
-
This section defines custom resource names that are linked to other heat templates. This provides a method to create custom resources that do not exist within the core resource collection. These are defined in the
resource_registrysection of an environment file. - Parameters
-
These are common settings that you apply to the parameters of the top-level template. For example, if you have a template that deploys nested stacks, such as resource registry mappings, the parameters apply only to the top-level template and not templates for the nested resources. Parameters are defined in the
parameterssection of an environment file. - Parameter Defaults
-
These parameters modify the default values for parameters in all templates. For example, if you have a heat template that deploys nested stacks, such as resource registry mappings,the parameter defaults apply to all templates. The parameter defaults are defined in the
parameter_defaultssection of an environment file.
Use parameter_defaults instead of parameters when you create custom environment files for your overcloud. This is so that the parameters apply to all stack templates for the overcloud.
Example of a basic environment file:
The environment file,my_env.yaml, might be included when creating a stack from a heat template, my_template.yaml. The my_env.yaml file creates a new resource type called OS::Nova::Server::MyServer. The myserver.yaml file is a heat template file that provides an implementation for this resource type that overrides any built-in ones. You can include the OS::Nova::Server::MyServer resource in your my_template.yaml file.
The MyIP applies a parameter only to the main heat template that deploys with this environment file. In this example, it only applies to the parameters in my_template.yaml.
The NetworkName applies to both the main heat template, my_template.yaml, and the templates that are associated with the resources that are included the main template, such as the OS::Nova::Server::MyServer resource and its myserver.yaml template in this example.
For RHOSP to use the heat template file as a custom template resource, the file extension must be either .yaml or .template.
2.3. Core Overcloud Heat Templates Copiar o linkLink copiado para a área de transferência!
The director contains a core heat template collection for the Overcloud. This collection is stored in /usr/share/openstack-tripleo-heat-templates.
The main files and directories in this template collection are:
overcloud.j2.yaml- This is the main template file that creates the overcloud environment. This file uses Jinja2 syntax to iterate over certain sections in the template to create custom roles. The Jinja2 formatting is rendered into YAML during the overcloud deployment process.
overcloud-resource-registry-puppet.j2.yaml- This is the main environment file that creates the overcloud environment. It provides a set of configurations for Puppet modules that are stored on the overcloud image. After director writes the overcloud image to each node, heat starts the Puppet configuration for each node by using the resources registered in this environment file. This file uses Jinja2 syntax to iterate over certain sections in the template to create custom roles. The Jinja2 formatting is rendered into YAML during the overcloud deployment process.
roles_data.yaml- This is a file that defines the roles in an overcloud and maps services to each role.
network_data.yaml-
This is a file that defines the networks in an overcloud and their properties such as subnets, allocation pools, and VIP status. The default
network_datafile contains the default networks: External, Internal Api, Storage, Storage Management, Tenant, and Management. You can create a customnetwork_datafile and add it to youropenstack overcloud deploycommand with the-noption. plan-environment.yaml- This is a file that defines the metadata for your overcloud plan. This includes the plan name, main template to use, and environment files to apply to the overcloud.
capabilities-map.yaml-
This is a mapping of environment files for an overcloud plan. Use this file to describe and enable environment files on the director web UI. Custom environment files that are detected in the
environmentsdirectory in an overcloud plan but are not defined in thecapabilities-map.yamlare listed in the Other subtab of 2 Specify Deployment Configuration > Overall Settings on the web UI. environments-
Contains additional heat environment files that you can use with your overcloud creation. These environment files enable extra functions for your resulting Red Hat OpenStack Platform (RHOSP) environment. For example, the directory contains an environment file to enable Cinder NetApp backend storage (
cinder-netapp-config.yaml). Any environment files that are detected in this directory that are not defined in thecapabilities-map.yamlfile are listed in the Other subtab of 2 Specify Deployment Configuration > Overall Settings in the director’s web UI. network- This is a set of heat templates to help create isolated networks and ports.
puppet-
These are templates that are mostly driven by configuration with Puppet. The
overcloud-resource-registry-puppet.j2.yamlenvironment file uses the files in this directory to drive the application of the Puppet configuration on each node. puppet/services- This is a directory that contains heat templates for all services in the composable service architecture.
extraconfig- These are templates that enable extra functionality.
firstboot-
Provides example
first_bootscripts that director uses when it initially creates the nodes.
2.4. Plan Environment Metadata Copiar o linkLink copiado para a área de transferência!
A plan environment metadata file allows you to define metadata about your overcloud plan. This information is used when importing and exporting your overcloud plan, plus used during the overcloud creation from your plan.
A plan environment metadata file includes the following parameters:
- version
- The version of the template.
- name
- The name of the overcloud plan and the container in OpenStack Object Storage (swift) used to store the plan files.
- template
-
The core parent template to use for the overcloud deployment. This is most often
overcloud.yaml, which is the rendered version of theovercloud.yaml.j2template. - environments
-
Defines a list of environment files to use. Specify the path of each environment file with the
pathsub-parameter. - parameter_defaults
-
A set of parameters to use in your overcloud. This functions in the same way as the
parameter_defaultssection in a standard environment file. - passwords
-
A set of parameters to use for overcloud passwords. This functions in the same way as the
parameter_defaultssection in a standard environment file. Normally, the director automatically populates this section with randomly generated passwords. - workflow_parameters
- Allows you to provide a set of parameters to OpenStack Workflow (mistral) namespaces. You can use this to calculate and automatically generate certain overcloud parameters.
The following is an example of the syntax of a plan environment file:
You can include the plan environment metadata file with the openstack overcloud deploy command using the -p option. For example:
(undercloud) $ openstack overcloud deploy --templates \ -p /my-plan-environment.yaml \ [OTHER OPTIONS]
(undercloud) $ openstack overcloud deploy --templates \
-p /my-plan-environment.yaml \
[OTHER OPTIONS]
You can also view plan metadata for an existing overcloud plan using the following command:
(undercloud) $ openstack object save overcloud plan-environment.yaml --file -
(undercloud) $ openstack object save overcloud plan-environment.yaml --file -
2.5. Capabilities Map Copiar o linkLink copiado para a área de transferência!
The capabilities map provides a mapping of environment files in your plan and their dependencies. Use this file to describe and enable environment files through the director’s web UI. Custom environment files detected in an overcloud plan but not listed in the capabilities-map.yaml are listed in the Other subtab of 2 Specify Deployment Configuration > Overall Settings on the web UI.
The default file is located at /usr/share/openstack-tripleo-heat-templates/capabilities-map.yaml.
The following is an example of the syntax for a capabilities map:
- 1
- The
topicsparameter contains a list of sections in the UI’s deployment configuration. Each topic is displayed as a single screen of environment options and contains multiple environment groups, which you define with theenvironment_groupsparameter. Each topic can have a plain texttitleanddescription. - 2
- The
environment_groupsparameter lists groupings of environment files in the UI’s deployment configuration. For example, on a storage topic, you might have an environment group for Ceph-related environment files. Each environment group can have a plain texttitleanddescription. - 3
- The
environmentsparameter shows all environment files that belong to an environment group. Thefileparameter is the location of the environment file. Each environment entry can have a plain texttitleanddescription. - 4 5
- The
requiresparameter is a list of dependencies for an environment file. In this example, bothenvironment_file_1.yamlandenvironment_file_2.yamlrequire you to enabledependent_environment_file.yamltoo.
Red Hat OpenStack Platform uses this file to add access to features to the director UI. It is recommended not to modify this file as newer versions of Red Hat OpenStack Platform might override this file.
2.6. Including Environment Files in Overcloud Creation Copiar o linkLink copiado para a área de transferência!
The deployment command (openstack overcloud deploy) uses the -e option to include an environment file to customize your Overcloud. You can include as many environment files as necessary. However, the order of the environment files is important as the parameters and resources defined in subsequent environment files take precedence. For example, you might have two environment files:
environment-file-1.yaml
environment-file-2.yaml
resource_registry: OS::TripleO::NodeExtraConfigPost: /home/stack/templates/template-2.yaml parameter_defaults: TimeZone: 'Hongkong'
resource_registry:
OS::TripleO::NodeExtraConfigPost: /home/stack/templates/template-2.yaml
parameter_defaults:
TimeZone: 'Hongkong'
Then deploy with both environment files included:
openstack overcloud deploy --templates -e environment-file-1.yaml -e environment-file-2.yaml
$ openstack overcloud deploy --templates -e environment-file-1.yaml -e environment-file-2.yaml
In this example, both environment files contain a common resource type (OS::TripleO::NodeExtraConfigPost) and a common parameter (TimeZone). The openstack overcloud deploy command runs through the following process:
-
Loads the default configuration from the core Heat template collection as per the
--templateoption. -
Applies the configuration from
environment-file-1.yaml, which overrides any common settings from the default configuration. -
Applies the configuration from
environment-file-2.yaml, which overrides any common settings from the default configuration andenvironment-file-1.yaml.
This results in the following changes to the default configuration of the Overcloud:
-
OS::TripleO::NodeExtraConfigPostresource is set to/home/stack/templates/template-2.yamlas perenvironment-file-2.yaml. -
TimeZoneparameter is set toHongkongas perenvironment-file-2.yaml. -
RabbitFDLimitparameter is set to65536as perenvironment-file-1.yaml.environment-file-2.yamldoes not change this value.
This provides a method for defining custom configuration to the your Overcloud without values from multiple environment files conflicting.
2.7. Using Customized Core Heat Templates Copiar o linkLink copiado para a área de transferência!
When creating the overcloud, the director uses a core set of Heat templates located in /usr/share/openstack-tripleo-heat-templates. If you want to customize this core template collection, use a Git workflow to track changes and merge updates. Use the following git processes to help manage your custom template collection:
Initializing a Custom Template Collection
Use the following procedure to create an initial Git repository containing the Heat template collection:
Copy the template collection to the
stackusers directory. This example copies the collection to the~/templatesdirectory:cd ~/templates cp -r /usr/share/openstack-tripleo-heat-templates .
$ cd ~/templates $ cp -r /usr/share/openstack-tripleo-heat-templates .Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change to the custom template directory and initialize a Git repository:
cd openstack-tripleo-heat-templates git init .
$ cd openstack-tripleo-heat-templates $ git init .Copy to Clipboard Copied! Toggle word wrap Toggle overflow Configure your Git user name and email address:
git config --global user.name "<USER_NAME>" git config --global user.email "<EMAIL_ADDRESS>"
$ git config --global user.name "<USER_NAME>" $ git config --global user.email "<EMAIL_ADDRESS>"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Replace
<USER_NAME>with the user name that you want to use. Replace<EMAIL_ADDRESS>with your email address.Stage all templates for the initial commit:
git add *
$ git add *Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create an initial commit:
git commit -m "Initial creation of custom core heat templates"
$ git commit -m "Initial creation of custom core heat templates"Copy to Clipboard Copied! Toggle word wrap Toggle overflow
This creates an initial master branch containing the latest core template collection. Use this branch as the basis for your custom branch and merge new template versions to this branch.
Creating a Custom Branch and Committing Changes
Use a custom branch to store your changes to the core template collection. Use the following procedure to create a my-customizations branch and add customizations to it:
Create the
my-customizationsbranch and switch to it:git checkout -b my-customizations
$ git checkout -b my-customizationsCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Edit the files in the custom branch.
Stage the changes in git:
git add [edited files]
$ git add [edited files]Copy to Clipboard Copied! Toggle word wrap Toggle overflow Commit the changes to the custom branch:
git commit -m "[Commit message for custom changes]"
$ git commit -m "[Commit message for custom changes]"Copy to Clipboard Copied! Toggle word wrap Toggle overflow
This adds your changes as commits to the my-customizations branch. When the master branch updates, you can rebase my-customizations off master, which causes git to add these commits on to the updated template collection. This helps track your customizations and replay them on future template updates.
Updating the Custom Template Collection:
When updating the undercloud, the openstack-tripleo-heat-templates package might also update. When this occurs, use the following procedure to update your custom template collection:
Save the
openstack-tripleo-heat-templatespackage version as an environment variable:export PACKAGE=$(rpm -qv openstack-tripleo-heat-templates)
$ export PACKAGE=$(rpm -qv openstack-tripleo-heat-templates)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change to your template collection directory and create a new branch for the updated templates:
cd ~/templates/openstack-tripleo-heat-templates git checkout -b $PACKAGE
$ cd ~/templates/openstack-tripleo-heat-templates $ git checkout -b $PACKAGECopy to Clipboard Copied! Toggle word wrap Toggle overflow Remove all files in the branch and replace them with the new versions:
git rm -rf * cp -r /usr/share/openstack-tripleo-heat-templates/* .
$ git rm -rf * $ cp -r /usr/share/openstack-tripleo-heat-templates/* .Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add all templates for the initial commit:
git add *
$ git add *Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a commit for the package update:
git commit -m "Updates for $PACKAGE"
$ git commit -m "Updates for $PACKAGE"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Merge the branch into master. If using a Git management system (such as GitLab) use the management workflow. If using git locally, merge by switching to the
masterbranch and run thegit mergecommand:git checkout master git merge $PACKAGE
$ git checkout master $ git merge $PACKAGECopy to Clipboard Copied! Toggle word wrap Toggle overflow
The master branch now contains the latest version of the core template collection. You can now rebase the my-customization branch from this updated collection.
Rebasing the Custom Branch
Use the following procedure to update the my-customization branch,:
Change to the
my-customizationsbranch:git checkout my-customizations
$ git checkout my-customizationsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Rebase the branch off
master:git rebase master
$ git rebase masterCopy to Clipboard Copied! Toggle word wrap Toggle overflow
This updates the my-customizations branch and replays the custom commits made to this branch.
If git reports any conflicts during the rebase, use this procedure:
Check which files contain the conflicts:
git status
$ git statusCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Resolve the conflicts of the template files identified.
Add the resolved files
git add [resolved files]
$ git add [resolved files]Copy to Clipboard Copied! Toggle word wrap Toggle overflow Continue the rebase:
git rebase --continue
$ git rebase --continueCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Deploying Custom Templates
Use the following procedure to deploy the custom template collection:
Make sure you have switched to the
my-customizationbranch:git checkout my-customizations
git checkout my-customizationsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run the
openstack overcloud deploycommand with the--templatesoption to specify your local template directory:openstack overcloud deploy --templates /home/stack/templates/openstack-tripleo-heat-templates [OTHER OPTIONS]
$ openstack overcloud deploy --templates /home/stack/templates/openstack-tripleo-heat-templates [OTHER OPTIONS]Copy to Clipboard Copied! Toggle word wrap Toggle overflow
The director uses the default template directory (/usr/share/openstack-tripleo-heat-templates) if you specify the --templates option without a directory.
Red Hat recommends using the methods in Chapter 4, Configuration Hooks instead of modifying the heat template collection.
2.8. Jinja2 rendering Copiar o linkLink copiado para a área de transferência!
The core Heat templates in /usr/share/openstack-tripleo-heat-templates contains a number of files ending with a j2.yaml extension. These files contain Jinja2 template syntax and the director renders these files to their static Heat template equivalents ending in .yaml. For example, the main overcloud.j2.yaml file renders into overcloud.yaml. The director uses the resulting overcloud.yaml file.
The Jinja2-enabled Heat templates use Jinja2 syntax to create parameters and resources for iterative values. For example, the overcloud.j2.yaml file contains the following snippet:
When the director renders the Jinja2 syntax, the director iterates over the roles defined in the roles_data.yaml file and populates the {{role.name}}Count parameter with the name of the role. The default roles_data.yaml file contains five roles and results in the the following parameters from our example:
-
ControllerCount -
ComputeCount -
BlockStorageCount -
ObjectStorageCount -
CephStorageCount
A example rendered version of the parameter looks like this:
The director only renders Jinja2-enabled templates and environment files within the directory of your core Heat templates. The following use cases demonstrate the correct method to render the Jinja2 templates.
Use case 1: Default core templates
Template directory: /usr/share/openstack-tripleo-heat-templates/
Environment file: /usr/share/openstack-tripleo-heat-templates/environments/network-isolation.j2.yaml
The director uses the default core template location (--templates). The director renders the network-isolation.j2.yaml file into network-isolation.yaml. When running the openstack overcloud deploy command, use the -e option to include the name of rendered network-isolation.yaml file.
openstack ovecloud deploy --templates \
-e /usr/share/openstack-tripleo-heat-templates/environments/network-isolation.yaml
$ openstack ovecloud deploy --templates \
-e /usr/share/openstack-tripleo-heat-templates/environments/network-isolation.yaml
...
Use case 2: Custom core templates
Template directory: /home/stack/tripleo-heat-templates
Environment file: /home/stack/tripleo-heat-templates/environments/network-isolation.j2.yaml
The director uses a custom core template location (--templates /home/stack/tripleo-heat-templates). The director renders the network-isolation.j2.yaml file within the custom core templates into network-isolation.yaml. When running the openstack overcloud deploy command, use the -e option to include the name of rendered network-isolation.yaml file.
openstack ovecloud deploy --templates /home/stack/tripleo-heat-templates \
-e /home/stack/tripleo-heat-templates/environments/network-isolation.yaml
$ openstack ovecloud deploy --templates /home/stack/tripleo-heat-templates \
-e /home/stack/tripleo-heat-templates/environments/network-isolation.yaml
...
Use case 3: Incorrect usage
Template directory: /usr/share/openstack-tripleo-heat-templates/
Environment file: /home/stack/tripleo-heat-templates/environments/network-isolation.j2.yaml
This director uses a custom core template location (--templates /home/stack/tripleo-heat-templates). However, the chosen network-isolation.j2.yaml is not located within the custom core templates, so it will not render into network-isolation.yaml. This causes the deployment to fail.