# lineinfile: backrefs and jinja2 variables

**URL:** <https://forum.ansible.com/t/lineinfile-backrefs-and-jinja2-variables/15373>\
**Category:** Ansible Project\
**Created:** [May 30, 2014, 8:58am UTC](https://forum.ansible.com/t/lineinfile-backrefs-and-jinja2-variables/15373 "2014-05-30T08:58:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregor\_Giesen](https://avatars.discourse-cdn.com/v4/letter/g/47e85d/32.png) [@Gregor\_Giesen](https://forum.ansible.com/u/Gregor_Giesen)\
**Post date:** [May 30, 2014, 8:58am UTC](https://forum.ansible.com/t/lineinfile-backrefs-and-jinja2-variables/15373/1 "2014-05-30T08:58:53Z")

</div>

Hi everybody,

when I try the following in a playbook (ansible 1.6.2):

- lineinfile:  
dest: /etc/nagios/nrpe.cfg  
backrefs: yes  
regexp: ‘^(allowed\_hosts=).\*$’  
line: ‘\1{{ monitoring\_server }}’

where “monitoring\_server=10.0.0.5”, it replaces the line “allowed\_hosts=127.0.0.1” with “H.0.0.5”.  
If I put any character between “\1” and “{{”, it seems to be working correctly, but I don’t want an additional character there.

Thanks and best regards,  
Gregor

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 31, 2014, 4:21pm UTC](https://forum.ansible.com/t/lineinfile-backrefs-and-jinja2-variables/15373/2 "2014-05-31T16:21:01Z")

</div>

lineinfile can be tricky and most times I’d discourage usage of it in favor of the template module.

However, in this case, this feels like a bug report to me. Please be sure to file one on github.

---

<div class="post-metadata">

**Author:** ![Gregor\_Giesen](https://avatars.discourse-cdn.com/v4/letter/g/47e85d/32.png) [@Gregor\_Giesen](https://forum.ansible.com/u/Gregor_Giesen)\
**Post date:** [May 31, 2014, 8:40pm UTC](https://forum.ansible.com/t/lineinfile-backrefs-and-jinja2-variables/15373/3 "2014-05-31T20:40:02Z")

</div>

> However, in this case, this feels like a bug report to me. Please be sure to file one on github.

Done.  
[https://github.com/ansible/ansible/issues/7615](https://github.com/ansible/ansible/issues/7615)
