Templates¶
Templates can be created directly in Morpheus and/or sourced from version control, depending on the type. They can be used to help users consume IaC technologies, generate configuration files, utilize scripts or store security scan packages. Once stored, they can be used with provisioned Instances, configured as part of Tasks or Workflows, or run regularly as part of security scan Jobs. Each section below discusses template types in greater detail.
Spec Templates¶
Spec Templates allow Morpheus users to leverage several major Infrastructure-as-Code solutions. These are typically JSON or YAML-based configuration files which make creating and managing multiple resource types easier. Morpheus allows users to create and/or manage a collection of these templates for different solutions and from different sources.
Morpheus currently supports Spec Templates of the following types:
Kubernetes Spec
Helm Chart
Terraform
ARM Template
CloudFormation Template
OneView Server Profile Template
UCS Service Profile Template
Morpheus also allows users to leverage templates pulled from URL sources, online repositories (such as GitHub), or you can write a template locally inside the “NEW SPEC TEMPLATE” modal.
Tip
To see Morpheus Spec Templates in action, take a look at our guide on creating custom Instance Types using Terraform or see our KnowledgeBase for another example where a CloudFormation Spec Template is used to create a provisionable custom Instance Type.
Creating a Spec Template¶
Navigate to Library > Templates > Spec Templates
Click + ADD
Complete the following fields, then click SAVE CHANGES:
NAME
TYPE: See the previous section for a complete list of Spec Template types
SOURCE: Local, Repository, or URL
CONTENT: If this is a local Spec Template, supply the template in this field. If the template is supplied through a URL or online repository, the CONTENT field will change to allow the user to point Morpheus to that resource
VERSION: (Only displayed on Terraform Spec Templates) Enter a Terraform version number to force a specific version when provisioning your Terraform Instance Type or App, assuming your Terraform Runtime setting (Administration > Settings > Provisioning Tab) is “auto”. If Terraform Runtime is set to “manual”, Morpheus will use the version of Terraform installed on the appliance box
File Templates¶
File Templates are for generating config files, such as my.cnf, elasticsearch.yml, morpheus.rb, or any text file. With full config map variable support, Template Files are dynamically generated during a Workflow phase or ad hoc via Instance actions.
File Templates can also be exposed on Instances in the Settings Tab. Ensure the Instance Type supports settings, and Category is defined in Advance Options on the Library Template config.
Note
Morpheus variables are supported in Library Templates using <%= variable.var %>
format
Examples:
HA Proxy Config (haproxy.cfg)
FILE NAME: haproxy.cfg
FILE PATH: /config/haproxy.cfg
PHASE: Pre Provision
TEMPLATE:
SETTING NAME: haproxyConfig
SETTING CATEGORY: haproxy
#!/bin/bash
global
maxconn 256
log /dev/log local0 warning
log-tag <%=logTag%>
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
log global
frontend http-in
bind *:<%=container.externalPort%>
default_backend servers
backend servers
# server server1 127.0.0.1:80 maxconn 32
mysql config (mysqld.cnf)
FILE NAME: mysqld.cnf
FILE PATH: /config/mysqld.cnf
PHASE: Pre Provision
#!/bin/bash
[mysqld]
pid-file= /var/run/mysqld/mysqld.pid
socket= /var/run/mysqld/mysqld.sock
datadir= /var/lib/mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
explicit_defaults_for_timestamp = 1
Script Templates¶
Scripts are bash and Powershell scripts that can be attached to Node Types to always execute at the selected phase when that Node Type is provisioned, added to Workflows as Library Script Tasks, and/or executed ad-hoc on Instances.
Creating Scripts¶
Navigate to Library > Templates > Script Templates
Select + ADD
Enter the Following:
- NAME
Name of the Script in Morpheus
- SCRIPT TYPE
Bash
Powershell
- PHASE
Select which phase the Script will execute when attached to a Node Type. When a script is attached to a Node Type, it will execute according to the selcted phase:
- Start Service
Any time the Instance action
Start Service
is executed- Stop Service
Any time the Instance action
Stop Service
is executed- Pre-Provision
Containers: Script will execute against the container host before the container is provisioned
Virtual Machines: Script will execute before any provision phase Scripts or Tasks
- Provision
Script will execute once per new Instance node during the provision Phase. Provisioning will not be considered complete until all scripts and tasks in the provisioning phase are completed
Note
Any Script or Task set to the provision phase will be included in the total provision time and impact success/warn/failure provisioning status messages. As an example, your VM could be up and running but if your Script is in the provision phase and fails, provisioning will be marked as a failure.
- Post-Provision
Script will execute once per new Instance node after the provision phase is completed. Scripts and Tasks in the Post-Provision phase will show execution status and history, but are not considered part of the provision and do not impact provisioning status.
- Pre-Deploy
Script will execute on target Instance any time a deployment is run against the Instance. The Script will run prior to the deployment file(s) being written
- Deploy
Script will execute on target Instance any time a deployment is run against the Instance. The script will run after the deployment file(s) are written
- Reconfigure
Script will execute on target Instance any time a reconfigure is executed against the Instance.
- Teardown
Script will execute on target Instance upon Instance deletion. Script will execute against target Instance prior to the deletion/removal of resources.
- SCRIPT
Enter Bash or Powershell script.
Note
Morpheus variables are supported in Library Scripts using
<%= variable.var %>
format- RUN AS USER
By default Scripts are execute as
morpheus-node
. To execute as another User, populateRUN AS USER
and ensure proper user permissions & group access- SUDO
Flag
SUDO
if sudo is required to execute the Script
To attach Scripts and templates that have been added to the Library to a Node Type, start typing the name and then select the script(s) and/or template(s).
Multiple scripts and templates can be added to a Node Type
Scripts and Templates can be added/shared among multiple Node Types
The execution phase can be set for Scripts in the Scripts section
Search will populate Scripts or Templates containing the characters entered anywhere in their name, not just the first letter(s) of the name
Security Packages¶
The Security Packages Section is for uploading SCAP packages which can then be consumed in Security Scan Jobs (Provisioning > Jobs).
Add a new Security Package¶
Navigate to Library > Templates > Security Packages
Click +ADD > SCAP Package
Provide a name in addition to a URL to source the package
Click SAVE CHANGES
Note
Currently URL is the only source option for security packages