Thanks, Vladimir. I had missed the point of "community.general.dict_kv". I had gotten as far as this:

    - 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_db

But 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

This for me is one of the more frustrating things about Jinja pipelines. I keep wishing "map" would take arbitrary expressions rather than the limited set it's stuck with. So you end up with a fleet of one-off filters like "community.general.dict_kv" which does what "community.general.dict" would do if there were an obvious way to turn this:

  - - basename
    - dev_wss_db
  - - basename
    - dev_wss_db_requests
  - - basename
    - dev_bss_service_database
  - - basename
    - dev_bss_frontend_db
  - - basename
    - dev_mss_db

into this:

  - - - basename
      - dev_wss_db
  - - - basename
      - dev_wss_db_requests
  - - - basename
      - dev_bss_service_database
  - - - basename
      - dev_bss_frontend_db
  - - - basename
      - dev_mss_db

i.e. a "deepen" counterpart to "flatten". But that magical incantation has so far eluded me.
--
Todd

On 8/16/23 6:46 PM, Vladimir Botka wrote:
Create the list of the hashes

   bn_regex: '^{{ prefix }}\d{10}_(.*)\.pgdump$'
   bn: "{{ all_objects|
           map(attribute='Key')|
           map('regex_replace', bn_regex, '\\1')|
           map('community.general.dict_kv', 'basename') }}"

gives

   bn:
   - basename: dev_wss_db
   - basename: dev_wss_db_requests
   - basename: dev_bss_service_database
   - basename: dev_bss_frontend_db
   - basename: dev_mss_db

zip the lists and combine the items

   backup_object: "{{ all_objects|zip(bn)|map('combine') }}"



--
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-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/d783a813-746b-c961-eca7-76ba6bccc6aa%40gmail.com.

Reply via email to