Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ldap inventory add filter_without_computer #60

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelogs/fragments/ldap-filter-raw.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
minor_changes:
- >-
microsoft.ad.ldap - Added the option ``filter_without_computer`` to not add the AND clause ``objectClass=computer``
to the final filter used - https://github.com/ansible-collections/microsoft.ad/issues/55
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace: microsoft
name: ad
version: 1.2.0
version: 1.3.0
readme: README.md
authors:
- Jordan Borean @jborean93
Expand Down
28 changes: 21 additions & 7 deletions plugins/inventory/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,19 @@
filter:
description:
- The LDAP filter string used to query the computer objects.
- This will be combined with the filter "(objectClass=computer)".
- By default, this will be combined with the filter
"(objectClass=computer)". Use I(filter_without_computer) to override
this behavior and have I(filter) be the only filter used.
type: str
filter_without_computer:
description:
- Will not combine the I(filter) value with the filter
"(objectClass=computer)".
- In most cases this should be C(false) but can be set to C(true) to have
the I(filter) value specified be the only filter used.
type: bool
default: false
version_added: '1.3.0'
search_base:
description:
- The LDAP search base to find the computer objects in.
Expand Down Expand Up @@ -259,6 +270,7 @@ def parse(
groups = self.get_option("groups")
keyed_groups = self.get_option("keyed_groups")
ldap_filter = self.get_option("filter")
ldap_filter_without_computer = self.get_option("filter_without_computer")
search_base = self.get_option("search_base")
search_scope = self.get_option("search_scope")
strict = self.get_option("strict")
Expand All @@ -272,12 +284,14 @@ def parse(
computer_filter = sansldap.FilterEquality("objectClass", b"computer")
final_filter: sansldap.LDAPFilter
if ldap_filter:
final_filter = sansldap.FilterAnd(
filters=[
computer_filter,
sansldap.LDAPFilter.from_string(ldap_filter),
]
)
ldap_filter_obj = sansldap.LDAPFilter.from_string(ldap_filter)

if ldap_filter_without_computer:
final_filter = ldap_filter_obj
else:
final_filter = sansldap.FilterAnd(
filters=[computer_filter, ldap_filter_obj]
)
else:
final_filter = computer_filter

Expand Down