Circular dependency issue in release 1.4 ?

I’ve just upgrade my installation of ansible with the latest release and it seems there’s an issue with the callbacks module:

Considering the following directory structure:

ansible/
callbacks.py
utils/
init.py

callbacks.py line 18:

import utils

utils/init.py line 30:

from ansible.callbacks import display

This is just not possible since it take you to a circular dependency.

I’m not really sure what would be the best way to deal with that, probably splitting utils into multiple modules or removing code from init.py, i’m not exactly sure. Also i might not be the first one to raise this point, if it’s the case, i’m sorry about that :slight_smile:

How was it installed and then upgraded?

using pip:

pip install ansible

I imagine the world would be yelling us in greater quantity if callbacks weren’t working.

Please let us know steps to reproduce this problem and we can take a look, though I think it’s possible you have a mixed up install where you have “make installed” 1.3 or something and need to clean up after it, maybe?

That’s quite easy:

$ virtualenv test
$ source test/bin/activate
$ python

from ansible import callbacks, utils

Traceback (most recent call last):
File “”, line 1, in
File “/Users/mlhamel/test/lib/python2.7/site-packages/ansible/callbacks.py”, line 18, in
import utils
File “/Users/mlhamel/test/lib/python2.7/site-packages/ansible/utils/init.py”, line 30, in
from ansible.callbacks import display
ImportError: cannot import name display

I’m on OSX maverick

oh and i forget to mention an important step before running python:

$ pip install ansible

:-/

Let me know if you are able to reproduce, i’ll fill a bug report whenever you’re ready, i was able to reproduce also on Linux (Ubuntu and Arch) with and without --no-site-packages on the virtualenv

I confirm the issue.
Did anybody looked at it?

I have a very poor memory 4 months back, but I haven’t heard of reports of anything like this.

Everybody seems to be following the install instructions and doing fine.

Curious what’s different in your case, but also the latest is 1.4.4, not 1.4, so perhaps try a recent release.

All the 1.4.* releases has this issue, previous 1.3.* doesnt.

It’s simple to reproduce:

$ virtualenv p-env

New python executable in p-env/bin/python…

$ . p-env/bin/activate

$ pip install ansible==1.4.5

Downloading/unpacking ansible==1.4.5

$ pip freeze

Jinja2==2.7.2

MarkupSafe==0.18

PyYAML==3.10

ansible==1.4.5

ecdsa==0.10

httplib2==0.8

paramiko==1.12.2

pycrypto==2.6.1

wsgiref==0.1.2

$ python

Python 2.7.2 (default, Oct 11 2012, 20:14:37)

[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin

Type “help”, “copyright”, “credits” or “license” for more information.

from ansible import callbacks

Traceback (most recent call last):

File “”, line 1, in

File “/Users/tiziano/Development/Work-Startersquad/prudentia/p-env/lib/python2.7/site-packages/ansible/callbacks.py”, line 18, in

import utils

File “/Users/tiziano/Development/Work-Startersquad/prudentia/p-env/lib/python2.7/site-packages/ansible/utils/init.py”, line 30, in

from ansible.callbacks import display

ImportError: cannot import name display

looks like callbacks depends from utils, and utils depends from callbacks

Why are you trying to import callbacks explicitly?

Core ansible works which is why I am confused here.

– Michael

I’m developing a tool that uses Ansible and I want to run a Playbook myself, something like:

stats = callbacks.AggregateStats()
playbook_cb = callbacks.PlaybookCallbacks(verbose=True)
runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=True)
playbook = PlayBook(
playbook=playbook_file,
inventory=inventory,
remote_user=remote_user,
remote_pass=remote_pass,
transport=transport,
extra_vars=extra_vars,
only_tags=only_tags,
callbacks=playbook_cb,
runner_callbacks=runner_cb,
stats=stats
)

similar at want ansible-playbook does.

Do you have any suggestion?

I’d look at the bin script in /bin and follow the same pattern of imports probably.

– Michael