On Thu, 17 Aug 2023 00:46:08 +0200
Vladimir Botka <[email protected]> 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

There are options. Filter *basename* and get rid of *prefix*

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

Create the hash in *regex_replace* and use *from_yaml* instead
of *community.general.dict_kv*

  bn: "{{ all_objects|
          map(attribute='Key')|
          map('basename')|
          map('regex_replace', bn_regex, '{basename: \\1}')|
          map('from_yaml') }}"

Instead of *regex_replace* use *splitext* and *split*

  bn: "{{ all_objects|
          map(attribute='Key')|
          map('basename')|
          map('splitext')|map('first')|
          map('split', '_', 1)|map('last')|
          map('community.general.dict_kv', 'basename') }}"


-- 
Vladimir Botka

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20230817013426.387bc3d6%40gmail.com.

Attachment: pgpIJbMNdKKpL.pgp
Description: OpenPGP digital signature

Reply via email to