microsoft.ad.ldap 库存 – Active Directory 的库存插件
注意
此库存插件是 microsoft.ad 集合(版本 1.7.1)的一部分。
如果您正在使用 ansible
包,您可能已经安装了这个集合。它不包含在 ansible-core
中。要检查是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install microsoft.ad
。您需要其他要求才能使用此库存插件,有关详细信息,请参阅要求。
要在 playbook 中使用它,请指定:microsoft.ad.ldap
。
microsoft.ad 1.1.0 中的新增功能
概要
Active Directory 或其他 LDAP 源的库存插件。
使用以
microsoft.ad.ldap.{yml|yaml}
结尾的 YAML 配置文件。添加的每个主机都将
inventory_hostname
设置为 LDAP 计算机对象的name
,并将ansible_host
设置为dNSHostName
LDAP 属性的值(如果已设置)。如果计算机对象上未设置dNSHostName
属性,则不会设置ansible_host
。有关如何设置这些值以及如何调整它们的更多信息,请参阅 LDAP 库存主机名。主机事实
microsoft_ad_distinguished_name
也将设置为用于派生主机条目的主机的专有名称。所需的任何其他事实都需要在 _attributes_ 选项中定义。
要求
以下要求需要在执行此库存的本地控制器节点上满足。
dnspython - 用于选项服务器查找支持
pyspnego >= 0.8.0
pyspnego[kerberos] - 用于 Kerberos 和服务器查找支持
sansldap
dpapi-ng - 用于 LAPS 解密支持
参数
参数 |
注释 |
---|---|
要检索的 LDAP 属性。 指定的键是请求的 LDAP 属性,每个属性的值是一个字典,反映要将其设置为主机变量的内容以及如何设置。 内部字典值的每个键是要设置的主机变量名,值是用于派生值的模板。如果未显式设置值,则将使用从 LDAP 属性返回的强制值。 在 LDAP 架构中表示为单值的属性将作为该单值返回,多值属性将作为值列表返回。 有关更多信息,请参阅 LDAP 库存属性。 默认值: |
|
连接到 LDAP 主机时使用的身份验证协议。 如果使用 LDAPS/StartTLS 并且已指定 _certificate_,则默认为
Kerberos 支持需要安装 有关更多信息,请参阅 LDAP 身份验证。 可以使用 Jinja2 模板值设置此选项。 选择
配置 |
|
可以是用于证书验证的 CA 证书 PEM 或 DER 文件、PEM 证书目录或 CA 证书 PEM 字符串的路径。 如果省略,则用于验证的默认 CA 存储取决于当前的 Python 设置。 可以使用 Jinja2 模板值设置此选项。 配置 |
|
使用 TLS 连接时的证书验证行为。 可以设置为
有关更多信息,请参阅 证书验证。 可以使用 Jinja2 模板值设置此选项。 选择
配置 |
|
用于证书身份验证的证书或包含密钥的证书捆绑包。 该值可以是包含证书的文件路径,也可以是 PEM 编码的证书字符串。 如果使用证书文件的路径,则该文件可以是 PEM 编码的证书、PEM 编码的证书和密钥捆绑包、DER 编码的证书或 PFX/PKCS12 编码的证书和密钥捆绑包。 如果指定的证书不包含密钥,请使用 *certificate_key*。 如果密钥使用密码加密,请使用 *certificate_password*。 可以使用 Jinja2 模板值设置此选项。 配置 |
|
用于证书身份验证的证书密钥。 该值可以是包含 PEM 或 DER 编码格式的密钥的文件路径,也可以是 PEM 编码的密钥字符串。 如果密钥使用密码加密,请使用 *certificate_password*。 可以使用 Jinja2 模板值设置此选项。 配置 |
|
用于解密由 *certificate* 或 *certificate_key* 指定的证书密钥的密码。 可以使用 Jinja2 模板值设置此选项。 配置 |
|
从 jinja2 表达式创建变量。 默认值: |
|
是否需要对连接进行加密。 可以使用身份验证协议或通过 TLS 执行加密。 *auth_protocol* 如果使用 可以使用 Jinja2 模板值设置此选项。 选择
配置 |
|
用于查询计算机对象的 LDAP 筛选器字符串。 默认情况下,这将与筛选器“(objectCategory=computer)”组合使用。使用 *filter_without_computer* 来覆盖此行为,并使 *filter* 成为唯一使用的筛选器。 |
|
不会将 *filter* 值与默认筛选器“(objectCategory=computer)”组合使用。 在大多数情况下,这应为 选择
|
|
根据 Jinja2 条件将主机添加到组。 默认值: |
|
根据变量的值将主机添加到组。 默认值: |
|
当主机变量的值为空字符串时的默认值。 此选项与 |
|
用于生成组的输入字典中的键。 |
|
键控组的父组。 |
|
键控组名称将以此前缀开头。 默认值: |
|
用于构建键控组名称的分隔符。 默认值: |
|
将此选项设置为 此选项与 选择
|
|
与 默认情况下,没有提供前缀或分隔符的键控组的名称将以一个下划线开头。 这是因为默认前缀为 如果未给出前缀,请将此选项设置为 如果组名是从映射派生的,则分隔符仍用于连接项。 要完全不在组名中使用分隔符,请将键控组的分隔符设置为空字符串。 选择
|
|
用于进行身份验证的密码。 如果 *auth_protocol* 为 如果 *auth_protocol* 为 可以使用 Jinja2 模板值设置此选项。 配置 |
|
用于连接的 LDAP 端口。 端口 389 用于 LDAP,端口 686 用于 LDAPS。 如果 可以使用 Jinja2 模板值设置此选项。 配置
|
|
用于查找计算机对象的 LDAP 搜索基本路径。 如果未指定,则默认为 Active Directory 服务器的 如果搜索较大的 Active Directory 数据库,建议缩小搜索基本路径以加快查询速度。 |
|
要执行的 LDAP 搜索的范围。
选择
|
|
要连接的域控制器/服务器。 如果未指定,则将从当前的 krb5.conf 有关更多信息,请参阅 服务器查找。 可以使用 Jinja2 模板值设置此选项。 配置
|
|
如果 由于可以在表达式中使用事实,因此它们可能并不总是可用,默认情况下我们会忽略这些错误。 选择
|
|
要使用的 TLS 操作。 如果将显式 *port* 设置为
如果将要使用 TLS,建议使用 可以使用 Jinja2 模板值设置此选项。 选择
配置 |
|
将额外的变量合并到可用于组合的变量中(优先级最高)。 选择
配置
|
|
用于身份验证的用户名。 如果 auth_protocol 为 如果 auth_protocol 为 可以使用 Jinja2 模板值设置此选项。 配置 |
备注
示例
# Set in the file ending with microsoft.ad.ldap.yml or microsoft.ad.ldap.yaml
plugin: microsoft.ad.ldap
####################################################################
# Connection Options #
# #
# These options control how the plugin connects to the LDAP server #
####################################################################
# Connects to ldap://dc01.domain.com:389
server: dc01.domain.com
port: 389
# Connects to ldaps://dc01.domain.com:636
server: dc01.domain.com
tls_mode: ldaps
# Connects to the global catalog
# ldap://dc01.domain.com:3268
server: dc01.domain.com
port: 3268
# Provides explicit user, will use the current Kerberos ticket if no credential
# is provided.
username: [email protected]
password: Password123!
# Only allow Kerberos authentication.
auth_protocol: kerberos
# Verify LDAPS CA chain with custom CA chain.
tls_mode: ldaps
ca_cert: /home/user/certs/ldap.pem
# The username and password can be retrieved using a template with a lookup.
# Other connection options can also be set this way, the option description
# tells you whether it can be set to a template.
username: '{{ lookup("ansible.builtin.env", "LDAP_USERNAME") }}'
password: '{{ lookup("ansible.builtin.env", "LDAP_PASSWORD") }}'
##############################################
# Search Options #
# #
# These options control the searching rules #
##############################################
# Search for computer accounts in the Workshop OU.
search_base: OU=Workshop A,DC=domain,DC=com
# Filter the computer accounts returned for only ones with the dNSDomainName
# attribute set.
filter: (dNSDomainName=*)
# Filter computer accounts returned for ones starting with PROD and with the
# LAPS password set.
filter: (&(sAMAccountName=PROD*)(ms-Mcs-AdmPwd=*))
# See documentation for more details
attributes:
sAMAccountName:
sam_account_name:
objectSid:
computer_sid:
pwdLastSet:
password_last_set: this | microsoft.ad.as_datetime
comment:
host_comment
memberOf:
# Gets the value (1) of the first RDN (0) of each memberOf instance (this).
# For example 'CN=Domain Admins,CN=Users,DC=domain,DC=test'
# will be returned as just 'Domain Admins'
computer_membership: this | microsoft.ad.parse_dn | map(attribute="0.1")
location:
############################################################################
# LAPS Integration #
# #
# Examples on how to use the new Windows LAPS values as connection options #
############################################################################
attributes:
# msLAPS-Password is used if no encryption has been configured.
# Currently an encrypted LAPS password is not supported.
msLAPS-Password:
ansible_user: (this | from_json).n
ansible_password: (this | from_json).p
# msLAPS-EncryptedPassword is used if encryption has been configured.
# If the Python dpapi-ng library is installed the `this`` value will
# contain the entry `value` which is the decrypted value. The ``info``
# entry will contain the reason why the value could not be decrypted.
msLAPS-EncryptedPassword:
ansible_user: (this.value | from_json).n
ansible_password: (this.value | from_json).p
# ms-Mcs-AdmPwd is used for Legacy LAPS and stores just the password.
# The username needs to be hardcoded as a string value for this template.
ms-Mcs-AdmPwd:
ansible_user: '"Administrator"'
ansible_password: this
#####################################################################
# Constructed Options #
# #
# These options control the constructed values like vars and groups #
#####################################################################
# Build composed host variables. Requires attributes to be set in the
# attributes option to be referenced here.
compose:
host_var: computer_sid
# Conditionals that adds found hosts to the groups specified.
groups:
# Adds all hosts to the windows group
windows: true
# Uses the memberOf fact documented above to place the host in the production
# group if it's a member of that group
production: '"Production Group" in computer_membership'
# Adds the host to a group site_{{ location }} with the default group of
# site_unknown if the location isn't defined
keyed_groups:
- key: location | default(omit)
prefix: site
default_value: unknown