community.general.redhat_subscription 模块 – 使用 subscription-manager 管理 RHSM 的注册和订阅

注意

此模块是 community.general 集合(版本 10.1.0)的一部分。

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

要安装它,请使用: ansible-galaxy collection install community.general。您需要进一步的要求才能使用此模块,请参阅 要求 了解详细信息。

要在 playbook 中使用它,请指定: community.general.redhat_subscription

概要

  • 使用 subscription-manager 命令管理红帽订阅管理授权平台的注册和订阅,并在可能的情况下使用 D-Bus 进行注册。

要求

在执行此模块的主机上需要以下要求。

  • subscription-manager

  • 可选的 dbus Python 库;它通常包含在操作系统中,因为它被 subscription-manager 使用。

参数

参数

注释

activationkey

字符串

提供一个激活密钥以用于注册

auto_attach

布尔值

成功注册后,自动使用可用的订阅

请注意,别名 autosubscribe 已在 community.general 9.0.0 中删除。

选项

  • false

  • true

consumer_id

字符串

引用现有的消费者 ID,以恢复使用此系统的先前注册。如果系统的身份证书丢失或损坏,此选项允许它恢复使用其先前的身份和订阅。默认情况下不指定消费者 ID,因此会创建一个新的 ID。

consumer_name

字符串

要注册的系统名称,默认为主机名

consumer_type

字符串

要注册的单元类型,默认为系统

environment

字符串

在目标组织中注册到特定环境。与 Red Hat Satellite 或 Katello 一起使用

force_register

布尔值

即使系统已注册,也注册该系统

选项

  • false ←(默认)

  • true

org_id

字符串

与 activationkey 结合使用的组织 ID

password

字符串

access.redhat.com 或 Red Hat Satellite 或 Katello 密码

pool_ids

列表 / 元素=任意

指定要使用的订阅池 ID。池 ID 可以指定为 字符串 - 仅池 ID(例如 0123456789abcdef0123456789abcdef),或者指定为 字典,其中池 ID 作为键,数量作为值(例如 0123456789abcdef0123456789abcdef: 2。如果提供了数量,则用于从池中使用多个授权(池必须支持此操作)。

默认值: []

release

字符串

设置发布版本

rhsm_baseurl

字符串

指定 CDN baseurl

rhsm_repo_ca_cert

字符串

指定 CDN 的 CA 证书的备用位置

server_hostname

字符串

指定备用的 Red Hat 订阅管理或 Red Hat Satellite 或 Katello 服务器。

server_insecure

字符串

连接到 server_hostname 时,启用或禁用 https 服务器证书验证。

server_port

字符串

在 community.general 3.3.0 中添加

注册到 Red Hat 订阅管理或 Red Hat Satellite 或 Katello 服务器时指定端口。

server_prefix

字符串

在 community.general 3.3.0 中添加

注册到 Red Hat 订阅管理或 Red Hat Satellite 或 Katello 服务器时指定前缀。

server_proxy_hostname

字符串

指定 HTTP 代理主机名。

server_proxy_password

字符串

使用基本身份验证指定 HTTP 代理的密码

server_proxy_port

字符串

指定 HTTP 代理端口。

server_proxy_scheme

字符串

在 community.general 6.2.0 中添加

指定 HTTP 代理方案,例如 httphttps

server_proxy_user

字符串

使用基本身份验证指定 HTTP 代理的用户

state

字符串

是否注册和订阅(present),或注销(absent)系统

选项

  • "present" ←(默认)

  • "absent"

syspurpose

字典

在文件 /etc/rhsm/syspurpose/syspurpose.json 中设置 syspurpose 属性,并将这些属性与 RHSM 服务器同步。Syspurpose 属性有助于自动将最合适的订阅附加到系统。当 syspurpose.json 文件已经包含一些属性时,新属性将覆盖现有属性。当某些属性未在新属性列表中列出时,现有属性将从 syspurpose.json 文件中删除。未知的属性将被忽略。

addons

列表 / 元素=字符串

Syspurpose 属性 addons

role

字符串

Syspurpose 属性 role

service_level_agreement

字符串

Syspurpose 属性 service_level_agreement

sync

布尔值

当此选项为 true 时,syspurpose 属性会立即与 RHSM 服务器同步。当此选项为 false 时,syspurpose 属性将通过 rhsmcertd 守护进程与 RHSM 服务器同步。

选项

  • false ←(默认)

  • true

用法

字符串

Syspurpose 属性用法

令牌

字符串

在 community.general 6.3.0 中添加

sso.redhat.com API 访问令牌。

用户名

字符串

access.redhat.com 或 Red Hat Satellite 或 Katello 用户名

属性

属性

支持

描述

check_mode

支持:

可以在 check_mode 中运行并返回更改状态预测,而无需修改目标。

diff_mode

支持:

在 diff 模式下,将返回有关已更改的内容(或可能需要在 check_mode 中更改的内容)的详细信息。

说明

注意

  • 该模块尝试使用 D-Bus rhsm 服务(subscription-manager 的一部分)进行注册,从 community.general 6.5.0 开始:这样做是为了可以安全地将凭据(用户名、密码、激活密钥)传递给 rhsmsubscription-manager 本身仅将凭据作为命令行参数的参数获取,这安全,因为可以通过检查系统上的进程列表轻松窃取它们。由于 rhsm 的 D-Bus 接口的限制,当尝试使用 token 进行注册,或者在指定 environment 时,或者当系统较旧时(通常是 RHEL 7 早于 7.4、RHEL 6 以及更旧版本),该模块将使用 D-Bus 进行注册。

  • 为了注册系统,subscription-manager 需要用户名和密码,或者激活密钥和组织 ID。

  • 从 2.5 开始,server_hostnameserver_insecurerhsm_baseurlserver_proxy_hostnameserver_proxy_portserver_proxy_userserver_proxy_password 的值不再从 /etc/rhsm/rhsm.conf 配置文件中获取,默认值为 null

  • 只能以 root 身份与 subscription-manager 交互,因此需要 root 权限才能成功运行此模块。

  • 从 community.general 6.5.0 开始,只有在系统未注册或指定 force_register 时,才需要凭据(即 usernamepasswordactivationkeytoken)。这样就可以使用该模块来调整已注册的系统,例如将其附加到池(使用 pool_ids),以及修改 syspurpose 属性(使用 syspurpose)。

示例

- name: Register as user (joe_user) with password (somepass) and auto-subscribe to available content.
  community.general.redhat_subscription:
    state: present
    username: joe_user
    password: somepass
    auto_attach: true

- name: Same as above but subscribe to a specific pool by ID.
  community.general.redhat_subscription:
    state: present
    username: joe_user
    password: somepass
    pool_ids: 0123456789abcdef0123456789abcdef

- name: Register and subscribe to multiple pools.
  community.general.redhat_subscription:
    state: present
    username: joe_user
    password: somepass
    pool_ids:
      - 0123456789abcdef0123456789abcdef
      - 1123456789abcdef0123456789abcdef

- name: Same as above but consume multiple entitlements.
  community.general.redhat_subscription:
    state: present
    username: joe_user
    password: somepass
    pool_ids:
      - 0123456789abcdef0123456789abcdef: 2
      - 1123456789abcdef0123456789abcdef: 4

- name: Register and pull existing system data.
  community.general.redhat_subscription:
    state: present
    username: joe_user
    password: somepass
    consumer_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

- name: Register as user credentials into given environment (against Red Hat Satellite or Katello), and auto-subscribe.
  community.general.redhat_subscription:
    state: present
    username: joe_user
    password: somepass
    environment: Library
    auto_attach: true

- name: Register as user (joe_user) with password (somepass) and a specific release
  community.general.redhat_subscription:
    state: present
    username: joe_user
    password: somepass
    release: 7.4

- name: Register as user (joe_user) with password (somepass), set syspurpose attributes and synchronize them with server
  community.general.redhat_subscription:
    state: present
    username: joe_user
    password: somepass
    auto_attach: true
    syspurpose:
      usage: "Production"
      role: "Red Hat Enterprise Server"
      service_level_agreement: "Premium"
      addons:
        - addon1
        - addon2
      sync: true

返回值

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

描述

subscribed_pool_ids

字典

系统现在订阅的池 ID 列表

返回: 成功

示例: {"8a85f9815ab905d3015ab928c7005de4": "1"}

作者

  • Barnaby Court (@barnabycourt)