将 Automation Services Catalog 与您的 IT 服务管理(ITSM)系统集成

Red Hat Ansible Automation Platform 2.1

使用由订购过程和可替换的变量定义的工作流将 Automation Services Catalog 整合到您的 IT Service Management 系统工具链中。

Red Hat Customer Content Services

摘要

本指南描述了如何使用订购过程程和可替换变量把 Ansible Automation Platfrom 的作业模板中的数据传递给 IT Service Management(ITM)系统的工作流。

前言

您可以使用 Automation Services Catalog 的订购过程功能与 ITSM(ITSM)系统(如 ServiceNow)集成。

使开源包含更多

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。我们从这四个术语开始:master、slave、黑名单和白名单。由于此项工作十分艰巨,这些更改将在即将推出的几个发行版本中逐步实施。有关更多详情,请参阅我们的首席技术官 Chris Wright 提供的消息

第 1 章 规划您的 ITSM 与 Automation Services Catalog 集成

计划 Ansible Automation Platform 和 playbook 清单所需的更新和修改,以便与您的 ITSM 系统集成。有些更改需要在 Ansible Tower 和 Automation Services Catalog 中具有特定级别的管理权限。

本节将详细介绍执行更新所需的具体角色以及您需要修改的工件。

所需权限

您需要以下角色来完成集成工作流:

  • 您可以编写或更新用于 ITSM 集成的 playbook。
  • 您是一个 Ansible Tower 管理员,可以创建作业模板并添加问卷调查。
  • 您是一个目录管理员,可以创建产品组合、编辑问卷调查和设置订购过程。

Playbook

编写或更新作业模板和工作流中使用的 playbook,用于与 Automation Services Catalog 集成。

Ansible Tower 作业和工作流模板调查

更新附加到 playbook 之前和之后运行的作业模板中的调查,以支持可替换值。

Automation Services Catalog

更新调查设置为您的 ITSM 集成工作流中的产品,以启用替换。

第 2 章 更新 playbook 的 set_stats 字段来支持与 Automation Services Catalog 集成

您可以更新 playbook,将信息传递给 Automation Services Catalog,并在您的订购进程工作流中的产品中支持可替换变量。

2.1. 编写为 Automation Services Catalog 返回值的 playbook

您可以编写 playbook,以将值返回到 Automation Services Catalog。带有 expose_to_cloud_redhat_com_ 前缀的 set_stats 参数会将值返回到 Automation Services Catalog。然后,您可以使用可替换变量通过额外的 playbook 传递这些值。

使用以下的 playbook 示例来了解有关 set_stats 值的信息,并将值返回到 Automation Services Catalog,并在您的订购进程的后续 playbook 中使用它们作为可替换的值。

before order playbook 示例

这个 before order playbook 返回给 Automation Services Catalog set_stats 值用于热门颜色:

# This playbook prints a simple debug message and set_stats
- name: Echo Hello, world!
  hosts: localhost
  gather_facts: yes
  tasks:
    - debug:
        msg: "Hello, world!"

    - set_stats:
        data:
          expose_to_cloud_redhat_com_favorite_color: "orange"

product order playbook 示例

该 playbook 将可替换值传递给 Automation Services Catalog 作为工件值。

# This playbook prints a simple debug message with given information
- name: Echo Hello, world!
  hosts: localhost
  gather_facts: yes
  tasks:
    - debug:
        msg: "Hello, {{favorite_color}} world!"

    - set_stats:
        data:
          expose_to_cloud_redhat_com_after_data: "{{favorite_color}}"

after order playbook 示例

以下的 after order playbook 包含了由 product playbook 传递的工件 after_data 值。

# This playbook prints a simple debug message with given information
- name: Echo Hello, world!
  hosts: localhost
  gather_facts: yes
  tasks:
    - debug:
        msg: "{{after_data}}"
~

第 3 章 使用订购过程定义 ITSM 集成中的顺序操作

订购过程是主要的 Automation Services Catalog 功能,您可通过它将用户订购的产品与您的 ITSM 系统集成。订购过程由 Automation Services Catalog 中的产品组成,旨在执行作业模板,作业模板在您的 ITSM 系统中执行操作。这些过程由 Before order 和 After order 操作组成。您可以将您的订购进程定义为设计在用于订购产品之前和之后运行,以便信息可以在一系列的订购中进行传递。

序列示例

  • before order - 在 ITSM 系统中创建 ticket 的一个产品。
  • product order - 一个 web 服务器
  • after order - 关闭 ITSM 系统中的 ticket 的一个产品。

您可以通过创建一个适用于您的产品或产品组合级别的订购流程来定义序列以及运行哪些产品。

在本示例工作流中,我们需要创建一个订购过程,并将其附加到 before orderproduct orderafter order

3.1. 创建订购过程

作为目录管理员,创建订购进程可以允许您在订购产品前和订购产品后执行您的 Ansible Tower playbook。

先决条件

  • 要创建使用 Ansible Tower playbook 的订购过程,您必须有一个 Ansible Tower 集群作为源。

流程

  1. 从主导航中选择 Order Processes
  2. 点 btn:[Create]。
  3. 提供一个订购名称和描述。
  4. 在下拉菜单中,选择在订购前和订购后要发生的操作。

    注意

    下拉菜单将显示从 Ansible Tower 源中拉取的 playbook。每个订购进程只支持一个 Before 和 After 操作。

  5. 检查新的 Order Process 详情,然后点 btn:[Create]。

3.2. 为产品设置一个订购过程

设置应用于单个产品的订购进程。

流程

  1. 从主导航中选择 Products,然后选择一个产品。
  2. 点 btn:[More actions] 并选择 Set order process
  3. 展开下拉菜单并选择一个订购过程。

    注意

    Ansible Automation Platform 目前只支持每个产品置备中有一个订购过程。

  4. 点 btn:[Save]。

第 4 章 在订购工作流中启用可替换变量

您可以在您的订购过程工作流中使用的产品中替换变量。实现可替换变量需要创建或编辑 Ansible Tower 上的作业模板问卷调查,并启用对附加到 Automation Services Catalog 中的产品的调查的替换功能。

替换格式和要求

可替换值需要以 {{sub replaceion_express}} 格式表示,在大括号和表达式之间不能有空格。相关的详情,请参阅每个参数的替换变量的信息。

4.1. 在订购过程工作流中实现可替换变量

在本小节中,我们将演示如何使用本指南前面提供的 playbook 示例,在 playbook 中通过可替换变量使用在 Automation Services Catalog 中使用的数据。

4.1.1. 创建一个 before order 进程把一个值传递给产品订购。

用于 before order 进程的 before_order.yml playbook 示例

# This playbook prints a simple debug message and set_stats
- name: Echo Hello, world!
  hosts: localhost
  gather_facts: yes
  tasks:
    - debug:
        msg: "Hello, world!"

    - set_stats:
        data:
          expose_to_cloud_redhat_com_favorite_color: "orange"

此 playbook 为 Automation Services Catalog 返回一个 playbook 工件 favorite_color,它的值为 orange。因为不需要用户输入,所以不需要在 Ansible Tower 上进行作业模板问卷调查。您可以通过编辑 Automation Services Catalog 中的问卷调查,设置 before order 进程产品,将 favorite_color 传递给产品 playbook。

4.1.2. 配置 product order 来使用一个替换的变量

这个 product playbook 示例接受一个 {{favorite_color}} 可替代变量,并返回 Automation Services Catalog 工件 'after_data'。

playbook product_order.yml 示例

# This playbook prints a simple debug message with given information
- name: Echo Hello, world!
  hosts: localhost
  gather_facts: yes
  tasks:
    - debug:
        msg: "Hello, {{favorite_color}} world!"

    - set_stats:
        data:
          expose_to_cloud_redhat_com_after_data: "{{favorite_color}}"

在 Ansible Tower 上为 'product_order.yml' playbook 创建一个作业模板,将 favorite_color 设置为 *Answer Variable Name。

product_order.yml 作业模板创建问卷调查,其中包含:

  1. Prompt 项中输入 What is your favorite color?
  2. Answer Variable Name 项中输入 favorite_color
  3. 点 btn:[UPDATE]。

在 Automation Services Catalog 中启用 product order 问卷调查,使用从 before_order.yml 传递的 'favorite_color' 值。

在附加到您的 product order 的问卷调查中:

  1. 使用以下值更新字段:

    1. Name: favorite_color
    2. Initial Value: {{before.before_order.artifacts.favorite_color}}
    3. Label:您最喜欢的颜色是什么?
    4. Placeholder: {{before.before_order.artifacts.favorite_color}}
  2. Disabled 开关切换到活跃位置。
  3. Substitution 开关切换为活跃位置。

现在,您已将 product order 配置为使用来自 before_order.yml playbook 的 favorite_color 工件作为可替代变量。

4.1.3. 配置 after order 产品来接受来自产品订购的 after_data 工件值

通过使用可替换变量,可以使用问卷调查将 'product_order.yml' 工件 after_data 传递给 after_order.yml

用于 after order 产品的 after_order.yml playbook 示例

# This playbook prints a simple debug message with given information
- name: Echo Hello, world!
  hosts: localhost
  gather_facts: yes
  tasks:
    - debug:
        msg: "{{after_data}}"

为 'after_order.yml' playbook 在 Ansible Tower 上创建一个作业模板,该 playbook 将 after_data 设置为 *Answer Variable Name。

在附加到 after_order.yml 作业模板的问卷调查中:

  1. Prompt 字段中输入"Enter your after data"。
  2. Answer Variable Name 项中输入 after_data
  3. 点 btn:[UPDATE]。

在 Automation Services Catalog 中启用 after order 问卷调查,使用来自 after_order.yml 的 'after_data' 值。

在附加到您的 after order 的问卷调查中:

  1. 使用以下值更新字段:

    1. Name: after_data
    2. Initial Value: {{product.artifacts.after_data}}
    3. Label:"Enter your after data"
    4. Placeholder: {{product.artifacts.after_data}}
  2. Disabled 开关切换到活跃位置。
  3. Substitution 开关切换为活跃位置。

在运行作业模板时,playbook 将显示为 after data 传递的值。

4.2. 替换变量参考

替换格式为 {{substitution_express}}。在大括号和表达式之间不要有空格。

替换的值在 Ansible Tower 任务模板调查中设置。根据您的配置,替换从一个产品订购传递到另一个产品的变量。

如需有关更新作业模板调查的更多信息,请参阅 Ansible Tower 用户指南文档中的 Surveys

在您的调查中包含可替换变量时请参阅下表。

表 4.1. 对象模型参考表

对象表达式备注

Order

order.order_id

order.created_at

order.ordered_by.name

order.ordered_by.email

order.approval.updated_at

order.approval.decision

order.approval.reason

order.created_at` 是订购开始时的日期和时间。

日期格式:2007-02-10T20:30:45Z

示例:{{order.approval.reason}}

Before order

before.<order_process_name>.artifacts.<fact_name>

before.<order_process_name>.parameters.<parameter_name>

before.<order_process_name>.status

如果 order_process_name 包含空格,则不需要引号。

示例:{{before.Sample Order.artifacts.ticket_number}}

Product

product.name

product.description

product.long_description

product.help_url

product.support_url

product.vendor

product.platform

product.portfolio.name

product.portfolio.description

product.artifacts.<fact_name>

product.parameters.<parameter_name>

product.status

示例:{{product.artifacts.after_data}}

After order

after.<order_process_name>.artifacts.<fact_name>

after.<order_process_name>.parameters.<parameter_name>

after.<order_process_name>.status

如果 order_process_name 包含空格,则不需要引号。

示例:{{after.SampleOrder.status}}

法律通告

Copyright © 2023 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.