Here’s my version: ansible 2.2.0 (devel 87928ff56b) last updated 2016/06/22 13:32:23 (GMT -500)
I’m not sure if this is a bug, or misplaced syntax. When I attempt to use a dictionary, referencing the key of the dictionary and a subelement, I get the error
FAILED! => {"failed": true, "msg": "'dict object' has no attribute 'key'"}
Here is my task:
`
name: Add users to groups
shell: ‘ipa group-add-member {{item.1}} --users={{item.0.key}}’
with_subelements:
‘{{staff|default()}}’
‘extragroups’
skip_missing: yes
`
If I use item.0 instead of item.0.key, it tries to pass in the entire dictionary object rather than just the key, and the command spits back a “too many arguments” error, which is expected. I need just the username, eg the argument I want to pass is --users=user1. Is there a reason I cannot access it with item.0.key?
For a little while I thought maybe subelements cannot use a dict, but I just saw someone else’s error that with_subelements needs a dict or a list as its first argument. So, how do I access {{item.0.key}} from a dict using with_subelements?
Thanks for the quick response. I think i’m going to just hack the name into the dict like so as i want to preserve the dict structure and this least bad way i see of doing that. My dict var is auto populated from another tool so it shouldn’t be hard for me to keep these in sync.
This would be a super helfpul feature to have, even if it’s another lookup separate from with_subelements. The use case I have for this is a set of interfaces on a host that are in a dict with the keys being the interface names, e.g.: