# Ansible merge multiple files.

**URL:** <https://forum.ansible.com/t/ansible-merge-multiple-files/22540>\
**Category:** Ansible Project\
**Created:** [September 13, 2016, 10:06pm UTC](https://forum.ansible.com/t/ansible-merge-multiple-files/22540 "2016-09-13T22:06:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Marquez](https://avatars.discourse-cdn.com/v4/letter/e/9d8465/32.png) [@Eric\_Marquez](https://forum.ansible.com/u/Eric_Marquez)\
**Post date:** [September 13, 2016, 10:06pm UTC](https://forum.ansible.com/t/ansible-merge-multiple-files/22540/1 "2016-09-13T22:06:49Z")

</div>

Hello, I have a number of templates that are generated by Ansible but I need them combined into a single file. Is there a way to do this without having to do a shell command "file1 \>\> newFile.txt"

For example I have 4 files and I need to merge the content from these 4 source files to a single destination file.

File1 \> dest.txt  
File2 \>\> dest.txt  
File3 \>\> dest.txt  
File4 \>\> dest.txt

In my case these 4 files were generated by Ansible Templates. Since I have a vars file that is a data dictionary it creates multiple files. From these multiple files I need to merge them into a single file. I looked at lineinfile but I'm not saving a single line but 50 - 100 lines.  
Is there a better way to do this other than using shell commands?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [September 13, 2016, 10:52pm UTC](https://forum.ansible.com/t/ansible-merge-multiple-files/22540/2 "2016-09-13T22:52:34Z")

</div>

tempalate can do this via includes, but you also have the assemble module.

---

<div class="post-metadata">

**Author:** ![Eric\_Marquez](https://avatars.discourse-cdn.com/v4/letter/e/9d8465/32.png) [@Eric\_Marquez](https://forum.ansible.com/u/Eric_Marquez)\
**Post date:** [September 13, 2016, 11:14pm UTC](https://forum.ansible.com/t/ansible-merge-multiple-files/22540/3 "2016-09-13T23:14:00Z")

</div>

Is there an example of how you might use includes with template?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [September 13, 2016, 11:45pm UTC](https://forum.ansible.com/t/ansible-merge-multiple-files/22540/4 "2016-09-13T23:45:22Z")

</div>

here are the jinja docs about it:

[http://jinja.pocoo.org/docs/dev/templates/#include](http://jinja.pocoo.org/docs/dev/templates/#include)

---

<div class="post-metadata">

**Author:** ![Eric\_Marquez](https://avatars.discourse-cdn.com/v4/letter/e/9d8465/32.png) [@Eric\_Marquez](https://forum.ansible.com/u/Eric_Marquez)\
**Post date:** [September 15, 2016, 7:54pm UTC](https://forum.ansible.com/t/ansible-merge-multiple-files/22540/5 "2016-09-15T19:54:42Z")

</div>

Assemble worked, thanks for the help.
