Ansible merge multiple files.

5,654 views
Skip to first unread message

Eric Marquez

unread,
Sep 13, 2016, 6:06:56 PM9/13/16
to ansible-project (ansible-project@googlegroups.com)
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?
winmail.dat

Brian Coca

unread,
Sep 13, 2016, 6:53:00 PM9/13/16
to ansible...@googlegroups.com
tempalate can do this via includes, but you also have the assemble module.


--
----------
Brian Coca

Eric Marquez

unread,
Sep 13, 2016, 7:14:37 PM9/13/16
to ansible...@googlegroups.com

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

--
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 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/CACVha7esj9aHk7g6v8xDLzry%2BvWJxO3dvTxcRJ7%3DhdfCKbqZUA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Brian Coca

unread,
Sep 13, 2016, 7:45:41 PM9/13/16
to ansible...@googlegroups.com
here are the jinja docs about it:


 
----------
Brian Coca

Eric Marquez

unread,
Sep 15, 2016, 3:55:29 PM9/15/16
to ansible...@googlegroups.com

Assemble worked, thanks for the help.

 

From: ansible...@googlegroups.com [mailto:ansible...@googlegroups.com] On Behalf Of Brian Coca
Sent: Tuesday, September 13, 2016 4:45 PM
To: ansible...@googlegroups.com
Subject: Re: [ansible-project] Ansible merge multiple files.

 

here are the jinja docs about it:

--

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 post to this group, send email to ansible...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages