# lineinfile block missing last line

**URL:** <https://forum.ansible.com/t/lineinfile-block-missing-last-line/19053>\
**Category:** Ansible Developer\
**Created:** [August 19, 2015, 11:44am UTC](https://forum.ansible.com/t/lineinfile-block-missing-last-line/19053 "2015-08-19T11:44:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hce](https://avatars.discourse-cdn.com/v4/letter/h/c0e974/32.png) [@hce](https://forum.ansible.com/u/hce)\
**Post date:** [August 19, 2015, 11:44am UTC](https://forum.ansible.com/t/lineinfile-block-missing-last-line/19053/1 "2015-08-19T11:44:31Z")

</div>

Hi,

Sorry for duplicating post here, I did not get any response from ansible-project.

I tried to insert flowing block, but the last was never inserted because that line has already existed for other block in the config file. How can I make it work?

- name: “add test block”  
lineinfile: insertafter=“{{ item.after }}” line=“{{ item.line }}” dest=/etc/apache2/sites-available/default-ssl.conf state=present  
with\_items:
- { after: ‘EOF’, line: ‘\<Location /test\>’ }
- { after: ‘^\<Location /test\>’, line: ‘ProxyPass ajp://localhost:9000/api’ }
- { after: ‘^ProxyPass ajp://localhost:9000/api’, line: ‘’ }  
sudo: true

Thank you.

- hce

---

<div class="post-metadata">

**Author:** ![Takeshi\_Yaegashi](https://avatars.discourse-cdn.com/v4/letter/t/838e76/32.png) [@Takeshi\_Yaegashi](https://forum.ansible.com/u/Takeshi_Yaegashi)\
**Post date:** [September 4, 2015, 5:01pm UTC](https://forum.ansible.com/t/lineinfile-block-missing-last-line/19053/2 "2015-09-04T17:01:50Z")

</div>

Hi,

Consider using blockinfile module, which is exactly designed for such tasks.[https://github.com/yaegashi/ansible-role-blockinfile](https://github.com/yaegashi/ansible-role-blockinfile)

The module is available via blockinfile role in Ansible Galaxy so you can easily import it into your playbook.

[https://galaxy.ansible.com/list#/roles/1475](https://galaxy.ansible.com/list#/roles/1475)

`
