# unable to delete line  file

**URL:** <https://forum.ansible.com/t/unable-to-delete-line-file/29867>\
**Category:** Ansible Project\
**Created:** [March 12, 2019, 7:00pm UTC](https://forum.ansible.com/t/unable-to-delete-line-file/29867 "2019-03-12T19:00:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deepak\_Sharma](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@Deepak\_Sharma](https://forum.ansible.com/u/Deepak_Sharma)\
**Post date:** [March 12, 2019, 7:00pm UTC](https://forum.ansible.com/t/unable-to-delete-line-file/29867/1 "2019-03-12T19:00:08Z")

</div>

this is my host file.

# cat /tmp/node/test.new

[masters]  
[1234.abc.com](http://1234.abc.com)  
[nodes]  
[453.abc.com](http://453.abc.com) openshift\_node\_labels,22,=“{‘region’: ‘us\_midwest’, ‘datacenter’: ‘ctc’, ‘zone’: ‘core’, ‘environment’: ‘nonprod’, ‘logging-infra-fluentd’: ‘true’}”  
[678abc.com](http://678abc.com) openshift\_node\_labels,22,=“{‘region’: ‘us\_midwest’, ‘datacenter’: ‘ctc’, ‘zone’: ‘core’, ‘environment’: ‘nonprod’, ‘logging-infra-fluentd’: ‘true’}”

---

<div class="post-metadata">

**Author:** ![Deepak\_Sharma](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@Deepak\_Sharma](https://forum.ansible.com/u/Deepak_Sharma)\
**Post date:** [March 12, 2019, 9:19pm UTC](https://forum.ansible.com/t/unable-to-delete-line-file/29867/2 "2019-03-12T21:19:03Z")

</div>

can someone help me…??

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [March 12, 2019, 9:19pm UTC](https://forum.ansible.com/t/unable-to-delete-line-file/29867/3 "2019-03-12T21:19:56Z")

</div>

Provide error log

---

<div class="post-metadata">

**Author:** ![Sebastian\_Meyer](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@Sebastian\_Meyer](https://forum.ansible.com/u/Sebastian_Meyer)\
**Post date:** [March 12, 2019, 10:02pm UTC](https://forum.ansible.com/t/unable-to-delete-line-file/29867/4 "2019-03-12T22:02:44Z")

</div>

'^{{ ansible\_hostname }}$' matches a line containing only the name of  
the node currently running the task.

If you want to delete a line starting with the name of the node you'll  
need '^{{ ansible\_hostname }}', without the $ which means line end.

If you are getting an error, providing the error message would help ...

Regards

---

<div class="post-metadata">

**Author:** ![Deepak\_Sharma](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@Deepak\_Sharma](https://forum.ansible.com/u/Deepak_Sharma)\
**Post date:** [March 14, 2019, 8:01am UTC](https://forum.ansible.com/t/unable-to-delete-line-file/29867/5 "2019-03-14T08:01:02Z")

</div>

it is working now,

with below syntax.

lineinfile: dest=/tmp/node/test.new  
regexp=‘^{{ansible\_hostname}}’  
state=absent  
delegate\_to: “{{ groups[‘masters’][0] }}”  
changed\_when: False
