11.5. 创建新凭证类型


要创建新凭证类型,请执行以下操作:

流程

  1. Credential Types 视图中,点 Add

    Create new credential type

  2. NameDescription 字段中输入相关详情。

    注意

    在创建新凭证类型时,请不要为 INPUT 和 INJECTOR 名称和 ID 使用以 ANSIBLE_ 开头的 保留变量名称,因为它们对于自定义凭证类型无效。

  3. Input Configuration 字段中,指定一个输入模式,为该类型定义一组排序字段。格式可以是 YAML 或 JSON:

    YAML

    fields:
      - type: string
        id: username
        label: Username
      - type: string
        id: password
        label: Password
        secret: true
    required:
      - username
      - password

    在 YAML 页面 查看更多 YAML 示例。

    JSON

    {
    "fields": [
      {
      "type": "string",
      "id": "username",
      "label": "Username"
      },
      {
      "secret": true,
      "type": "string",
      "id": "password",
      "label": "Password"
       }
      ],
     "required": ["username", "password"]
    }

    请参阅 JSON 网站 查看更多 JSON 示例。

    以下 JSON 格式的配置显示了每个字段以及它们的使用方式:

    {
      "fields": [{
        "id": "api_token",    # required - a unique name used to reference the field value
    
        "label": "API Token", # required - a unique label for the field
    
        "help_text": "User-facing short text describing the field.",
    
        "type": ("string" | "boolean")   # defaults to 'string'
    
        "choices": ["A", "B", "C"]   # (only applicable to `type=string`)
    
        "format": "ssh_private_key"  # optional, can be used to enforce data format validity
                                     for SSH private key data (only applicable to `type=string`)
    
        "secret": true,       # if true, the field value will be encrypted
    
        "multiline": false    # if true, the field should be rendered as multi-line for input entry
                              # (only applicable to `type=string`)
    },{
        # field 2...
    },{
        # field 3...
    }],
    
    "required": ["api_token"]   # optional; one or more fields can be marked as required
    },

    type=string 时,字段可以选择性地指定多个选择选项:

    {
      "fields": [{
          "id": "api_token",    # required - a unique name used to reference the field value
          "label": "API Token", # required - a unique label for the field
          "type": "string",
          "choices": ["A", "B", "C"]
      }]
    },
  4. Injector Configuration 字段中输入环境变量或额外变量,用于指定凭证类型可注入的值。格式可以是 YAML 或 JSON (请参阅上一步中的示例)。

    以下 JSON 格式的配置显示了每个字段以及它们的使用方式:

    {
      "file": {
          "template": "[mycloud]\ntoken={{ api_token }}"
      },
      "env": {
          "THIRD_PARTY_CLOUD_API_TOKEN": "{{ api_token }}"
      },
      "extra_vars": {
          "some_extra_var": "{{ username }}:{{ password }}"
      }
    }

    凭证类型也可以生成临时文件来支持 .ini 文件或证书或密钥数据:

    {
      "file": {
          "template": "[mycloud]\ntoken={{ api_token }}"
      },
      "env": {
          "MY_CLOUD_INI_FILE": "{{ tower.filename }}"
      }
    }

    在本例中,自动化控制器会编写一个具有以下内容的临时文件:

    [mycloud]\ntoken=SOME_TOKEN_VALUE

    生成的文件的绝对路径存储在名为 MY_CLOUD_INI_FILE 的环境变量中。

    以下是引用自定义凭证模板中的很多文件的示例:

    输入

    {
      "fields": [{
        "id": "cert",
        "label": "Certificate",
        "type": "string"
      },{
        "id": "key",
        "label": "Key",
        "type": "string"
      }]
    }

    injectors

    {
      "file": {
        "template.cert_file": "[mycert]\n{{ cert }}",
        "template.key_file": "[mykey]\n{{ key }}"
    },
    "env": {
        "MY_CERT_INI_FILE": "{{ tower.filename.cert_file }}",
        "MY_KEY_INI_FILE": "{{ tower.filename.key_file }}"
    }
    }
  5. 点击 Save

    您新创建的凭证类型显示在凭证类型列表中:

    New credential type

  6. 点 Edit Edit 图标修改凭证类型选项。

    注意

    Edit 屏幕中,您可以修改详情或删除凭证。如果 Delete 选项被禁用,这意味着凭证正在使用凭证类型,且您必须在删除它前从所有使用的凭证中删除凭证类型。

验证

  • 验证在创建新凭证时是否可从 Credential Type 选择窗口中选择新创建的凭证类型:

Verify new credential type

其他资源

有关如何创建新凭证的详情,请参考 创建凭证

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.