# 10 lines in file

**URL:** <https://forum.ansible.com/t/10-lines-in-file/15495>\
**Category:** Ansible Project\
**Created:** [June 18, 2014, 8:14pm UTC](https://forum.ansible.com/t/10-lines-in-file/15495 "2014-06-18T20:14:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Baydoun](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@Michael\_Baydoun](https://forum.ansible.com/u/Michael_Baydoun)\
**Post date:** [June 18, 2014, 8:14pm UTC](https://forum.ansible.com/t/10-lines-in-file/15495/1 "2014-06-18T20:14:44Z")

</div>

I need to add 10 lines to the middle of a file where the rest of the file is dynamic. Since it’s dynamic I need to use something like lineinfile. I’d rather not invoke lineinfile 10 times as that seems messy.

Suggestions?

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [June 19, 2014, 5:35am UTC](https://forum.ansible.com/t/10-lines-in-file/15495/2 "2014-06-19T05:35:32Z")

</div>

Why not use a template, or the assemble module? Both of those would seem to be a better fit.

---

<div class="post-metadata">

**Author:** ![Michael\_Schultz](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Michael\_Schultz](https://forum.ansible.com/u/Michael_Schultz)\
**Post date:** [June 19, 2014, 11:41am UTC](https://forum.ansible.com/t/10-lines-in-file/15495/3 "2014-06-19T11:41:37Z")

</div>

Depending on the file, sometimes they support an include statement (e.g., sudoers, apparmor, mysql, apache, …) that you could assert lineinfile for then use template or file on the include file as appropriate.

–michael

---

<div class="post-metadata">

**Author:** ![Michael\_Baydoun](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@Michael\_Baydoun](https://forum.ansible.com/u/Michael_Baydoun)\
**Post date:** [June 19, 2014, 2:19pm UTC](https://forum.ansible.com/t/10-lines-in-file/15495/4 "2014-06-19T14:19:32Z")

</div>

Because an application is making changes to other parts of the file, and those changes need to be maintained. I can’t overwrite what the application is doing.

---

<div class="post-metadata">

**Author:** ![Michael\_Baydoun](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@Michael\_Baydoun](https://forum.ansible.com/u/Michael_Baydoun)\
**Post date:** [June 19, 2014, 2:21pm UTC](https://forum.ansible.com/t/10-lines-in-file/15495/5 "2014-06-19T14:21:18Z")

</div>

unfortunately, it’s not that kind of file. It’s a xml file for Oracle BI

---

<div class="post-metadata">

**Author:** ![Michael\_Baydoun](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@Michael\_Baydoun](https://forum.ansible.com/u/Michael_Baydoun)\
**Post date:** [June 19, 2014, 2:22pm UTC](https://forum.ansible.com/t/10-lines-in-file/15495/6 "2014-06-19T14:22:55Z")

</div>

on second thought, maybe I can do something like this in xml. I’ll take a look into that.
