Example to customize modules errors

60 views
Skip to first unread message

Tiglath

unread,
Oct 30, 2014, 2:58:41 PM10/30/14
to ansible...@googlegroups.com
I followed the docs example to add a module as with the time.py example.
 
So I have:
-----------
#!/usr/bin/python

import datetime
import json

date = str(datetime.datetime.now())
print json.dumps({
    "time" : date
})
-----------
 
And after:
 
source ansible/hacking/env-setup
chmod +x ansible/hacking/test-module
ansible/hacking/test-module -m ./time.py
 
I get:
 

{"time": "2014-10-30 14:34:22.224548"}

Traceback (most recent call last):

File "ansible-dev/hacking/test-module", line 37, in <module>

import ansible.utils as utils

File "/export/home/jsuriol/.local/lib/python2.6/site-packages/ansible-1.8-py2.6.egg/ansible/utils/__init__.py", line 29, in <module>

from ansible.utils.display_functions import *

File "/export/home/jsuriol/.local/lib/python2.6/site-packages/ansible-1.8-py2.6.egg/ansible/utils/display_functions.py", line 22, in <module>

from ansible.callbacks import display

File "/export/home/jsuriol/.local/lib/python2.6/site-packages/ansible-1.8-py2.6.egg/ansible/callbacks.py", line 31, in <module>

import logging

File "/usr/lib/python2.6/logging/__init__.py", line 89, in <module>

_startTime = time.time()

AttributeError: 'module' object has no attribute 'time'

-------

The file logging/__init__.py imports time, so what can the problem be?

 

Thanks

 

 

 

Matt Martz

unread,
Oct 30, 2014, 3:07:55 PM10/30/14
to ansible...@googlegroups.com
Since "time" is part of the Python standard library and it is imported from various places within ansible you should not have a module named time.py since puthon will try to use that file as the file to satisfy "import time".

This wouldn't have been a problem before modules had .py extensions.  I imagine the docs should probably be updated to name this something other than time.py
--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/78ba5eaa-226c-412c-8df9-559014c722e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

Michael DeHaan

unread,
Oct 30, 2014, 4:56:53 PM10/30/14
to ansible...@googlegroups.com
Yep, that's a good suggestion.

Can you either please file a ticket on github.com/ansible/ansible or submit a pull request that changes the docs (.rst files in the code tree) to say something like "timecheck" ?

I think this ordinarily won't happen anyway, but the module happened to be in your PYTHON_PATH.  Usually this wouldn't be the case but it would be nice to step around the possible confusion for others finding this in the dev docs.

Appreciate the heads up!



Reply all
Reply to author
Forward
0 new messages