Discussion:
[ansible-project] List of list and variables
Guillaume Querso
2015-07-23 08:36:10 UTC
Permalink
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 ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/61c7d5bf-9906-497f-a680-273f52cc22bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Brian Coca
2015-07-28 23:23:46 UTC
Permalink
first this is a list of dictionaries in mixed list/dictionaries which
are part of a dictionary (my_files), access to list is via index [0]
for first item or [1] for second, for dictionaries just use keys. But
I'm not sure this is a proper construct at all.
--
Brian Coca
--
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+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAJ5XC8mEdEDQf_CuspS_d%2Bn-cELU4BhjhKpz7_a0297-7oGVSg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
J Hawkesworth
2015-07-29 05:30:55 UTC
Permalink
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
Post by Guillaume Querso
i am not sure it is possible to do so, but i would like to have a list of
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 ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/75e8d7fb-5c73-4b26-902f-01fc55fb20ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Guillaume Querso
2015-07-29 08:28:15 UTC
Permalink
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, ...).
Post by J Hawkesworth
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
Post by Guillaume Querso
i am not sure it is possible to do so, but i would like to have a list of
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 ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1e24433a-e412-4267-8cc2-6c1917946a67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
J Hawkesworth
2015-07-29 11:41:40 UTC
Permalink
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
Post by Guillaume Querso
thank you for all your replies. i changed the way i am organizing my file.
- {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, ...).
Post by J Hawkesworth
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
Post by Guillaume Querso
i am not sure it is possible to do so, but i would like to have a list
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 ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
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.
Loading...