I’m getting a traceback on a group_by, which is intended to create a group named after each of a host’s existing groups, prepended by a variable that is being set with ‘-e’ at invocation (a site/host-group ID):
name: vagrant | Create provider-agnostic ID_and_type group
group_by: key=“{{ id }}_{{ item }}”
with_items: group_names
when: provider == “vagrant”
The variable provider is also being set via ‘-e’. So for example, a host that was part of the dns and mail groups would be added to groups like prodSite1_dns and prodSite1_mail. These are not being set statically in an inventory file because sometimes it is run on ec2 hosts and the groups are pulled from tags, and sometimes it is run on a vagrant box and the groups are written into an inventory script.
For what it’s worth, I tried taking out the reference to group_names and instead passed into the role as a variable a list of group names to test with. I still got the traceback. It doesn’t happen if I just duplicate the task and use multiple copies of it that are even more hard coded such as: “{{ id }}_aStaticGroupName”. Now the whole thing breaks horribly past that point because of the change, but the tracebacks stop.
So AFAICT I get the traceback trying to use “{{ id }}_{{ item }}”.
Also I forgot to mention that I’m seeing this on v1.4.3.
Hi Mark/James,
Do you guys know if there was a bug filed on this? I’m running into a similar thing in 1.5.3. If not i’ll try and put together a minimal playbook to reproduce.
At the time I wasn’t immediately able to test the newer version James mentioned, and I worked around it soon after. So in short, no, I forgot to file anything in this case (sorry!).
How similar is your issue? (mainly curious if it is a host grouping thing, or if you’re just also iterating a built in structure with with_items:)
My normal “real” ec2 workflow expected Ansible to use a dynamic inventory anyway, and I’d already parameter-ized that call to allow for different inventory scripts in case I wanted to add rax support later. So what I ended up doing to get by was get help on IRC to write a simple (basically fake) dynamic inventory script for vagrant deploys that just prints out “localhost”, but already a member of the groups I needed. So it’s pretty much just a static inventory file in a format that is more convenient to the situation.
Hey Mark,
Mine is using with_items as well; i think that’s the common thread here. Specifically the task that seems to cause the exact traceback you see is as follows:
name: generate role groups
group_by: key=“{{ item }}”
with_items: all_roles
and it throws this traceback:
fatal: [waluat1] => Traceback (most recent call last):
File “/rbi/ansible/ansible/lib/ansible/runner/init.py”, line 532, in _executor
exec_rc = self._executor_internal(host, new_stdin)
File “/rbi/ansible/ansible/lib/ansible/runner/init.py”, line 654, in _executor_internal
complex_args=complex_args
File “/rbi/ansible/ansible/lib/ansible/runner/init.py”, line 809, in _executor_internal_inner
result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
File “/rbi/ansible/ansible/lib/ansible/runner/action_plugins/group_by.py”, line 86, in run
del self.runner.inventory._vars_per_host[host]
KeyError: ‘waluat1’
I will file something on github with a small example to reproduce.