---
- 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
> --
> 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/cc4a64d8-87da-4bf7-8a91-16618f349270n%40googlegroups.com.
--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT