Tested with:
| #!/usr/bin/python3 | | import re | | import ldap3 | | if __name__ == '__main__': | # Get user name and password. | with open('/etc/ldap.conf', 'r') as f: | for line in f.readlines(): | if line == '\n': | continue | m = re.match('^([^ ]+) +(.*?) *\n$', line) | if m.group(1) == 'binddn': | binddn = m.group(2) | elif m.group(1) == 'bindpw': | bindpw = m.group(2) | | # Connect to LDAP server. | server = ldap3.Server('ldap-eqiad.wikimedia.org') | conn = ldap3.Connection(server, read_only=True, | user=binddn, password=bindpw) | conn.bind() | conn.start_tls() | | # Query. | conn.search('ou=hosts,dc=wikimedia,dc=org', | '(puppetVar=instanceproject=%s)' % 'tools', | ldap3.SEARCH_SCOPE_WHOLE_SUBTREE, | attributes=ldap3.ALL_ATTRIBUTES) | for responseitem in conn.response: | print(repr(responseitem))
for python3-ldap3 and amending the shebang line and the print call for python-ldap3 (Python 2).
Tested with:
| #!/usr/bin/python3 etc/ldap. conf', 'r') as f: 'ldap-eqiad. wikimedia. org') n(server, read_only=True, 'ou=hosts, dc=wikimedia, dc=org' , instanceproject =%s)' % 'tools', SCOPE_WHOLE_ SUBTREE, ldap3.ALL_ ATTRIBUTES) responseitem) )
|
| import re
|
| import ldap3
|
| if __name__ == '__main__':
| # Get user name and password.
| with open('/
| for line in f.readlines():
| if line == '\n':
| continue
| m = re.match('^([^ ]+) +(.*?) *\n$', line)
| if m.group(1) == 'binddn':
| binddn = m.group(2)
| elif m.group(1) == 'bindpw':
| bindpw = m.group(2)
|
| # Connect to LDAP server.
| server = ldap3.Server(
| conn = ldap3.Connectio
| user=binddn, password=bindpw)
| conn.bind()
| conn.start_tls()
|
| # Query.
| conn.search(
| '(puppetVar=
| ldap3.SEARCH_
| attributes=
| for responseitem in conn.response:
| print(repr(
for python3-ldap3 and amending the shebang line and the print call for python-ldap3 (Python 2).