# how to use insertbefore/after correctly?

**URL:** <https://forum.ansible.com/t/how-to-use-insertbefore-after-correctly/21555>\
**Category:** Ansible Project\
**Created:** [May 24, 2016, 6:55pm UTC](https://forum.ansible.com/t/how-to-use-insertbefore-after-correctly/21555 "2016-05-24T18:55:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaron.trujillo](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@aaron.trujillo](https://forum.ansible.com/u/aaron.trujillo)\
**Post date:** [May 24, 2016, 6:55pm UTC](https://forum.ansible.com/t/how-to-use-insertbefore-after-correctly/21555/1 "2016-05-24T18:55:45Z")

</div>

lineinfile: dest=/etc/rsyslog.conf insertafter=“\*.\*;auth,authpriv.none” regexp=“\*.\*;auth,authpriv.none” line=“Listen 8080”

The only thing that happens here is Listen 8080 replaces the _._;auth,authpriv.none line. should it not be placing it after it???

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [May 25, 2016, 2:55pm UTC](https://forum.ansible.com/t/how-to-use-insertbefore-after-correctly/21555/2 "2016-05-25T14:55:31Z")

</div>

I think you don't need the regexp, or rather the regexp should match  
the line you are \*inserting\*. To let ansible know, if the line is  
already in there.

Right now you are telling ansible to replace the line  
...auth,authpriv... and insert the line after the line ...auth,authpriv...

Johannes
