community.windows.win_domain_object_info 模块 – 收集 Active Directory 对象的信息

注意

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

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

要安装它,请使用: ansible-galaxy collection install community.windows

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

已弃用

在以下版本中删除:

版本 3.0.0

原因:

此模块已移至 microsoft.ad 集合中。

替代方案:

请改用 microsoft.ad.object_info 模块。

概要

  • 收集有关多个 Active Directory 对象的信息。

参数

参数

注释

domain_password

字符串

domain_username 的密码。

domain_server

字符串

指定要连接的 Active Directory 域服务实例。

可以是 FQDN 或 NetBIOS 名称的形式。

如果未指定,则该值基于运行 PowerShell 的计算机的默认域。

domain_username

字符串

与 AD 交互时要使用的用户名。

如果未设置此项,则用于身份验证的用户将是连接用户。

除非身份验证是 Kerberos 并且具有凭据委派或 CredSSP,否则 Ansible 将无法使用连接用户,或者在任务中使用 become。

filter

字符串

使用 PowerShell 表达式语言语法指定查询字符串。

这遵循与 PowerShell AD cmdlet 的 -Filter 参数相同的规则和格式,但没有变量替换。

这与 _identity_ 和 _ldap_filter_ 互斥。

identity

字符串

通过其专有名称或对象 GUID 指定单个 Active Directory 对象。

这与 _filter_ 和 _ldap_filter_ 互斥。

不能与 _search_base_ 或 _search_scope_ 选项一起使用。

include_deleted

布尔值

同时搜索已删除的 Active Directory 对象。

选项

  • false ← (默认)

  • true

ldap_filter

字符串

与 _filter_ 类似,但这是一个传统的 LDAP 查询字符串,用于筛选要返回的对象。

这与 _filter_ 和 _identity_ 互斥。

properties

列表 / elements=字符串

要返回的属性列表。

如果属性是 *,则将返回 AD 对象上具有设置值的所有属性。

如果属性在对象上有效但未设置,则仅当在此选项列表中显式定义时才会返回。

始终返回 DistinguishedNameNameObjectClassObjectGUID 属性。

指定多个属性可能会对性能产生影响,最好只返回所需的属性。

如果指定了无效属性,则模块将针对其无效的每个对象显示警告。

search_base

字符串

指定要搜索对象的 Active Directory 路径。

不能与 _identity_ 一起设置。

默认情况下,搜索库是目标 AD 实例的默认命名上下文,即 “(Get-ADRootDSE).defaultNamingContext” 返回的 DN。

search_scope

字符串

指定在 search_base 中搜索对象时的范围。

base 将搜索限制为基本对象,因此返回的最大对象数始终为 1。这不会搜索容器内的任何对象。

one_level 将搜索当前路径和该路径中的任何直接对象。

subtree 将递归搜索当前路径和该路径的所有对象。

不能与 _identity_ 一起设置。

选项

  • "base"

  • "one_level"

  • "subtree"

注释

注意

  • sAMAccountType_AnsibleFlagsuserAccountControl_AnsibleFlags 返回属性是模块本身设置的,目的是作为一种查看这些标志所代表内容的简便方法。这些属性不能用作 _filter_ 或 _ldap_filter_ 的一部分,并且如果在请求这些属性时会自动添加。

  • 必须在安装了 ActiveDirectory powershell 模块的主机上运行此命令。

示例

- name: Get all properties for the specified account using its DistinguishedName
  community.windows.win_domain_object_info:
    identity: CN=Username,CN=Users,DC=domain,DC=com
    properties: '*'

- name: Get the SID for all user accounts as a filter
  community.windows.win_domain_object_info:
    filter: ObjectClass -eq 'user' -and objectCategory -eq 'Person'
    properties:
      - objectSid

- name: Get the SID for all user accounts as a LDAP filter
  community.windows.win_domain_object_info:
    ldap_filter: (&(objectClass=user)(objectCategory=Person))
    properties:
      - objectSid

- name: Search all computer accounts in a specific path that were added after February 1st
  community.windows.win_domain_object_info:
    filter: objectClass -eq 'computer' -and whenCreated -gt '20200201000000.0Z'
    properties: '*'
    search_scope: one_level
    search_base: CN=Computers,DC=domain,DC=com

返回值

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

描述

objects

列表 / elements=字典

找到的 Active Directory 对象以及所请求的属性的字典列表。

字典的键是属性名称,值是属性的值。

所有日期属性均以 UTC 时区的 ISO 8601 格式返回。

所有 SID 属性都作为字典返回,其中键 Sid 作为 SID 字符串,键 Name 作为已转换的 SID 帐户名称。

所有字节属性都作为 base64 字符串返回。

所有安全描述符属性都作为该描述符的 SDDL 字符串返回。

始终返回 DistinguishedNameNameObjectClassObjectGUID 属性。

返回: 始终

示例: "[{\n  \"accountExpires\": 0,\n  \"adminCount\": 1,\n  \"CanonicalName\": \"domain.com/Users/Administrator\",\n  \"CN\": \"Administrator\",\n  \"Created\": \"2020-01-13T09:03:22.0000000Z\",\n  \"Description\": \"用于管理计算机/域的内置账户\",\n  \"DisplayName\": null,\n  \"DistinguishedName\": \"CN=Administrator,CN=Users,DC=domain,DC=com\",\n  \"memberOf\": [\n    \"CN=组策略创建者所有者,CN=Users,DC=domain,DC=com\",\n    \"CN=域管理员\",CN=Users,DC=domain,DC=com\"\n  ],\n  \"Name\": \"Administrator\",\n  \"nTSecurityDescriptor\": \"O:DAG:DAD:PAI(A;;LCRPLORC;;;AU)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;SY)(A;;CCDCLCSWRPWPLOCRSDRCWDWO;;;BA)\",\n  \"ObjectCategory\": \"CN=Person,CN=Schema,CN=Configuration,DC=domain,DC=com\",\n  \"ObjectClass\": \"user\",\n  \"ObjectGUID\": \"c8c6569e-4688-4f3c-8462-afc4ff60817b\",\n  \"objectSid\": {\n    \"Sid\": \"S-1-5-21-2959096244-3298113601-420842770-500\",\n    \"Name\": \"DOMAIN\\Administrator\"\n  },\n  \"sAMAccountName\": \"Administrator\",\n}]\n"

状态

  • 此模块将在 3.0.0 版本中移除。[已弃用]

  • 有关更多信息,请参阅 已弃用

作者

  • Jordan Borean (@jborean93)