---
- hosts: local
tasks:
- name: Line In File
lineinfile:
dest: /home/ansible/test.txt
regexp: '%reen%'
line: '%jabba%'
register: foundstuff
- debug: var=foundstuff
% is not a valid regexp special character so you literally searching for a line containing %reen% and replace that line with %jabba%.
But since %reen% is not in file it will add %jabba% to the bottom.
To make it work you need to do this
- name: Line In File
lineinfile:
dest: /home/ansible/test.txt
backrefs: yes
regexp: '(.*)reen(.*)'
line: '\1jabba\2'