Not really what it is you are trying to achieve, but perhaps you can have a 
simple structure and use filters to fetch the parts of the full path that 
you need.

Something like this:

---
- name: Demonstrate splitting paths
  hosts: localhost
  gather_facts: false
  vars:
    my_files:
      - /data/ansible/testing1/test.reg
      - /data/ansible/testing1/test.lst
  tasks:
     - name: get directory
       debug: msg={{item | dirname }}
       with_items: my_files


     - name: get basename
       debug: msg={{item | basename }}
       with_items: my_files


     - name: get extention before v2
       debug: msg={{item.split('.')[1] }}
       with_items: my_files


Hope this helps

Jon


On Wednesday, July 29, 2015 at 9:28:15 AM UTC+1, Guillaume Querso wrote:
>
> thank you for all your replies. i changed the way i am organizing my file. 
> now i do:
> my_files:
>   - {path: '/data/ansible/testing1', name: 'test1.reg', ext: '.reg'}
>   - {path: '/data/ansible/testing1', name: 'test1.lst', ext: '.lst'}
>
> so it is less readable but easier to access to a variable (item.path, 
> item.name, ...). 
>
> Le mercredi 29 juillet 2015 06:30:55 UTC+1, J Hawkesworth a écrit :
>>
>> That's a complicated structure, and you seem to be storing some redundant 
>> information.
>> Just wondering if you can simplify the structure and use filters to 
>> derive the ext from the name
>> See 
>> http://docs.ansible.com/ansible/playbooks_filters.html#other-useful-filters 
>> - there's a splitext filter which looks appropriate.
>>
>> Hope that helps,
>>
>> Jon
>>
>> On Thursday, July 23, 2015 at 9:36:10 AM UTC+1, Guillaume Querso wrote:
>>>
>>> i am not sure it is possible to do so, but i would like to have a list 
>>> of list. it would look like this:
>>>
>>> my_files:
>>>   path: /data/ansible/testing1/
>>>     - {name: 'test1.reg', ext: '.reg'}
>>>     - {name: 'test1.lst', ext: '.lst'}
>>>     - {name: 'test1.sql', ext: '.sql'}
>>>   path: /data/ansible/testing2/
>>>     - {name: 'test2.reg', ext: '.reg'}
>>>     - {name: 'test2.lst', ext: '.lst'}
>>>     - {name: 'test2.xsl', ext: '.xsl'}
>>>
>>> and most important, how can i access to those vairables in a playbook? 
>>>
>>> Note: i absolutely need to keep this kind of hierarchy with the path and 
>>> then the files in this path.
>>>
>>> Thank you!
>>>
>>

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/57e0dc2f-0a6e-4a37-aaa2-8b5a4be84a9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to