Debian Codegraph @

ansible_collections/microsoft/ad/tests/integration/targets/object_info/tasks/main.yml

raw
1 - name: create test ad group
2 microsoft.ad.group:
3 name: Ansible Test Group
4 scope: global
5
6 - name: create test ad user
7 microsoft.ad.user:
8 name: Ansible Test User
9 firstname: Ansible
10 surname: Test
11 company: Contoso R Us
12 password: Password01
13 state: present
14 password_never_expires: yes
15 groups:
16 set:
17 - Domain Users
18 - Ansible Test Group
19 enabled: false
20 register: test_user
21 notify: remove test domain user
22
23 - name: set a binary attribute and return other useful info missing from above
24 ansible.windows.win_powershell:
25 parameters:
26 SecurityId: '{{ test_user.sid }}'
27 script: |
28 param($SecurityId)
29
30 Set-ADUser -Identity $SecurityId -Replace @{ audio = @([byte[]]@(1, 2, 3, 4), [byte[]]@(5, 6, 7, 8)) }
31
32 $user = Get-ADUser -Identity $SecurityId -Properties modifyTimestamp, ObjectGUID
33
34 [TimeZoneInfo]::ConvertTimeToUtc($user.modifyTimestamp).ToString('o')
35 $user.ObjectGUID.ToString()
36 ([System.Security.Principal.SecurityIdentifier]$SecurityId).Translate([System.Security.Principal.NTAccount]).Value
37 register: test_user_extras
38
39 - name: set other test info for easier access
40 set_fact:
41 test_user_mod_date: '{{ test_user_extras.output[0] }}'
42 test_user_id: '{{ test_user_extras.output[1] }}'
43 test_user_name: '{{ test_user_extras.output[2] }}'
44
45 - name: get properties for single user by DN
46 object_info:
47 identity: '{{ test_user.distinguished_name }}'
48 properties:
49 - memberOf
50 register: by_identity
51 check_mode: yes # Just verifies it runs in check mode
52
53 - name: assert get properties for single user by DN
54 assert:
55 that:
56 - not by_identity is changed
57 - by_identity.objects | length == 1
58 - by_identity.objects[0].keys() | list | length == 5
59 - by_identity.objects[0].DistinguishedName == test_user.distinguished_name
60 - by_identity.objects[0].Name == 'Ansible Test User'
61 - by_identity.objects[0].ObjectClass == 'user'
62 - by_identity.objects[0].ObjectGUID == test_user_id
63 - by_identity.objects[0].memberOf | length == 1
64 - by_identity.objects[0].memberOf[0] is match("CN=Ansible Test Group,.*")
65
66 - name: get specific properties by GUID
67 object_info:
68 identity: '{{ test_user_id }}'
69 properties:
70 - audio # byte[]
71 - company # string
72 - department # not set
73 - logonCount # int
74 - modifyTimestamp # DateTime
75 - nTSecurityDescriptor # SecurityDescriptor as SDDL
76 - objectSID # SID
77 - ProtectedFromAccidentalDeletion # bool
78 - sAMAccountType # Test out the enum string attribute that we add
79 - userAccountControl # Test ou the enum string attribute that we add
80 register: by_guid_custom_props
81
82 - name: assert get specific properties by GUID
83 assert:
84 that:
85 - not by_guid_custom_props is changed
86 - by_guid_custom_props.objects | length == 1
87 - by_guid_custom_props.objects[0].DistinguishedName == test_user.distinguished_name
88 - by_guid_custom_props.objects[0].Name == 'Ansible Test User'
89 - by_guid_custom_props.objects[0].ObjectClass == 'user'
90 - by_guid_custom_props.objects[0].ObjectGUID == test_user_id
91 - not by_guid_custom_props.objects[0].ProtectedFromAccidentalDeletion
92 - by_guid_custom_props.objects[0].audio == ['BQYHCA==', 'AQIDBA==']
93 - by_guid_custom_props.objects[0].company == 'Contoso R Us'
94 - by_guid_custom_props.objects[0].department == None
95 - by_guid_custom_props.objects[0].logonCount == 0
96 - by_guid_custom_props.objects[0].modifyTimestamp == test_user_mod_date
97 - by_guid_custom_props.objects[0].nTSecurityDescriptor.startswith('O:')
98 - by_guid_custom_props.objects[0].objectSID.Name == test_user_name
99 - by_guid_custom_props.objects[0].objectSID.Sid == test_user.sid
100 - by_guid_custom_props.objects[0].sAMAccountType == 805306368
101 - by_guid_custom_props.objects[0].sAMAccountType_AnsibleFlags == ['SAM_USER_OBJECT']
102 - by_guid_custom_props.objects[0].userAccountControl == 66050
103 - by_guid_custom_props.objects[0].userAccountControl_AnsibleFlags == ['ADS_UF_ACCOUNTDISABLE', 'ADS_UF_NORMAL_ACCOUNT', 'ADS_UF_DONT_EXPIRE_PASSWD']
104
105 - name: get the groupType attribute
106 object_info:
107 filter: sAMAccountName -eq 'Domain Admins'
108 properties:
109 - groupType
110 register: group_type_prop
111
112 - name: assert get the groupType attribute
113 assert:
114 that:
115 - group_type_prop.objects[0].groupType_AnsibleFlags == ["GROUP_TYPE_ACCOUNT_GROUP", "GROUP_TYPE_SECURITY_ENABLED"]
116
117 - name: create computer object for enc type test
118 computer:
119 name: MyComputer
120 state: present
121 kerberos_encryption_types:
122 set:
123 - des
124 - rc4
125 - aes128
126 - aes256
127 register: comp_info
128
129 - block:
130 - name: get the supported encryption type attribute
131 object_info:
132 identity: '{{ comp_info.object_guid }}'
133 properties:
134 - msDS-SupportedEncryptionTypes
135 register: enc_type_prop
136
137 - name: assert get the supported encryption type attribute
138 assert:
139 that:
140 - enc_type_prop.objects[0]["msDS-SupportedEncryptionTypes"] == 31
141 - enc_type_prop.objects[0]["msDS-SupportedEncryptionTypes_AnsibleFlags"] == ["DES_CBC_CRC", "DES_CBC_MD5", "RC4_HMAC", "AES128_CTS_HMAC_SHA1_96", "AES256_CTS_HMAC_SHA1_96"]
142
143 always:
144 - name: remove computer object
145 computer:
146 name: MyComputer
147 identity: '{{ comp_info.object_guid }}'
148 state: absent
149
150 - name: get invalid property
151 object_info:
152 filter: sAMAccountName -eq 'Ansible Test User'
153 properties:
154 - FakeProperty
155 register: invalid_prop_warning
156
157 - name: assert get invalid property
158 assert:
159 that:
160 - not invalid_prop_warning is changed
161 - invalid_prop_warning.objects | length == 0
162 - invalid_prop_warning.warnings | length == 1
163 - '"Failed to retrieve properties for AD object" not in invalid_prop_warning.warnings[0]'
164
165 - name: get by ldap filter returning multiple
166 object_info:
167 ldap_filter: (&(objectClass=computer)(objectCategory=computer))
168 properties: '*'
169 register: multiple_ldap
170
171 - name: assert get by ldap filter returning multiple
172 assert:
173 that:
174 - not multiple_ldap is changed
175 - multiple_ldap.objects | length > 0
176
177 - name: get by filter returning multiple
178 object_info:
179 filter: objectClass -eq 'computer' -and objectCategory -eq 'computer'
180 properties: '*'
181 register: multiple_filter
182
183 - name: assert get by filter returning multiple
184 assert:
185 that:
186 - not multiple_filter is changed
187 - multiple_filter.objects | length > 0
188
189 - name: fail trying to use variable in filter
190 object_info:
191 filter: sAMAccountName -eq $domainUsername
192 properties:
193 - sAMAccountName
194 register: fail_filter_var
195 failed_when:
196 - '"Variable: ''domainUsername'' found in expression: $domainUsername is not defined." not in fail_filter_var.msg'