# how to use lineinfile to add block of \<Location /test\> .... \</Location\>

**URL:** <https://forum.ansible.com/t/how-to-use-lineinfile-to-add-block-of-location-test-location/19035>\
**Category:** Ansible Project\
**Created:** [August 17, 2015, 10:45am UTC](https://forum.ansible.com/t/how-to-use-lineinfile-to-add-block-of-location-test-location/19035 "2015-08-17T10:45:13Z")\
**Posts on this page:** 1\
**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 17, 2015, 10:45am UTC](https://forum.ansible.com/t/how-to-use-lineinfile-to-add-block-of-location-test-location/19035/1 "2015-08-17T10:45:13Z")

</div>

Hi,

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.

- j
