community.general.ldap_entry 模块 – 添加或删除 LDAP 条目

注意

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

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

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

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

概要

  • 添加或删除 LDAP 条目。此模块仅声明 LDAP 条目的存在或不存在,而不是其属性。要声明条目的属性值,请参阅 community.general.ldap_attrs

需求

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

  • python-ldap

参数

参数

注释

attributes

字典

如果 state=present,则创建条目所需的属性。现有条目永远不会被修改。要声明现有条目上的特定属性值,请改用 community.general.ldap_attrs 模块。

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

如果您在 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。

objectClass

列表 / 元素=字符串

如果 state=present,则创建条目时要使用的值或值列表。它可以是字符串或实际的字符串列表。

recursive

布尔值

在 community.general 4.6.0 中添加

如果 state=delete,则表示是否必须删除单个条目或整个分支。

选项

  • 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"

validate_certs

布尔值

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

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

选项

  • false

  • true ← (默认)

xorder_discovery

字符串

在 community.general 6.4.0 中添加

设置处理 Xordered DN 的行为。

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

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

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

选项

  • "enable"

  • "auto" ← (默认)

  • "disable"

属性

属性

支持

描述

check_mode

支持:完全支持

可以在 check_mode 中运行,并在不修改目标的情况下返回更改状态预测。

diff_mode

支持:不支持

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

备注

注意

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

示例

- name: Make sure we have a parent entry for users
  community.general.ldap_entry:
    dn: ou=users,dc=example,dc=com
    objectClass: organizationalUnit

- name: Make sure we have an admin user
  community.general.ldap_entry:
    dn: cn=admin,dc=example,dc=com
    objectClass:
      - simpleSecurityObject
      - organizationalRole
    attributes:
      description: An LDAP administrator
      userPassword: "{SSHA}tabyipcHzhwESzRaGA7oQ/SDoBZQOGND"

- name: Set possible values for attributes elements
  community.general.ldap_entry:
    dn: cn=admin,dc=example,dc=com
    objectClass:
      - simpleSecurityObject
      - organizationalRole
    attributes:
      description: An LDAP Administrator
      roleOccupant:
      - cn=Chocs Puddington,ou=Information Technology,dc=example,dc=com
      - cn=Alice Stronginthebrain,ou=Information Technology,dc=example,dc=com
      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

- name: Get rid of an old entry
  community.general.ldap_entry:
    dn: ou=stuff,dc=example,dc=com
    state: absent
    server_uri: ldap://127.0.0.1/
    bind_dn: cn=admin,dc=example,dc=com
    bind_pw: password

#
# The same as in the previous example but with the authentication details
# stored in the ldap_auth variable:
#
# ldap_auth:
#   server_uri: ldap://127.0.0.1/
#   bind_dn: cn=admin,dc=example,dc=com
#   bind_pw: password
#
# In the example below, 'args' is a task keyword, passed at the same level as the module
- name: Get rid of an old entry
  community.general.ldap_entry:
    dn: ou=stuff,dc=example,dc=com
    state: absent
  args: "{{ ldap_auth }}"

作者

  • Jiri Tyr (@jtyr)