Este conteúdo não está disponível no idioma selecionado.

Chapter 3. Working with templates


3.1. Customized self-service templates

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
Note

Setting the ui:widget: hidden field hides the Red Hat Ansible Automation Platform token input in the form.

3.2. Understanding auto-generated templates

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.

Note

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-template action.
  • 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

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

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 metadata fields.
  • Each Prompt on Launch option becomes an AAPResourcePicker field.
  • Each Ansible Automation Platform Survey question becomes a standard form field.
  • The steps section launches the original Ansible Automation Platform Job Template using the rhaap:launch-job-template action.
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:

Expand
Table 3.1. Field mapping
Ansible Automation Platform sourceAnsible Automation Platform valueGenerated fieldTransformation

N/A

default

metadata.namespace

Hardcoded to default.

Job Template Name

Deploy Application

metadata.name

Lowercase with hyphens.

Job Template Name

Deploy Application

metadata.title

Copied directly.

Job Template Description

Deploy application to target environment

metadata.description

Copied directly.

Job Template Labels

automation, aap

metadata.tags

Lowercase, special characters replaced with hyphens.

Always present

OAuth2 token

parameters.token

Auto-populated and hidden from user.

Prompt on Launch Inventory

Production Servers

parameters.inventory

AAPResourcePicker; user selects by name, resolved to Ansible Automation Platform ID at launch.

Survey Question 1

app_name (text, required, default: "my-app")

parameters.app_name

Variable, title, type, and default copied from Survey spec.

Job Template Name

Deploy Application

input.values.template

Identifies which Ansible Automation Platform Job Template to launch.

Prompt on Launch value

${{ parameters.inventory }}

input.values.inventory

Name resolved to Ansible Automation Platform ID at launch.

Survey answers

${{ parameters.app_name }}

input.values.extraVariables

Passed as extra_vars to the Ansible Automation Platform Job.

3.2.3. How templates are generated

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

The following table shows how Ansible Automation Platform Job Template properties are mapped to template metadata fields:

Expand
Table 3.2. Metadata mapping
Ansible Automation Platform Job Template propertyGenerated template fieldTransformation

Name

metadata.name

Converted to lowercase with hyphens

Name

metadata.title

Copied directly

Description

metadata.description

Copied directly

Labels

metadata.tags

Converted to lowercase, special characters replaced with hyphens

N/A

metadata.namespace

Hardcoded to default

3.2.3.2. Parameter mapping

The following table shows how Ansible Automation Platform Job Template sources are mapped to template parameters:

Expand
Table 3.3. Parameter mapping
Ansible Automation Platform Job Template sourceGenerated template parameter type

Survey questions

Standard form fields (type: string, enum, ui:widget)

"Prompt on Launch" options

AAPResourcePicker fields for Ansible Automation Platform resources

3.2.3.3. Field order

self-service automation portal generates form fields from two sources in the Ansible Automation Platform Job Template configuration. Fields appear in the following order:

  1. OAuth token (hidden): Auto-populated with the user’s authentication token. This field is always present and always hidden.
  2. "Prompt on Launch" fields: Each enabled "Prompt on Launch" option becomes an AAPResourcePicker field. 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.
  3. 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

  • 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

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).

Note

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.name field is unique and does not match an existing auto-generated template or another custom self-service template. For example, append *-custom to the value of the metadata.name key.
metadata:
  name: provision-database-custom
  • You must be logged in to self-service automation portal as an Ansible Automation Platform platform administrator.

Procedure

  1. In a browser, navigate to your self-service automation portal instance and sign in with your Ansible Automation Platform credentials.
  2. Navigate to the Templates Page.
  3. Click Add template.
  4. Enter a valid Git SCM URL for the template that you want to add.
  5. Click Analyze to fetch the template.
  6. After the template has been fetched, review the list of what will be imported and added to the catalog.
  7. Click Import.

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

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

  1. In a browser, navigate to your self-service automation portal instance and sign in with your Ansible Automation Platform credentials.
  2. Navigate to the Templates page. The templates you have set up are displayed as tiles on the page.
  3. In the template that you want to launch, click Start.

    A description of the template is displayed.

  4. Click Launch to begin configuring the parameters for running the template.
  5. Fill out the required fields.
  6. Click Next.
  7. Review the entered information.
  8. Click Create to launch the template.
  9. The progress for the template execution is displayed.
Red Hat logoGithubredditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

Theme

© 2026 Red Hat
Voltar ao topo