Hello all, I'm new to python and ansible in general. I feel like I can't 
use this unless I plug into AD. I spent a great deal of time trying to 
learn python for a dynamic inventory and I'm completely stumped. The json 
seems to check out with the doc almost exact.

I'm running ansible from os x using python 2.7.11 and ansible 2.0.1.0

Here's my python script

non-essential-servers.py
==============================
# import class and constants
from ldap3 import Server, Connection, ALL, NTLM, Tls
import json
import ssl

#prompt for ldapusername and password
#ldapusr = ("playnetwork.com\\")
#ldapusr += raw_input("Username (use a read-only account):")
#ldappwd = getpass.getpass("Password for " + ldapusr + ":")


# define the server and the connection

server = Server('reddc2.playnetwork.com', use_ssl=True)
conn = Connection(server, user="domain\\username", password="password", 
authentication=NTLM, auto_bind=True)
#conn = Connection(server, user="playnetwork.com\\ldapusr", 
password=ldappwd, authentication=NTLM, auto_bind=True)

conn.open()
conn.bind()
conn.entries
conn.search('OU=Servers, OU=PlayNetwork, DC=playnetwork, 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['servers'] = hosts
export['vars'] = var
print json.dumps(export, sort_keys=True, indent=4, separators=(',', ': '))
====================
Simplied the json looks like this
{
    "servers": {
        "hosts": [
            "SERVER1",
            "SERVER2",
            "SERVER3",
        ]
    },
    "vars": {
        "a": true
    }
}

when I run 
ansible -i non-essential-servers.py all -m win_ping

I get the error
ERROR! non-essential-servers.py:2: Expected key=value host variable 
assignment, got: ldap3

I feel like I'm not "printing" like I should or not closing my ldap 
connection properly.
Thank you!

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2ef7cd25-b27e-4de5-912c-1123c06c9878%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to