# blockinfile state:absent is not working, I'm trying to remove mulitple lines but not working

**URL:** <https://forum.ansible.com/t/blockinfile-state-absent-is-not-working-im-trying-to-remove-mulitple-lines-but-not-working/29690>\
**Category:** Ansible Project\
**Created:** [February 15, 2019, 12:25pm UTC](https://forum.ansible.com/t/blockinfile-state-absent-is-not-working-im-trying-to-remove-mulitple-lines-but-not-working/29690 "2019-02-15T12:25:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deepan\_M](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Deepan\_M](https://forum.ansible.com/u/Deepan_M)\
**Post date:** [February 15, 2019, 12:25pm UTC](https://forum.ansible.com/t/blockinfile-state-absent-is-not-working-im-trying-to-remove-mulitple-lines-but-not-working/29690/1 "2019-02-15T12:25:47Z")

</div>

please someone help me to get answer for my query!

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [February 15, 2019, 12:45pm UTC](https://forum.ansible.com/t/blockinfile-state-absent-is-not-working-im-trying-to-remove-mulitple-lines-but-not-working/29690/2 "2019-02-15T12:45:04Z")

</div>

> please someone help me to get answer for my query!
> 
> ---  
> - hosts: testuser  
> &nbsp;&nbsp;become: yes  
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;- name: removelines  
> &nbsp;&nbsp;&nbsp;&nbsp;blockinfile:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;block: |
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;################ request ###################  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;User\_Alias S3\_OPS=pams3fedqaadmin  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;S3\_OPS ALL=(ALL) ALL  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;####################################################"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: /tmp/test  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: absent  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;backup: yes

You'll need to move your markers from block to marker\_begin and marker\_end

V/r,  
James Cassell

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [February 15, 2019, 12:55pm UTC](https://forum.ansible.com/t/blockinfile-state-absent-is-not-working-im-trying-to-remove-mulitple-lines-but-not-working/29690/3 "2019-02-15T12:55:17Z")

</div>

> \>  
> \> please someone help me to get answer for my query!  
> \>  
> \> ---  
> \> - hosts: testuser  
> \> become: yes  
> \> tasks:  
> \> - name: removelines  
> \> blockinfile:  
> \> block: |  
> \>  
> \> ################ request ###################  
> \> User\_Alias S3\_OPS=pams3fedqaadmin  
> \> S3\_OPS ALL=(ALL) ALL  
> \> ####################################################"  
> \> path: /tmp/test  
> \> state: absent  
> \> backup: yes  
> \>
> 
> You'll need to move your markers from block to marker\_begin and marker\_end

You'll also need to set marker.

---

<div class="post-metadata">

**Author:** ![Deepan\_M](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Deepan\_M](https://forum.ansible.com/u/Deepan_M)\
**Post date:** [February 15, 2019, 1:35pm UTC](https://forum.ansible.com/t/blockinfile-state-absent-is-not-working-im-trying-to-remove-mulitple-lines-but-not-working/29690/4 "2019-02-15T13:35:42Z")

</div>

Hi James,

Still same problem! Can you please see below entries and correct me if anything wrong in that?

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [February 15, 2019, 1:47pm UTC](https://forum.ansible.com/t/blockinfile-state-absent-is-not-working-im-trying-to-remove-mulitple-lines-but-not-working/29690/5 "2019-02-15T13:47:11Z")

</div>

> Hi James,
> 
> Still same problem! Can you please see below entries and correct me if  
> anything wrong in that?
> 
> ---  
> - hosts: xerox  
> &nbsp;&nbsp;become: yes  
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;- name: removelines  
> &nbsp;&nbsp;&nbsp;&nbsp;blockinfile:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;marker\_begin: "################ REQ000000931296 ###################"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content: |  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;User\_Alias S3\_OPS=pams3fedqaadmin  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;S3\_OPS ALL=(ALL) ALL  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;marker\_end: "####################################################"

Also set marker: "{mark}"

---

<div class="post-metadata">

**Author:** ![Deepan\_M](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Deepan\_M](https://forum.ansible.com/u/Deepan_M)\
**Post date:** [February 15, 2019, 1:59pm UTC](https://forum.ansible.com/t/blockinfile-state-absent-is-not-working-im-trying-to-remove-mulitple-lines-but-not-working/29690/6 "2019-02-15T13:59:36Z")

</div>

Hi James,

Thank you so much for your help, its working perfect.
