Re: Inventory: ERROR! non-essential-servers.py:2: Expected key=value host variable assignment, got: ldap3

360 views
Skip to first unread message
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Jared Jenkins

unread,
Apr 26, 2016, 2:45:25 PM4/26/16
to Ansible Project
#!/usr/bin/env python
# -*- coding: utf-8 -*

# import class and constants
from ldap3 import Server, Connection, ALL, NTLM, Tls
import json
import ssl


# define the server and the connection

server = Server('server', use_ssl=True)
conn = Connection(server, user="domain\\kace_ldap", password="password", authentication=NTLM, auto_bind=True)
#conn = Connection(server, user=ldapusr, password=ldappwd, authentication=NTLM, auto_bind=True)

conn.open()
conn.bind()
conn.entries
conn.search('OU=Servers, OU=OU, DC=Domain, DC=com', '(objectclass=computer)', attributes=["name"])

names = []
for x in conn.response:
    names.append(x['attributes']['name'][0])

conn.unbind()

hosts = {}
hosts['hosts'] = names
var = {'a':True}

export = {}
export['windows'] = hosts
print json.dumps(export, sort_keys=True, indent=4, separators=(',', ': '))

Reply all
Reply to author
Forward
0 new messages