# creating a list of dicts from a list

**URL:** <https://forum.ansible.com/t/creating-a-list-of-dicts-from-a-list/27332>\
**Category:** Ansible Project\
**Created:** [April 19, 2018, 8:03pm UTC](https://forum.ansible.com/t/creating-a-list-of-dicts-from-a-list/27332 "2018-04-19T20:03:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim1](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@Tim1](https://forum.ansible.com/u/Tim1)\
**Post date:** [April 19, 2018, 8:03pm UTC](https://forum.ansible.com/t/creating-a-list-of-dicts-from-a-list/27332/1 "2018-04-19T20:03:55Z")

</div>

Hi,

I'm wondering if anyone might know how I would use the standard  
ansible filters to create a new variable from an existing variable.

I would like to take a list of items

list1:  
&nbsp;&nbsp;- foo  
&nbsp;&nbsp;- bar  
&nbsp;&nbsp;- baz

and convert it into a list of dictionaries with a "name" key

list2:  
&nbsp;&nbsp;- name: foo  
&nbsp;&nbsp;- name: bar  
&nbsp;&nbsp;- name: baz

Any ideas?

Thanks,  
-tim

---

<div class="post-metadata">

**Author:** ![Karl\_Auer1](https://avatars.discourse-cdn.com/v4/letter/k/b77776/32.png) [@Karl\_Auer1](https://forum.ansible.com/u/Karl_Auer1)\
**Post date:** [April 19, 2018, 10:11pm UTC](https://forum.ansible.com/t/creating-a-list-of-dicts-from-a-list/27332/2 "2018-04-19T22:11:43Z")

</div>

Use set\_fact?

---

<div class="post-metadata">

**Author:** ![Tim1](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@Tim1](https://forum.ansible.com/u/Tim1)\
**Post date:** [April 19, 2018, 10:26pm UTC](https://forum.ansible.com/t/creating-a-list-of-dicts-from-a-list/27332/3 "2018-04-19T22:26:46Z")

</div>

Obviously, care to elaborate? Like with Jinja filters, loops, etc
