5.3. 自定义后阶段操作
通过以下操作,您可以在软件模板工作流中管理 Ansible Automation Platform 资源。
5.3.1. rhaap:create-project 复制链接链接已复制到粘贴板!
创建一个 Ansible Automation Platform 项目,它链接到包含 Ansible 内容的源控制存储库。
输入参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
|
| string | 是 | 用于 Ansible Automation Platform 身份验证的 OAuth2 令牌。 |
|
| 布尔值 | 否 |
如果为 |
|
| object | 是 | 项目配置对象。请参阅"值"对象结构表。 |
"values" 对象结构
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
|
| string | 是 | 项目的名称。 |
|
| string | 否 | 项目的描述。 |
|
| object | 是 |
带有 |
|
| object | 否 |
带有 |
|
| string | 是 | 源控制 URL (如 GitHub/GitLab 存储库 URL)。 |
|
| string | 否 | 源控制分支、标签或提交。 |
|
| 布尔值 | 否 |
如果为 |
输出参数
| 参数 | 类型 | 描述 |
|---|---|---|
|
| object | 创建项目详情。 |
|
| number | Ansible Automation Platform (AAP)中的项目 ID。 |
|
| string | 项目名称。 |
|
| string | 项目描述. |
|
| string | 项目的 Ansible Automation Platform URL。 |
示例
steps:
- id: create-aap-project
name: Create AAP Project
action: rhaap:create-project
input:
token: ${{ parameters.AAP_TOKEN }}
deleteIfExist: true
values:
projectName: ${{ parameters.projectName }}
organization: ${{ parameters.organization }}
scmUrl: https://github.com/my-org/ansible-playbooks
scmBranch: main
scmUpdateOnLaunch: true
credentials: GitHub Token
5.3.2. rhaap:create-execution-environment 复制链接链接已复制到粘贴板!
在 Ansible Automation Platform 中创建一个执行环境,用于定义用于运行 Ansible 作业的容器镜像。
输入参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
|
| string | 是 | 用于 Ansible Automation Platform 身份验证的 OAuth2 令牌。 |
|
| 布尔值 | 否 |
如果为 |
|
| object | 是 | 执行环境配置对象。 |
"values" 对象结构
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
|
| string | 是 | 执行环境的名称。 |
|
| string | 否 | 执行环境的描述。 |
|
| object | 是 |
带有所需 |
|
| string | 是 |
完整镜像位置,包括 registry、镜像名称和标签(如 |
|
| string | 否 |
镜像拉取策略: |
输出参数
| 参数 | 类型 | 描述 |
|---|---|---|
|
| object | 创建执行环境详情。 |
|
| number | 执行环境 ID。 |
|
| string | 执行环境名称。 |
|
| string | 执行环境描述。 |
|
| string | 执行环境的 Ansible Automation Platform (AAP) URL。 |
示例
steps:
- id: create-ee
name: Create Execution Environment
action: rhaap:create-execution-environment
input:
token: ${{ parameters.AAP_TOKEN }}
deleteIfExist: false
values:
environmentName: Custom EE
environmentDescription: Execution environment with custom collections
organization: ${{ parameters.organization }}
image: quay.io/ansible/creator-ee:v0.16.0
pull: missing
5.3.3. rhaap:create-job-template 复制链接链接已复制到粘贴板!
在 Ansible Automation Platform 中创建作业模板,以定义用于运行 Ansible playbook 的可重复使用的配置。
输入参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
|
| string | 是 | 用于 Ansible Automation Platform 身份验证的 OAuth2 令牌。 |
|
| 布尔值 | 否 |
如果为 |
|
| object | 是 | 作业模板配置对象。 |
"values" 对象结构
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
|
| string | 是 | 作业模板的名称。 |
|
| string | 否 | 作业模板的描述。 |
|
| object | 是 |
带有所需 |
|
| object | 否 |
带有 |
|
| object | 是 |
带有所需 |
|
| string | 是 | 要执行的 playbook 文件的路径。 |
|
| string | 否 | 作业模板的描述。 |
|
| string | 否 |
源控制类型(如 |
|
| object | 否 |
带有所需 |
|
| object | 否 | 传递给 playbook (键-值对)的额外变量。 |
输出参数
| 参数 | 类型 | 描述 |
|---|---|---|
|
| object | 创建作业模板详情。 |
|
| number | 作业模板 ID。 |
|
| string | 作业模板名称。 |
|
| string | 作业模板描述。 |
|
| string | 作业模板的 Ansible Automation Platform (AAP) URL。 |
示例
steps:
- id: create-job-template
name: Create Job Template
action: rhaap:create-job-template
input:
token: ${{ parameters.AAP_TOKEN }}
deleteIfExist: true
values:
templateName: Deploy Application
templateDescription: Deploys the application to production
project: ${{ steps['create-aap-project'].output.project }}
organization: ${{ parameters.organization }}
jobInventory: ${{ parameters.jobInventory }}
playbook: deploy.yml
executionEnvironment: ${{ steps['create-ee'].output.executionEnvironment }}
extraVariables:
app_version: 1.0.0
environment: production
5.3.4. rhaap:launch-job-template 复制链接链接已复制到粘贴板!
在 Ansible Automation Platform 中启动现有作业模板。
输入参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
|
| string | 是 | 用于 Ansible Automation Platform 身份验证的 OAuth2 令牌。 |
|
| object | 是 | 作业启动配置对象。 |
"values" 对象结构
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
|
| string | 是 | 要启动的作业模板名称。 |
|
| object | 否 |
使用 |
|
| 数组 | 否 | 要使用的凭证对象数组。 |
|
| object | 否 | 传递给作业(键-值对)的额外变量。 |
|
| string | 否 | 用于限制作业运行的主机的主机模式。 |
|
| string | 否 |
作业类型: |
|
| object | 否 |
使用 |
|
| object | 否 |
带有 |
|
| number | 否 |
并行进程数量(默认为 |
|
| number | 否 | 将作业划分为 N 分片。 |
|
| number | 否 |
作业超时(以秒为单位)( |
|
| 布尔值 | 否 | 启用 diff 模式以显示更改。 |
|
| string | 否 | 以逗号分隔的标签,仅运行特定的任务。 |
|
| string | 否 | 以逗号分隔的标签,用于跳过特定的任务。 |
输出参数
| 参数 | 类型 | 描述 |
|---|---|---|
|
| object | 作业执行详细信息. |
|
| number | 作业 ID。 |
|
| string | 作业状态. |
|
| string | 作业的 Ansible Automation Platform (AAP) URL。 |
示例
steps:
- id: launch-job
name: Launch Job Template
action: rhaap:launch-job-template
input:
token: ${{ parameters.AAP_TOKEN }}
values:
template: Deploy Application
inventory: ${{ parameters.jobInventory }}
credentials: ${{ parameters.credentials }}
extraVariables:
app_version: v1.0.1
deploy_env: production
jobType: run
verbosity: Normal
diffMode: true
timeout: 3600
5.3.5. 具有所有 backstage 操作的示例 复制链接链接已复制到粘贴板!
以下示例演示了如何一起使用多个操作。
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
name: ansible-complete-setup
title: Complete Ansible Setup
description: Creates an Ansible project, execution environment, job template, and launches it
spec:
owner: platform-team
type: service
parameters:
- title: Project Information
required:
- projectName
- repoUrl
properties:
projectName:
title: Project Name
type: string
description: Name of the Ansible project
repoUrl:
title: Repository URL
type: string
description: Git repository URL containing Ansible content
- title: AAP Configuration
required:
- organization
- jobInventory
- credentials
properties:
organization:
title: Organization
type: string
description: AAP Organization name
default: 1-org
ui:field: hidden # To hide this field in the UI
jobInventory:
title: Inventory name
type: string
description: AAP Inventory name
resource: inventories
ui:field: AAPResourcePicker
default: my-inventory
credentials:
title: Credentials
description: Select SCM credential for Private repositories
resource: credentials
ui:field: AAPResourcePicker
default: my-machine-credential
steps:
# Step 1: Create AAP Project
- id: create-project
name: Create AAP Project
action: rhaap:create-project
input:
token: ${{ parameters.AAP_TOKEN }}
deleteIfExist: true
values:
projectName: ${{ parameters.projectName }}
organization: ${{ parameters.organization }}
scmUrl: ${{ parameters.repoUrl }}
scmBranch: main
scmUpdateOnLaunch: true
# Step 2: Create Execution Environment
- id: create-ee
name: Create Execution Environment
action: rhaap:create-execution-environment
input:
token: ${{ parameters.AAP_TOKEN }}
values:
environmentName: ${{ parameters.projectName }}-ee
organization: ${{ parameters.organization }}
image: quay.io/ansible/creator-ee:latest
pull: missing
# Step 3: Create Job Template
- id: create-template
name: Create Job Template
action: rhaap:create-job-template
input:
token: ${{ parameters.AAP_TOKEN }}
values:
templateName: ${{ parameters.projectName }}-deploy
templateDescription: Deployment job template
project: ${{ steps['create-project'].output.project }}
organization: ${{ parameters.organization }}
jobInventory: ${{ parameters.jobInventory }}
playbook: site.yml
executionEnvironment: ${{ steps['create-ee'].output.executionEnvironment }}
# Step 4: Launch the Job
- id: launch-job
name: Launch Job
action: rhaap:launch-job-template
input:
token: ${{ parameters.AAP_TOKEN }}
values:
template: ${{ parameters.projectName }}-deploy
inventory: ${{ parameters.jobInventory }}
credentials: ${{ parameters.credentials }}
jobType: run
extraVariables:
created_by: backstage
timestamp: ${{ '' | now }}
output:
links:
- title: AAP Project
url: ${{ steps['create-project'].output.project.url }}
- title: Job Template
url: ${{ steps['create-template'].output.template.url }}
- title: Job Execution
url: ${{ steps['launch-job'].output.data.url }}