# HowTo transform variable groups.my\_group into array of dicts

**URL:** <https://forum.ansible.com/t/howto-transform-variable-groups-my-group-into-array-of-dicts/19669>\
**Category:** Ansible Project\
**Created:** [November 1, 2015, 8:22pm UTC](https://forum.ansible.com/t/howto-transform-variable-groups-my-group-into-array-of-dicts/19669 "2015-11-01T20:22:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Serega\_Sheypak](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Serega\_Sheypak](https://forum.ansible.com/u/Serega_Sheypak)\
**Post date:** [November 1, 2015, 8:22pm UTC](https://forum.ansible.com/t/howto-transform-variable-groups-my-group-into-array-of-dicts/19669/1 "2015-11-01T20:22:58Z")

</div>

Hi, I have a group named “zookeeper\_node”:

tasks:

- debug: msg=“System {{ groups.zookeeper\_node }}”

OUTPUT:

ok: [mesosnode01] =\> {  
“msg”: “System [‘mesosnode01’, ‘mesosnode02’, ‘mesosnode03’]”  
}

I want to transform it into array of dicts:

[{‘host’: ‘mesosnode01’},{‘host’: ‘mesosnode02’}, {‘host’: ‘mesosnode03’}]

and pass as variable to role:

roles:

- { role: ‘ansible-zookeeper’,  
zookeeper\_hosts: “{{ groups.zookeeper\_node | some magic expression here … }}”  
}

Can I do it in Ansible?

---

<div class="post-metadata">

**Author:** ![Serega\_Sheypak](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Serega\_Sheypak](https://forum.ansible.com/u/Serega_Sheypak)\
**Post date:** [November 1, 2015, 9:17pm UTC](https://forum.ansible.com/t/howto-transform-variable-groups-my-group-into-array-of-dicts/19669/2 "2015-11-01T21:17:04Z")

</div>

Did it using ugly filter:

```auto
def array_to_array_of_dicts(some_array, *args, **kw):
    data = []
    for some_value in some_array:
        data.append({'host': some_value})
    return data

class FilterModule (object):
    def filters(self):
        return {"array_to_array_of_dicts": array_to_array_of_dicts}

```
