community.general.ldap_attrs 模块 – 添加或删除多个 LDAP 属性值

注意

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

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

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

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

community.general 0.2.0 中的新增功能

概要

  • 添加或删除多个 LDAP 属性值。

要求

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

  • python-ldap

参数

参数

注释

attributes

字典 / 必需

要添加或删除的属性和值。

每个属性值可以是单值属性的字符串,也可以是多值属性的字符串列表。

如果您在 YAML 中为此选项指定值,请注意,您可以使用 YAML 块修饰符来提高长字符串值的可读性,如本模块的示例所示。

请注意,当使用 YAML/ansible-core 解释为其他类型的值时,例如 yesno(布尔值)或 2.10(浮点数),如果这些值是要作为字符串使用,请确保用引号引起来。否则,可能会将错误的值发送到 LDAP。

bind_dn

字符串

要绑定的 DN。如果省略此项,我们将尝试使用 EXTERNAL 机制进行 SASL 绑定作为默认值。

如果此项为空,我们将使用匿名绑定。

bind_pw

字符串

要与 bind_dn 一起使用的密码。

默认值: ""

ca_path

路径

在 community.general 6.5.0 中添加

设置包含 CA 证书的 PEM 文件的路径。

client_cert

路径

在 community.general 7.1.0 中添加

用于 SSL 客户端身份验证的 PEM 格式证书链文件。

如果定义了 client_key,则为必需。

client_key

路径

在 community.general 7.1.0 中添加

包含用于 SSL 客户端身份验证的私钥的 PEM 格式文件。

如果定义了 client_cert,则为必需。

dn

字符串 / 必需

要添加或删除的条目的 DN。

ordered

布尔值

如果为 true,则在当前任务中指定的所有属性中,使用 X-ORDERED 索引号前置列表值。这主要在使用 olcAccess 属性时有用,以便轻松管理 LDAP 访问控制列表。

选择

  • false ←(默认)

  • true

referrals_chasing

字符串

在 community.general 2.0.0 中添加

设置引荐跟踪行为。

anonymous 匿名跟踪引荐。这是默认行为。

disabled 禁用引荐跟踪。这将 OPT_REFERRALS 设置为关闭。

选择

  • "disabled"

  • "anonymous" ←(默认)

sasl_class

字符串

在 community.general 2.0.0 中添加

用于 SASL 身份验证的类。

选择

  • "external" ←(默认)

  • "gssapi"

server_uri

字符串

server_uri 参数可以是仅包含模式、主机和端口字段的 URI 的逗号分隔或空格分隔列表。

默认值允许底层 LDAP 客户端库在其默认位置查找 UNIX 域套接字。

请注意,当使用多个 URI 时,您无法确定客户端连接到哪个 URI。

对于包含额外字段的 URI,特别是使用逗号时,行为是未定义的。

默认值: "ldapi:///"

start_tls

布尔值

如果为 true,我们将使用 START_TLS LDAP 扩展。

选择

  • false ←(默认)

  • true

state

字符串

属性值的状态。如果为 present,则如果缺少所有给定的属性值,则会添加它们。如果为 absent,则如果存在所有给定的属性值,则会删除它们。如果为 exact,则属性值的集合将被强制为仅为提供的那些,而不会有其他值。如果 state=exact 并且属性值为空,则将删除此属性的所有值。

选择

  • "present" ← (默认)

  • "absent"

  • "exact"

validate_certs

布尔值

如果设置为 false,则不会验证 SSL 证书。

这仅应在使用自签名证书的站点上使用。

选择

  • false

  • true ← (默认)

xorder_discovery

字符串

在 community.general 6.4.0 中添加

设置如何处理 Xordered DN 的行为。

enable 将在 superior RDN 下执行 ONELEVEL 搜索以找到匹配的 DN。

disable 将始终使用未修改的 DN(由 dn 参数传递)。

auto 仅当第一个 RDN 不包含索引号 ({x}) 时才执行搜索。

选择

  • "enable"

  • "auto" ← (默认)

  • "disable"

属性

属性

支持

描述

check_mode

支持: 完全

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

diff_mode

支持: 完全

在 community.general 8.5.0 中添加

当处于 diff 模式时,将返回已更改(或可能需要在 check_mode 中更改)的详细信息。

备注

注意

  • 这仅处理现有条目上的属性。要添加或删除整个条目,请参阅 community.general.ldap_entry

  • 默认的身份验证设置将尝试使用 SASL EXTERNAL 绑定通过 UNIX 域套接字。例如,这与默认的 Ubuntu 安装配合使用效果很好,其中包括允许 root 修改服务器配置的 cn=peercred,cn=external,cn=auth ACL 规则。如果您需要使用简单绑定来访问服务器,请在 bind_dnbind_pw 中传递凭据。

  • 对于 state=presentstate=absent,所有值比较都在服务器上执行,以获得最大精度。对于 state=exact,必须在 Python 中比较值,这显然会忽略 LDAP 匹配规则。这在大多数情况下应该可以正常工作,但理论上可能会在目标值和实际值在语义上相同但在词汇上不同时看到虚假的更改。

示例

- name: Configure directory number 1 for example.com
  community.general.ldap_attrs:
    dn: olcDatabase={1}hdb,cn=config
    attributes:
        olcSuffix: dc=example,dc=com
    state: exact

# The complex argument format is required here to pass a list of ACL strings.
- name: Set up the ACL
  community.general.ldap_attrs:
    dn: olcDatabase={1}hdb,cn=config
    attributes:
        olcAccess:
          - >-
            {0}to attrs=userPassword,shadowLastChange
            by self write
            by anonymous auth
            by dn="cn=admin,dc=example,dc=com" write
            by * none'
          - >-
            {1}to dn.base="dc=example,dc=com"
            by dn="cn=admin,dc=example,dc=com" write
            by * read
    state: exact

# An alternative approach with automatic X-ORDERED numbering
- name: Set up the ACL
  community.general.ldap_attrs:
    dn: olcDatabase={1}hdb,cn=config
    attributes:
        olcAccess:
          - >-
            to attrs=userPassword,shadowLastChange
            by self write
            by anonymous auth
            by dn="cn=admin,dc=example,dc=com" write
            by * none'
          - >-
            to dn.base="dc=example,dc=com"
            by dn="cn=admin,dc=example,dc=com" write
            by * read
    ordered: true
    state: exact

- name: Declare some indexes
  community.general.ldap_attrs:
    dn: olcDatabase={1}hdb,cn=config
    attributes:
        olcDbIndex:
            - objectClass eq
            - uid eq

- name: Set up a root user, which we can use later to bootstrap the directory
  community.general.ldap_attrs:
    dn: olcDatabase={1}hdb,cn=config
    attributes:
        olcRootDN: cn=root,dc=example,dc=com
        olcRootPW: "{SSHA}tabyipcHzhwESzRaGA7oQ/SDoBZQOGND"
    state: exact

- name: Remove an attribute with a specific value
  community.general.ldap_attrs:
    dn: uid=jdoe,ou=people,dc=example,dc=com
    attributes:
        description: "An example user account"
    state: absent
    server_uri: ldap://127.0.0.1/
    bind_dn: cn=admin,dc=example,dc=com
    bind_pw: password

- name: Remove specified attribute(s) from an entry
  community.general.ldap_attrs:
    dn: uid=jdoe,ou=people,dc=example,dc=com
    attributes:
        description: []
    state: exact
    server_uri: ldap://127.0.0.1/
    bind_dn: cn=admin,dc=example,dc=com
    bind_pw: password

返回值

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

描述

modlist

列表 / elements=字符串

修改的参数列表

返回: 成功

示例: [[2, "olcRootDN", ["cn=root,dc=example,dc=com"]]]

作者

  • Jiri Tyr (@jtyr)

  • Alexander Korinek (@noles)

  • Maciej Delmanowski (@drybjed)