lineinfile: backrefs and jinja2 variables

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

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.

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