Este conteúdo não está disponível no idioma selecionado.
Chapter 3. Working with templates
3.1. Customized self-service templates Copiar o linkLink copiado para a área de transferência!
Custom self-service templates are stored as YAML files in repositories in GitHub or Gitlab. When a user launches a software template from self-service automation portal, they must fill in a form with the values needed to run the associated job template in Ansible Automation Platform.
The custom self-service template YAML file must have a token: section that includes a ui:field: key for the authentication token for Ansible Automation Platform. This generates a field for the token in the form that appears when the user launches the template in self-service automation portal. The user enters the token: it is used to authenticate job template execution in Ansible Automation Platform.
The following example shows the token: section in a template. For security reasons, set the value of token.ui:backstage.review.show to false to ensure that the token is not visible to the user.
spec:
...
parameters:
...
properties:
token:
title: Token
type: string
description: Oauth2 token
ui:field: AAPTokenField
ui:widget: hidden
ui:backstage:
review:
show: false
Setting the ui:widget: hidden field hides the Red Hat Ansible Automation Platform token input in the form.
3.2. Understanding auto-generated templates Copiar o linkLink copiado para a área de transferência!
self-service automation portal automatically generates templates from Ansible Automation Platform Job Templates. Each Ansible Automation Platform Job Template with the appropriate configuration becomes a template that users can execute from self-service automation portal.
Templates in self-service automation portal use Backstage Software Templates as the underlying technology. For details on supported usage, see the self-service automation portal support policy.
Auto-generated templates include:
- Form fields generated from Ansible Automation Platform Job Template Surveys and "Prompt on Launch" options.
- Metadata (name, description, labels) mapped from Ansible Automation Platform Job Template properties.
-
A single step that launches the Ansible Automation Platform Job Template using the
rhaap:launch-job-templateaction. - Output that displays the job execution results to the user.
Users only see and execute templates for Ansible Automation Platform Job Templates they have Job Template Execute permission in Ansible Automation Platform.
3.2.1. What users see Copiar o linkLink copiado para a área de transferência!
Auto-generated templates appear in the template catalog alongside custom templates. Users browse or search the catalog and select a template to run.
When a user opens an auto-generated template, self-service automation portal checks the Ansible Automation Platform Job Template for Prompt on Launch options and Survey questions. If the Job Template has Prompt on Launch options or Survey questions, self-service automation portal displays a form. Users select Ansible Automation Platform resources by name (such as Inventories or Credentials) and answer survey questions (such as application name or environment). self-service automation portal handles authentication automatically, so credentials are not visible on the form. If the Job Template has no Prompt on Launch options or Survey questions, the Job Template starts running automatically without displaying a form.
After the user submits the form or execution starts automatically, self-service automation portal launches the Ansible Automation Platform Job Template and displays an output page. The output page shows the job ID, job status, and optional links such as a direct link to the job in Ansible Automation Platform.
Users do not need to understand YAML or the template structure. The form collects the required input, and the output page displays the results.
3.2.2. Auto-generated template example Copiar o linkLink copiado para a área de transferência!
The following example shows a template that self-service automation portal auto-generates from an existing Ansible Automation Platform Job Template. Every field in the generated YAML maps directly to an Ansible Automation Platform artifact:
-
The Ansible Automation Platform Job Template name and description become
metadatafields. -
Each Prompt on Launch option becomes an
AAPResourcePickerfield. - Each Ansible Automation Platform Survey question becomes a standard form field.
-
The
stepssection launches the original Ansible Automation Platform Job Template using therhaap:launch-job-templateaction.
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
# Namespace is hardcoded to "default"
namespace: default
# AAP artifact: Job Template name lowercase with hyphens
name: deploy-application
# AAP artifact: Job Template name title (copied directly)
title: Deploy Application
# AAP artifact: Job Template description description (copied directly)
description: Deploy application to target environment
# AAP artifact: Job Template labels tags (lowercase)
tags:
- automation
- aap
# AAP artifact: Job Template URL annotations
annotations:
backstage.io/techdocs-ref: url:https://aap.example.com/#/templates/job_template/42
backstage.io/source-location: url:https://aap.example.com/#/templates/job_template/42
spec:
type: service
parameters:
- title: "Please enter the following details"
required:
- token
- inventory
- app_name
properties:
# Always present: OAuth token for AAP authentication (hidden from user)
token:
title: Token
type: string
description: Oauth2 token
ui:field: AAPTokenField
ui:widget: hidden
ui:backstage:
review:
show: false
ui:options:
disabled: true
hidden: true
# AAP artifact: "Prompt on Launch" Inventory (users select by name; self-service portal resolves to AAP ID)
inventory:
title: Inventory
description: Please enter the inventory you want to use the services on
resource: inventories
ui:field: AAPResourcePicker
default: Production Servers
# AAP artifact: Survey question "Application Name" (variable, title, type, default from survey spec)
app_name:
title: Application Name
description: Name of the application to deploy
type: string
default: my-app
steps:
- id: launch-job
# AAP artifact: Job Template name used as the step name
name: Deploy Application
action: rhaap:launch-job-template
input:
token: ${{ parameters.token }}
values:
# AAP artifact: Job Template name identifies which template to launch
template: Deploy Application
# "Prompt on Launch" values passed as launch parameters
inventory: ${{ parameters.inventory }}
# Survey answers passed as extra variables to AAP
extraVariables:
app_name: ${{ parameters.app_name }}
output:
text:
- title: Deploy Application template executed successfully
content: |
**Job ID:** ${{ steps['launch-job'].output.data.id }}
**Job status:** ${{ steps['launch-job'].output.data.status }}
The following table maps each generated field to its Ansible Automation Platform source:
| Ansible Automation Platform source | Ansible Automation Platform value | Generated field | Transformation |
|---|---|---|---|
| N/A |
|
|
Hardcoded to |
|
Job Template | Deploy Application |
| Lowercase with hyphens. |
|
Job Template | Deploy Application |
| Copied directly. |
|
Job Template | Deploy application to target environment |
| Copied directly. |
|
Job Template |
|
| Lowercase, special characters replaced with hyphens. |
| Always present | OAuth2 token |
| Auto-populated and hidden from user. |
|
Prompt on Launch | Production Servers |
|
|
|
Survey | app_name (text, required, default: "my-app") |
| Variable, title, type, and default copied from Survey spec. |
|
Job Template | Deploy Application |
| Identifies which Ansible Automation Platform Job Template to launch. |
| Prompt on Launch value |
|
| Name resolved to Ansible Automation Platform ID at launch. |
| Survey answers |
|
|
Passed as |
3.2.3. How templates are generated Copiar o linkLink copiado para a área de transferência!
When synchronization runs, self-service automation portal reads Ansible Automation Platform Job Template configurations and generates corresponding templates. self-service automation portal maps Ansible Automation Platform Job Template properties to template fields as follows.
3.2.3.1. Metadata mapping Copiar o linkLink copiado para a área de transferência!
The following table shows how Ansible Automation Platform Job Template properties are mapped to template metadata fields:
| Ansible Automation Platform Job Template property | Generated template field | Transformation |
|---|---|---|
| Name |
| Converted to lowercase with hyphens |
| Name |
| Copied directly |
| Description |
| Copied directly |
| Labels |
| Converted to lowercase, special characters replaced with hyphens |
| N/A |
|
Hardcoded to |
3.2.3.2. Parameter mapping Copiar o linkLink copiado para a área de transferência!
The following table shows how Ansible Automation Platform Job Template sources are mapped to template parameters:
| Ansible Automation Platform Job Template source | Generated template parameter type |
|---|---|
| Survey questions |
Standard form fields ( |
| "Prompt on Launch" options |
|
3.2.3.3. Field order Copiar o linkLink copiado para a área de transferência!
self-service automation portal generates form fields from two sources in the Ansible Automation Platform Job Template configuration. Fields appear in the following order:
- OAuth token (hidden): Auto-populated with the user’s authentication token. This field is always present and always hidden.
-
"Prompt on Launch" fields: Each enabled "Prompt on Launch" option becomes an
AAPResourcePickerfield. Users select Ansible Automation Platform resources by name (Inventories, Credentials, Execution Environments). self-service automation portal resolves names to Ansible Automation Platform internal IDs at launch time. -
Survey questions: Each survey question becomes a form field with the matching input type (
text,dropdown,password,textarea,integer,float,multiplechoice,multiselect).
3.2.3.4. Defaults and required fields Copiar o linkLink copiado para a área de transferência!
- Survey question defaults and required/optional settings are preserved from the Ansible Automation Platform Job Template Survey.
- "Prompt on Launch" fields use the current Ansible Automation Platform Job Template settings for defaults and required/optional status.
- Ansible Automation Platform resource picker fields display resource names, not internal IDs.
3.3. Adding a template to self-service automation portal Copiar o linkLink copiado para a área de transferência!
You can add a custom self-service template to the Templates view of your self-service automation portal instance. Custom self-service templates are stored in git repositories. self-service automation portal supports GitLab and GitHub Source Control Management (SCM).
Names for custom self-service templates must be unique. Custom self-service templates must have a different name to auto-generated job templates and also to other custom self-service templates.
Prerequisites
- You have created repositories in your Git SCM for the templates that you want to use.
-
In the git repository for your custom templates, ensure that the
metadata.namefield is unique and does not match an existing auto-generated template or another custom self-service template. For example, append*-customto the value of themetadata.namekey.
metadata:
name: provision-database-custom
- You must be logged in to self-service automation portal as an Ansible Automation Platform platform administrator.
Procedure
- In a browser, navigate to your self-service automation portal instance and sign in with your Ansible Automation Platform credentials.
- Navigate to the Templates Page.
- Click .
- Enter a valid Git SCM URL for the template that you want to add.
- Click to fetch the template.
- After the template has been fetched, review the list of what will be imported and added to the catalog.
- Click .
Verification
After the import is complete, return to the Templates page to view the newly created template. You can now launch your template.
3.4. Launching a template Copiar o linkLink copiado para a área de transferência!
This procedure describes how to launch a template from a tile in the Templates view of your self-service automation portal instance.
Prerequisites
You have configured RBAC in Ansible Automation Platform for templates that are associated with Ansible Automation Platform job templates.
Procedure
- In a browser, navigate to your self-service automation portal instance and sign in with your Ansible Automation Platform credentials.
- Navigate to the Templates page. The templates you have set up are displayed as tiles on the page.
In the template that you want to launch, click Start.
A description of the template is displayed.
- Click Launch to begin configuring the parameters for running the template.
- Fill out the required fields.
- Click Next.
- Review the entered information.
- Click Create to launch the template.
- The progress for the template execution is displayed.