# lineinfile module

**URL:** <https://forum.ansible.com/t/lineinfile-module/12290>\
**Category:** Ansible Project\
**Created:** [February 4, 2013, 7:34pm UTC](https://forum.ansible.com/t/lineinfile-module/12290 "2013-02-04T19:34:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [February 4, 2013, 7:34pm UTC](https://forum.ansible.com/t/lineinfile-module/12290/1 "2013-02-04T19:34:08Z")

</div>

How difficult would it be to add an "insertafter\_regex" in the lineinfile module?

Reasoning:  
For system files, I often much prefer use something like lineifile rather than template, so that I benefit of the changes brought by new versions when deploying to newer system. Unfortunately, often, \*where\* I insert a file makes a big difference, and it cannot always be at the beginning or at the end, often, it has to be somewhere precise in the middle. One good example is server.xml for tomcat. I only need to change very few lines somewhere in the middle, but I don't want to template the whole file, because from one version to the next, they add useful modifications.

---

<div class="post-metadata">

**Author:** ![Daniel\_Hokka\_Zakriss](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@Daniel\_Hokka\_Zakriss](https://forum.ansible.com/u/Daniel_Hokka_Zakriss)\
**Post date:** [February 4, 2013, 7:36pm UTC](https://forum.ansible.com/t/lineinfile-module/12290/2 "2013-02-04T19:36:37Z")

</div>

Yves Dorfsman wrote:

> How difficult would it be to add an "insertafter\_regex" in the lineinfile  
> module?

That is what insertafter= is. So it was so easy, I went back in time and  
did it when the lineinfile module was added!

Daniel

---

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [February 4, 2013, 7:59pm UTC](https://forum.ansible.com/t/lineinfile-module/12290/3 "2013-02-04T19:59:17Z")

</div>

Ah.The docs says:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Choices:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;• BOF  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;• EOF

But I do see now that it mentions regular expression in the comments. We should add "regex" to the choices...

---

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [February 4, 2013, 8:07pm UTC](https://forum.ansible.com/t/lineinfile-module/12290/4 "2013-02-04T20:07:37Z")

</div>

Another request...

insertbefore would be a great addition!
