---
- name: Add helper keys to list of dicts
hosts: localhost
connection: local
gather_facts: no
tasks:
- set_fact:
backup_objects: "{{ backup_objects|default([]) | union(
[
item | combine(
{
'basename': item.Key|regex_replace('^' ~ prefix ~ '\\d{10}_(.*)\\.pgdump', '\\1')
}
)
]
)
}}"
loop: "{{ all_objects }}"
loop_control:
label: "{{ item.Key }}"
- debug: var=backup_objects
vars:
prefix: backup/database/
all_objects:
- ETag: '"d41d8cd98f00b204e9800998ecf8427e"'
Key: backup/database/1689953756_dev_wss_db.pgdump
LastModified: '2023-07-21T15:36:01.000Z'
Owner:
ID: 2d8917bbcab5a8e0d3d7f5f39d147cd6de38e883357d7ae16323398c302fe97e
Size: 0
StorageClass: STANDARD
- ETag: '"d41d8cd98f00b204e9800998ecf8427e"'
Key: backup/database/1689953756_dev_wss_db_requests.pgdump
LastModified: '2023-07-21T15:36:08.000Z'
Owner:
ID: 2d8917bbcab5a8e0d3d7f5f39d147cd6de38e883357d7ae16323398c302fe97e
Size: 0
StorageClass: STANDARD
- ETag: '"d41d8cd98f00b204e9800998ecf8427e"'
Key: backup/database/1689953756_dev_bss_service_database.pgdump
LastModified: '2023-07-21T15:36:13.000Z'
Owner:
ID: 2d8917bbcab5a8e0d3d7f5f39d147cd6de38e883357d7ae16323398c302fe97e
Size: 0
StorageClass: STANDARD
- ETag: '"d41d8cd98f00b204e9800998ecf8427e"'
Key: backup/database/1689953756_dev_bss_frontend_db.pgdump
LastModified: '2023-07-21T15:36:19.000Z'
Owner:
ID: 2d8917bbcab5a8e0d3d7f5f39d147cd6de38e883357d7ae16323398c302fe97e
Size: 0
StorageClass: STANDARD
- ETag: '"d41d8cd98f00b204e9800998ecf8427e"'
Key: backup/database/1689953756_dev_mss_db.pgdump
LastModified: '2023-07-21T15:36:25.000Z'
Owner:
ID: 2d8917bbcab5a8e0d3d7f5f39d147cd6de38e883357d7ae16323398c302fe97e
Size: 0
StorageClass: STANDARD
- set_fact: backup_objects: | {% set result = [] %} {% for obj in all_objects %} {% set _ = result.append({'basename': obj['Key'] | regex_replace('^' ~ prefix ~ '\\d{10}_(.*)\.pgdump', '\\1')} | combine(obj)) %} {% endfor %}{{ result }}The point of the "set _" line is for the side effect of appending revised objects to the "result" list. Otherwise it's pretty straightforward.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAF8BbLZDy-7ym4pcEJSBuCVkZZ2gPzinj8NFTcNnN6WedH%2BfMQ%40mail.gmail.com.
-- Todd
- set_fact: bn: | {{ query('ansible.builtin.nested', ['basename'], (all_objects | map(attribute='Key') | map('regex_replace', '^' ~ prefix ~ '\d{10}_(.*)\.pgdump', '\1'))) }}which produces:
bn: - - basename - dev_wss_db - - basename - dev_wss_db_requests - - basename - dev_bss_service_database - - basename - dev_bss_frontend_db - - basename - dev_mss_dbBut I didn't find a way to map that using "community.general.dict" to create
bn: - basename: dev_wss_db - basename: dev_wss_db_requests - basename: dev_bss_service_database - basename: dev_bss_frontend_db - basename: dev_mss_db
- - basename - dev_wss_db - - basename - dev_wss_db_requests - - basename - dev_bss_service_database - - basename - dev_bss_frontend_db - - basename - dev_mss_dbinto this:
- - - basename - dev_wss_db - - - basename - dev_wss_db_requests - - - basename - dev_bss_service_database - - - basename - dev_bss_frontend_db - - - basename - dev_mss_dbi.e. a "deepen" counterpart to "flatten". But that magical incantation has so far eluded me.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/20230817202944.3f3512c8%40gmail.com.