awx.awx.token 模块 – 创建、更新或销毁自动化平台控制器令牌。

注意

此模块是 awx.awx 集合 (版本 24.6.1) 的一部分。

如果您正在使用 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用: ansible-galaxy collection install awx.awx

要在 playbook 中使用它,请指定: awx.awx.token

awx.awx 2.3.0 中的新增功能

摘要

  • 创建或销毁自动化平台控制器令牌。有关概述,请参阅 https://ansible.org.cn/tower

  • 此外,该模块还会设置一个 Ansible 事实,该事实可以作为参数 controller_oauthtoken 传递到其他控制器模块。有关用法,请参阅示例。

  • 由于令牌的敏感性,创建的令牌值只能通过 Ansible 事实获得一次。(有关详细信息,请参阅 RETURN)

  • 由于令牌的性质,此模块不是幂等的。使用相同参数的第二次调用将创建一个新令牌。

  • 如果您正在为模块创建临时令牌,则在完成使用后应删除该令牌。有关如何操作,请参阅示例。

别名:tower_token

参数

参数

注释

application

字符串

与该令牌关联的应用程序名称、ID 或命名 URL。

controller_config_file

别名:tower_config_file

路径

控制器配置文件的路径。

如果提供,则不会考虑其他配置文件位置。

controller_host

别名:tower_host

字符串

指向您的自动化平台控制器实例的 URL。

如果未设置值,将尝试使用环境变量 CONTROLLER_HOST,然后是配置文件

如果任何方式均未指定值,则将使用 127.0.0.1 的值

controller_oauthtoken

别名:tower_oauthtoken

任意

awx.awx 3.7.0 中新增

要使用的 OAuth 令牌。

此值可以采用两种格式之一。

一个字符串,即令牌本身。(例如:bqV5txm97wqJqtkxlMkhQz0pKhRMMX)

令牌模块返回的字典结构。

如果未设置值,将尝试使用环境变量 CONTROLLER_OAUTH_TOKEN,然后是配置文件

controller_password

别名:tower_password

字符串

控制器实例的密码。

如果未设置值,将尝试使用环境变量 CONTROLLER_PASSWORD,然后是配置文件

controller_username

别名:tower_username

字符串

控制器实例的用户名。

如果未设置值,将尝试使用环境变量 CONTROLLER_USERNAME,然后是配置文件

description

字符串

此访问令牌的可选描述。

existing_token

字典

在创建模式下由令牌生成的用于 state absent 的数据结构。

existing_token_id

字符串

一个令牌 ID(数字),可用于使用 state absent 删除任意令牌。

request_timeout

浮点数

指定 Ansible 应在向控制器主机请求时使用的超时时间。

默认为 10 秒,但这由共享的 module_utils 代码处理

scope

字符串

允许的范围,进一步限制用户的权限。必须是一个简单的空格分隔的字符串,其中包含允许的范围 ['read','write']。

选项

  • "read"

  • "write"

state

字符串

资源的所需状态。

选项

  • "present" ← (默认)

  • "absent"

validate_certs

别名:tower_verify_ssl

布尔值

是否允许与 AWX 建立不安全连接。

如果 no,则不会验证 SSL 证书。

这只能在使用自签名证书的个人控制站点上使用。

如果未设置值,将尝试使用环境变量 CONTROLLER_VERIFY_SSL,然后是配置文件

选项

  • false

  • true

备注

注意

  • 如果没有提供 *config_file*,我们将尝试使用 tower-cli 库默认值来查找您的主机信息。

  • config_file 文件应采用以下格式:host=主机名 username=用户名 password=密码

示例

- block:
    - name: Create a new token using an existing token
      token:
        description: '{{ token_description }}'
        scope: "write"
        state: present
        controller_oauthtoken: "{{ my_existing_token }}"

    - name: Delete this token
      token:
        existing_token: "{{ controller_token }}"
        state: absent

    - name: Create a new token using username/password
      token:
        description: '{{ token_description }}'
        scope: "write"
        state: present
        controller_username: "{{ my_username }}"
        controller_password: "{{ my_password }}"

    - name: Use our new token to make another call
      job_list:
        controller_oauthtoken: "{{ controller_token }}"

  always:
    - name: Delete our Token with the token we created
      token:
        existing_token: "{{ controller_token }}"
        state: absent
      when: token is defined

- name: Delete a token by its id
  token:
    existing_token_id: 4
    state: absent

返回值

常见的返回值已在 此处 记录,以下是此模块特有的字段:

描述

controller_token

字典

一个 Ansible Fact 变量,表示一个令牌对象,可用于后续模块中的身份验证。请参阅示例以了解用法。

返回:创建成功时

id

字符串

已创建令牌的数字 ID

返回:成功

token

字符串

生成的令牌。此令牌将无法再次访问,请确保在丢失之前记下此值。

返回:成功

作者

  • John Westcott IV (@john-westcott-iv)