Convert with_dict to loop - help!

Hello there!

I’m trying (and failing) to convert a with_dict to a loop (have referred to this section of the docs https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#with-dict) with no success. I’m looping over a list of dicts and trying to access the key attribute for use in a template.

The data looks like this:

  • debug:
    var: delta

TASK [debug] ********************************
ok: [localhost] => {
“delta”: [
{
“test_developers”: {
“members”: [
“foo”,
“bar”
]
}
},
{
“test_qa”: {
“members”: [
“cheese”,
“rice”
]
}
}
]
}

The attribute I want to access is for example “test_developers” or “test_qa”, which I can do with with_dict like so:

loop over with_dict and print key

  • name: debug
    debug:
    msg: “{{ item.key }}”
    with_dict: “{{ delta }}”

TASK [debug] ********************************
ok: [localhost] => (item={‘key’: ‘test_developers’, ‘value’: {‘members’: [‘foo’, ‘bar’]}}) => {
“msg”: “test_developers”
}

- debug:
        msg: "{{ group|dict2items }}"
      loop: "{{ delta }}"
      loop_control:
        loop_var: group
        label: "{{ group }}"

Ah that works, thanks Dick - much appreciated!