Make a list from list of dicts

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.

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.