# Make a list from list of dicts

**URL:** <https://forum.ansible.com/t/make-a-list-from-list-of-dicts/29915>\
**Category:** Ansible Project\
**Created:** [March 19, 2019, 11:32pm UTC](https://forum.ansible.com/t/make-a-list-from-list-of-dicts/29915 "2019-03-19T23:32:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ashok1](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@Ashok1](https://forum.ansible.com/u/Ashok1)\
**Post date:** [March 19, 2019, 11:32pm UTC](https://forum.ansible.com/t/make-a-list-from-list-of-dicts/29915/1 "2019-03-19T23:32:00Z")

</div>

Hi all…

I’ve a list of dicts like the below:

`  
client\_destinations:  
apache-servers:  
pre\_cmd: ‘$template custom,“/logs/apache-servers/%source%.log”’  
rules:

- var: ‘$syslogfacility-text’  
operator: ‘contains’  
search: ‘local5’  
destination: ‘-?custom’  
path: ‘/logs/apache-servers/\*.log’
- var: ‘$syslogtag’  
search: ‘apache-access:’  
operator: ‘contains’  
destination: ‘/logs/apache-servers/access.log’
- var: ‘$syslogtag’  
search: ‘apache-error:’  
operator: ‘contains’  
destination: ‘/logs/apache-servers/error.log’
- destination: ‘/logs/apache-servers/other.log’

old-web:  
rules:

- var: ‘$syslogfacility-text’  
operator: ‘==’  
search: ‘local3’  
destination: ‘/logs/web/dyn.log’
- var: ‘$syslogfacility-text’  
operator: ‘==’  
search: ‘local2’  
destination: ‘/logs/web/activity.log’

mx-catchall:  
rules:

- destination: ‘/logs/mx/mail.log’

switches:  
pre\_cmd: ‘$template network,“/logs/network/%source%.log”’  
rules:

- destination: ‘-?network’  
path: ‘/logs/network/\*.log’  
`

I need to form a “list” of values of `destination` (which are mostly file-paths). But, in case of `rules` that have non-file path values (like ‘-?custom’, ‘-?network’) in `destination`, I need to ignore this value, and instead, get the value of `path`. So far, I have come up with a task that generates `logf_dest`, a “list”, ignoring non-file paths:

`

- name: Collect log destinations  
set\_fact:  
logf\_dest: “{{ client\_destinations.values() | map(attribute=‘rules’) | list | flatten | map(attribute=‘destination’) | reject(‘match’, ‘-[?]’) | list }}”  
`

The downside to this is that while it successfully ignores `destination` that has non-file path values, it doesn’t include the corresponding value of `path` in place of the ignored `destination` value. How do I achieve this?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Ashok1](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@Ashok1](https://forum.ansible.com/u/Ashok1)\
**Post date:** [March 19, 2019, 11:51pm UTC](https://forum.ansible.com/t/make-a-list-from-list-of-dicts/29915/2 "2019-03-19T23:51:05Z")

</div>

Another way to state my requirement:

Form a list of values of `destination`. And, in `rules` where `destination` and `path` occur together, ignore `destination` and take up corresponding value of `path`. My desired output:

`  
logf\_dest:

- /logs/apache-servers/\*.log
- /logs/apache-servers/access.log
- /logs/apache-servers/error.log
- /logs/apache-servers/other.log
- /logs/web/dyn.log
- /logs/web/activity.log
- /logs/mx/mail.log
- /logs/network/\*.log  
`

Thanks.
