# issue with line insert lininfile

**URL:** <https://forum.ansible.com/t/issue-with-line-insert-lininfile/36872>\
**Category:** Ansible Project\
**Created:** [July 19, 2022, 5:39pm UTC](https://forum.ansible.com/t/issue-with-line-insert-lininfile/36872 "2022-07-19T17:39:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [July 19, 2022, 5:39pm UTC](https://forum.ansible.com/t/issue-with-line-insert-lininfile/36872/1 "2022-07-19T17:39:40Z")

</div>

I keep getting errors when running an insert line task

the task to insert is

- name: add line  
lineinfile:  
backup: no  
backrefs: yes  
state: present  
path: “{{ file\_path }}”  
regexp: ‘^(\s\*)[#]?{{ item.search }}(: )\*’  
line: ‘\1{{ item.search }}\2\n\1{{ item.add }}’  
with\_items:
- { search: “{{ line.replace\_with }}”, add: “{{ line.line\_to\_add }}” }

---

<div class="post-metadata">

**Author:** ![atul\_mohan](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@atul\_mohan](https://forum.ansible.com/u/atul_mohan)\
**Post date:** [August 28, 2023, 2:49pm UTC](https://forum.ansible.com/t/issue-with-line-insert-lininfile/36872/2 "2023-08-28T14:49:21Z")

</div>

- name: add line  
lineinfile:  
backup: no  
state: present  
path: “{{ file\_path }}”  
regexp: ‘^(\s\*)[#]?{{ item.search.replace(“/”, “\/”) }}(: )\*’  
line: ‘\1{{ item.search }}\2\n\1{{ item.add }}’  
with\_items:
- { search: “{{ line.replace\_with }}”, add: “{{ line.line\_to\_add }}” }
