# Collection: bundling a txt file

**URL:** <https://forum.ansible.com/t/collection-bundling-a-txt-file/34245>\
**Category:** Ansible Project\
**Created:** [November 26, 2020, 6:07pm UTC](https://forum.ansible.com/t/collection-bundling-a-txt-file/34245 "2020-11-26T18:07:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![belaran](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/belaran/32/2703_2.png) [@belaran](https://forum.ansible.com/u/belaran)\
**Post date:** [November 26, 2020, 6:07pm UTC](https://forum.ansible.com/t/collection-bundling-a-txt-file/34245/1 "2020-11-26T18:07:30Z")

</div>

Hi all,

I’ve a collection where I would like to externalize an array of strings. At run time, the collection will read their content and create an array based on the file. The idea being that this list can change without building again the collection.

I just wonder where, within my collection directory tree, to put this data file (it can be txt, csv, or even yml) and which internal API use to parse it.

Any tips?

Thanks!

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [November 27, 2020, 7:32am UTC](https://forum.ansible.com/t/collection-bundling-a-txt-file/34245/2 "2020-11-27T07:32:47Z")

</div>

Hi,

> I've a collection where I would like to externalize an array of  
> strings. At run time, the collection will read their content and  
> create an array based on the file. The idea being that this list can  
> change without building again the collection.

if the file is included in the collection, how can you update the file  
without building the collection?

> I just wonder where, within my collection directory tree, to put this  
> data file (it can be txt, csv, or even yml) and which internal API  
> use to parse it.

There's no internal API. You can place it whereever you want in the  
tree, there is no canonical place for it. I'd suggest to add some  
module\_utils code for reading it, it can use os.path.dirname(\_\_file\_\_)  
to get hold of the module\_utils directory path and load the file  
relative from there.

I did something like that in one of my collections:  
[https://github.com/felixfontein/ansible-tools/blob/main/plugins/filter/domain\_suffix.py#L10](https://github.com/felixfontein/ansible-tools/blob/main/plugins/filter/domain_suffix.py#L10)  
[https://github.com/felixfontein/ansible-tools/blob/main/plugins/public\_suffix\_list.dat](https://github.com/felixfontein/ansible-tools/blob/main/plugins/public_suffix_list.dat)

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![belaran](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/belaran/32/2703_2.png) [@belaran](https://forum.ansible.com/u/belaran)\
**Post date:** [November 27, 2020, 7:47am UTC](https://forum.ansible.com/t/collection-bundling-a-txt-file/34245/3 "2020-11-27T07:47:15Z")

</div>

Thanks for the tip.

Actually, I over simplify for the sake of brevity. The goal is to be able to add data to this file without changing the python code, because we need to duplicate source code for the sake of making it work on Windows ☹ So we try to reduce as much as possible the need to change the (duplicated) source file.
