community.windows.laps_password 查询 – 获取服务器的 LAPS 密码。

注意

此查询插件是 community.windows 集合 (版本 2.3.0) 的一部分。

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

要安装它,请使用:ansible-galaxy collection install community.windows。您需要其他要求才能使用此查询插件,请参阅 要求 获取详细信息。

要在 playbook 中使用它,请指定:community.windows.laps_password

概要

要求

以下要求是在执行此查询的本地控制器节点上需要的。

  • python-ldap

术语

参数

注释

术语

字符串 / 必需

要为其检索 LAPS 密码的主机名。

这是主机的 通用名称 (CN)

关键字参数

这描述了查询的关键字参数。这些是在以下示例中的值 key1=value1key2=value2 等:lookup('community.windows.laps_password', key1=value1, key2=value2, ...)query('community.windows.laps_password', key1=value1, key2=value2, ...)

参数

注释

allow_plaintext

布尔值

设置为 yes 时,允许发送未加密的流量。

强烈建议不要修改此设置,以避免任何凭据在网络流量中暴露。

使用 scheme=ldapsauth=gssapistart_tls=yes 来确保流量加密。

选项

  • false ← (默认)

  • true

auth

字符串

连接到 Active Directory 服务器时要使用的身份验证类型

使用 simple 时,必须设置 *用户名* 和 *密码* 选项。如果不使用 scheme=ldapsstart_tls=True,则这些凭据将在网络流量中以明文形式暴露。

建议使用 gssapi,因为它会自动加密流量。

使用 gssapi 时,在运行 Ansible 之前运行 kinit 以获取有效的 Kerberos 票证。

当设置 scheme=ldapsstart_tls=True 时,无法使用 gssapi

选项

  • "simple"

  • "gssapi" ← (默认)

ca_cert

别名:cacert_file

字符串

要用于证书验证的 CA 证书 PEM 文件的路径。

scheme=ldapsstart_tls=yes 时使用证书验证。

这可能会在具有较旧 OpenLDAP 安装(如 MacOS)的主机上失败,这将必须在重新安装 python-ldap 之前更新才能再次工作。

domain

字符串 / 必需

要从中检索 LAPS 密码的域。

这可以是 Ansible 控制器从 DNS 中看到的 Windows 域名,也可以是特定的域控制器 FQDN。

支持仅域名/主机名或已填充域名/主机的显式 LDAP URI。

如果设置了 URI,则忽略 *端口* 和 *方案*。

password

字符串

username 的密码。

当设置 username 时必需。

port

整数

要通过其通信的 LDAP 端口。

如果kdc已经是LDAP URI,则忽略此设置。

scheme

字符串

要使用的LDAP方案。

使用ldap时,建议设置auth=gssapistart_tls=yes,否则流量将以明文传输。

必须先为Active Directory主机配置具有证书的ldaps,然后才能使用它。

如果kdc已经是LDAP URI,则忽略此设置。

选项

  • "ldap" ← (默认)

  • "ldaps"

search_base

字符串

更改在Active Directory中搜索主机时使用的搜索基础。

默认为在Active Directory服务器的defaultNamingContext中搜索。

如果找到多个匹配项,则需要更明确的search_base,以便只找到1个主机。

如果搜索较大的Active Directory数据库,建议出于性能原因缩小search_base。

start_tls

布尔值

scheme=ldap时,将使用StartTLS扩展加密通过网络发送的流量。

这需要Active Directory使用支持StartTLS的证书进行设置。

scheme=ldaps时,此设置将被忽略,因为流量已加密。

选项

  • false ← (默认)

  • true

username

字符串

使用auth=simple时必需。

用于身份验证的用户名。

建议使用UPN格式的用户名,例如[email protected]

auth=simple时,这是必需的;当auth=gssapi时,不支持此设置。

如果需要auth=gssapi,请在Ansible外部调用kinit

validate_certs

字符串

使用scheme=ldapsstart_tls=yes时,这将控制证书验证行为。

demand如果未提供证书或提供的证书无效,则将失败。

try对于无效证书将失败,但如果未提供证书,则将继续。

allow将请求并检查证书,但即使证书无效,也将继续。

never不会向服务器请求证书,因此不会进行验证。

选项

  • "never"

  • "allow"

  • "try"

  • "demand" ← (默认)

备注

注意

  • 当关键字参数和位置参数一起使用时,位置参数必须列在关键字参数之前:lookup('community.windows.laps_password', term1, term2, key1=value1, key2=value2)query('community.windows.laps_password', term1, term2, key1=value1, key2=value2)

  • 如果找到主机但没有LAPS密码属性ms-Mcs-AdmPwd,则查找将失败。

  • 由于通过网络传输的数据的敏感性,强烈建议使用auth=gssapischeme=ldapsstart_tls=yes运行。

  • 未能使用上述设置之一将导致帐户凭据以及LAPS密码以明文形式发送。

  • 在具有较旧OpenLDAP安装(如MacOS)的主机上运行时,某些场景可能无法正常工作。建议安装最新版本的OpenLDAP并针对其构建python-ldap,有关更多信息,请参见https://keathmilligan.net/python-ldap-and-macos

示例

# This isn't mandatory but it is a way to call kinit from within Ansible before calling the lookup
- name: call kinit to retrieve Kerberos token
  expect:
    command: kinit [email protected]
    responses:
      (?i)password: SecretPass1
  no_log: true

- name: Get the LAPS password using Kerberos auth, relies on kinit already being called
  set_fact:
    ansible_password: "{{ lookup('community.windows.laps_password', 'SERVER', domain='dc01.ansible.com') }}"

- name: Specific the domain host using an explicit LDAP URI
  set_fact:
    ansible_password: "{{ lookup('community.windows.laps_password', 'SERVER', domain='ldap://ansible.org.cn:389') }}"

- name: Use Simple auth over LDAPS
  set_fact:
    ansible_password: "{{ lookup('community.windows.laps_password', 'server',
                                 domain='dc01.ansible.com',
                                 auth='simple',
                                 scheme='ldaps',
                                 username='[email protected]',
                                 password='SuperSecret123') }}"

- name: Use Simple auth with LDAP and StartTLS
  set_fact:
    ansible_password: "{{ lookup('community.windows.laps_password', 'app01',
                                 domain='dc01.ansible.com',
                                 auth='simple',
                                 start_tls=True,
                                 username='[email protected]',
                                 password='SuperSecret123') }}"

- name: Narrow down the search base to a an OU
  set_fact:
    ansible_password: "{{ lookup('community.windows.laps_password', 'sql10',
                                 domain='dc01.ansible.com',
                                 search_base='OU=Databases,DC=ansible,DC=com') }}"

- name: Set certificate file to use when validating the TLS certificate
  set_fact:
    ansible_password: "{{ lookup('community.windows.laps_password', 'windows-pc',
                                 domain='dc01.ansible.com',
                                 start_tls=True,
                                 ca_cert='/usr/local/share/certs/ad.pem') }}"

返回值

描述

返回值

字符串

请求的主机的LAPS密码。

返回:成功

作者

  • Jordan Borean (@jborean93)

提示

每个条目类型的配置项具有从低到高的优先级顺序。例如,列表中较低的变量将覆盖较高的变量。