Ansible/Trellis Bug? Unexpected Exception

Hey guys,

I haven’t posted a question on here for a wee bit. Which is amazing, because Roots has been working pretty damn flawlessly for me.

But the last project I spun up, I had some issue when vagranting up. Took me a few hours to work out. It was a matter of having Ansible v2.0.0.2, but it seemed to want v2.0.2.0.

I tried updating it via pip.

When that failed I tried using homebrew.

I went back to pip, figured out the upgrade, then everything worked fine. Provisioned, deployed to staging.

Until today when I went to go provision and deploy, it said:

ERROR! Unexpected Exception: 'AnsibleMapping' object has no attribute 'iteritems'

Verbose output:

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.4/bin/ansible-playbook", line 86, in <module> sys.exit( File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/ansible/cli/", line 128, in run inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=self.options.inventory) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/ansible/inventory/", line 85, in __init__ self.parse_inventory(host_list) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/ansible/inventory/", line 147, in parse_inventory host.vars = combine_vars(host.vars, self.get_host_variables( File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/ansible/inventory/", line 540, in get_host_variables self._vars_per_host[hostname] = self._get_host_variables(hostname, vault_password=vault_password) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/ansible/inventory/", line 558, in _get_host_variables vars_results = [ plugin.get_host_vars(host, vault_password=vault_password) for plugin in self._vars_plugins if hasattr(plugin, 'get_host_vars')] File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/ansible/inventory/", line 558, in <listcomp> vars_results = [ plugin.get_host_vars(host, vault_password=vault_password) for plugin in self._vars_plugins if hasattr(plugin, 'get_host_vars')] File "/Users/masoninthesis/Sites/jackalopeio-v2.0/trellis/lib/trellis/plugins/vars/", line 40, in get_host_vars self.wrap_salts_in_raw(host, host.get_group_vars()) File "/Users/masoninthesis/Sites/jackalopeio-v2.0/trellis/lib/trellis/plugins/vars/", line 25, in wrap_salts_in_raw for name, site in hostvars['vault_wordpress_sites'].iteritems(): AttributeError: 'AnsibleMapping' object has no attribute 'iteritems'

I know this isn’t entirely Roots related. Seems more Ansible related than anything. But it’s strange that my deploy worked fine a couple days ago, fast forward– I didn’t touch Ansible or Trellis, and it stopped working.

Any tips would be so lovely. Thanks!

Could be that messing with homebrew and pip has dirtied up your Ansible install. Maybe force uninstall Ansible on both homebrew and pip and then $ sudo pip install ansible v==

Hey thanks! I gave that a try but no luck. One odd thing is that when I tried re-installing Ansible with sudo pip install ansible v==, I would get:

Collecting ansible Downloading ansible- (1.9MB) 100% |████████████████████████████████| 1.9MB 331kB/s

Collecting v==2.0.2 Could not find a version that satisfies the requirement v==2.0.2 (from versions: 2.0.0, 2.1.0) No matching distribution found for v==2.0.2

Obviously, there is a v2.0.2 of Ansible. So I’m not sure why it’s telling me that.

I just ran sudo pip install ansible v==2.1, it installed. But I’m still getting the same unexpected exception error as I was getting before.

Any thoughts? Could it be an issue with my Python, and not just Ansible?

P.S. Meanwhile I’m checking out this bug on Ansible’s github. Looks like a mismatched ansible versions deal.

My mistake, the cmd is actually $ sudo pip install ansible== (removed the v switch/arg). Give that a try.


Awesome. Yeah that worked for the upgrade, but I still get the same error.

This ansible issue is marked as closed. But it’s not clear to me what the solution was. A debian package conflict? Is the solution to install Ansible via git clone? Or possibly some error with a git submodule?

Have you double checked your wordpress_sites.yml and vault.yml? Looks like this could also be a config issue, possibly even a syntax issue. Could even be an errant space or hyphen in one of your yml files. Try with those two files perhaps?

1 Like

The yaml checked out in the linter. It’s in a private repo, but I can put it up on a gist if you want.

The problem seems to be deeper than my Trellis project, because I vagrant destroyed, tried to re- vagrant up and I got the exact same error I was getting before.

So I went through my whole machine and wiped all traces of Ansible.


Now I get his error when Vagrant’ing up:

MasonsMBP:trellis masoninthesis$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... There are errors in the configuration of this machine. Please fix the following errors and try again:


  • The ‘ansible’ provisioner could not be found.`

There aren’t any results on Google for Ansible provisioner could not be found. Only for similar issues Ansible software could not be found. So I’m trying to explore where this new issues lies.

Ansible definitely appears to be installed:
MasonsMBP:/ masoninthesis$ ansible --version ansible config file = configured module search path = Default w/o overrides

MasonsMBP:/ masoninthesis$ which ansible /Library/Frameworks/Python.framework/Versions/3.4/bin/ansible

For the record, my other projects aren’t Vagrant’ing up right now either. So it’s definitely a local issue, not in the yml files.

I think I’m honing in closer to this issue. It seems related to this topic: Error on the “Install the Ansible Galaxy roles” step of Trellis installation (Newbie)

Notice that from my errors above, it seems to try using Python3.4, but I have 2.7 installed.
MasonsMBP:/ masoninthesis$ python --version Python 2.7.10

I’m going to look more into this topic and see if I can’t sort it out.

I have a feeling this is because I may have accidentally updated Python late one night. I’m trying to get everything back to just 2.7, but there’s a lot of different issues popping up. As mentioned in this StackOverflow thread, I might just be better off re-installing osX. I’ll probably do that sometime tonight unless anyone has any better ideas?

I’d probably try to install it with Homebrew first. It should override the system version.

I think the 'ansible' provisioner is Vagrant’s provisioner tool that reaches out to–and uses–your Ansible installation. So, it could be a Vagrant thing that you deleted when you “went through [your] whole machine and wiped all traces of Ansible.” You might need a Vagrant reinstall to fix that.

Given this suggestion that your Ansible is associated with python 3.x, note that the iteritems() method from python 2.x no longer exists (is renamed) in python 3.x. So, if you’re now using 3.x, that could account for the error you got …

However, the first instance of iteritems() is on line 26, not on line 25 like your error suggests. This makes me wonder if somehow your version of is missing one critical earlier line: from ansible.compat.six import iteritems, which defines a special iteritems() for your PY3 to use.

So, double-check that you do in fact have this line:
from ansible.compat.six import iteritems
If you do not have that line, perhaps you performed a strange Trellis update/merge at some point. Until you have that line or ensure that Ansible uses python 2.x, I think that no reinstall of other stuff will avoid the iteritems error. Note that in the past, I’ve tested Trellis on python 3.x and it worked fine, assuming you have that compat.six import that is part of default Trellis.

In any case, it might not hurt to reinstall stuff if you’ve been tinkering. Good luck. I recently enjoyed managing python versions on OS X via pyenv (example installation guide). For pyenv to work on el capitan, I had to first install python via brew, then apply pyenv.

1 Like

Thanks for the tips guys!

I’d probably try to install it with Homebrew first. It should override the system version.

@swalkinshaw, a few hours ago I used that exact same method for installing Python 2.7 again.

I want to delete 3.4, but I didn’t want to screw anything up worse either. Maybe it’s not overriding correctly, but brew link python seemed to work fine. I thought that would override it.

MasonsMBP:/ masoninthesis$ brew link python Warning: Already linked: /usr/local/Cellar/python/2.7.11 To relink: brew unlink python && brew link python

You might need a Vagrant reinstall to fix that.

@fullyint, I re-installed Vagrant. No dice, but when I vagrant up now I do get a different error:
vagrant-hostmanager missing, please install the plugin with this command: vagrant plugin install vagrant-hostmanager. Which is odd, because I keep installing hotmanager, and it successfully installs. (I do have manager.rb under /opt/vagrant/embedded/gems/gems/vagrant-1.8.3/lib/vagrant/plugin/).

So, double-check that you do in fact have this line: looks fine. Only reason it said line 25 was because I was using that error from a Roots project a couple months old (for testing vagrant up). But the one I’m currently working on is in the repo linked above.

Thanks guys. Still might have to look at re-installing osX, but I’m going to try a few things while I’m backing up my hardrive. (Such as pyenv and force deleting Python3)

Hey just to updated everyone– I finally got this worked out early this morning.

After trying out pyenv, confirming that it was working correctly, my vagrant/ansible still weren’t working correctly.

Then I started force deleting all the local versions of Python that weren’t v2.7.

Still no dice. So I reformatted my machine and did a clean install of El Capitan. Took quite awhile to get everything installed again, but everything seems to be working very smoothly at the moment. Thanks for the help guys!

Edit: To make the solution more clear- don’t go installing/upgrading new versions of Python if you don’t know what you’re doing. It can really screw things up (according to some horror stories, making most apps unfunctional). If you do something stupid, reformatting may be your best option.