---
- hosts: localhost
  connection: local
  gather_facts: no
  vars:
    p: /usr/local/bin/opt/etc/opt/var/tmp/sbin/lib/blah/something/else
  tasks:
    - set_fact:
        parts: "{{ p.split('/')|difference(['']) }}"
    - set_fact:
        all: "{{ all | default([]) | union([parts[0:idx+1]|join('/')]) }}"
      loop: "{{ parts }}"
      loop_control:
        index_var: idx
    - debug: var=all


Output:


TASK [debug] 
**************************************************************************************************
ok: [localhost] =>
  all:
  - usr
  - usr/local
  - usr/local/bin
  - usr/local/bin/opt
  - usr/local/bin/opt/etc
  - usr/local/bin/opt/etc/var
  - usr/local/bin/opt/etc/var/tmp
  - usr/local/bin/opt/etc/var/tmp/sbin
  - usr/local/bin/opt/etc/var/tmp/sbin/lib
  - usr/local/bin/opt/etc/var/tmp/sbin/lib/blah
  - usr/local/bin/opt/etc/var/tmp/sbin/lib/blah/something
  - usr/local/bin/opt/etc/var/tmp/sbin/lib/blah/something/else

PLAY RECAP 
****************************************************************************************************
localhost                  : ok=3    changed=0    unreachable=0
failed=0    skipped=0    rescued=0    ignored=0

On Thu, 5 Aug 2021 at 00:55, William McKenzie <[email protected]> wrote:
>
> Is there any simple expression/filter magic that would allow me to convert a 
> path string to a list of all the contained paths.
>
> So:
> "a/b/c/d"
>
> would become:
>
> [ "a",  "a/b" , "a/b/c" , "a/b/c/d" ]
>
> --
> 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/cc4a64d8-87da-4bf7-8a91-16618f349270n%40googlegroups.com.



-- 
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

-- 
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/CAL8fbwO0CLMGMzyK2kM%3D9YRrJLBQcgxqtDdUw%3DgoTAVeBLv1gQ%40mail.gmail.com.

Reply via email to