# lineinfile fails with a path only containing a file name

**URL:** <https://forum.ansible.com/t/lineinfile-fails-with-a-path-only-containing-a-file-name/13457>\
**Category:** Ansible Project\
**Created:** [September 11, 2013, 9:15pm UTC](https://forum.ansible.com/t/lineinfile-fails-with-a-path-only-containing-a-file-name/13457 "2013-09-11T21:15:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierre\_Thibault](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@Pierre\_Thibault](https://forum.ansible.com/u/Pierre_Thibault)\
**Post date:** [September 11, 2013, 9:15pm UTC](https://forum.ansible.com/t/lineinfile-fails-with-a-path-only-containing-a-file-name/13457/1 "2013-09-11T21:15:57Z")

</div>

Hello,

It seems that I found a bug with the lineinfile module:

- name: lineinfile fails with a path only containing a file name  
lineinfile: dest=afile regexp=“something” line=“something”

It fails with an error like:

failed: [iterativeocean.biz] =\> {“failed”: true, “item”: “”, “parsed”: false}  
invalid output was: Traceback (most recent call last):  
File “/home/pierre/.ansible/tmp/ansible-1378933589.79-184488600904880/lineinfile”, line 1255, in   
main()  
File “/home/pierre/.ansible/tmp/ansible-1378933589.79-184488600904880/lineinfile”, line 319, in main  
ins\_aft, ins\_bef, create, backup, backrefs)  
File “/home/pierre/.ansible/tmp/ansible-1378933589.79-184488600904880/lineinfile”, line 163, in present  
os.makedirs(destpath)  
File “/usr/lib/python2.7/os.py”, line 157, in makedirs  
mkdir(name, mode)  
OSError: [Errno 2] No such file or directory: ‘’

So, in that case, the directory is empty.

---

<div class="post-metadata">

**Author:** ![Pierre\_Thibault](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@Pierre\_Thibault](https://forum.ansible.com/u/Pierre_Thibault)\
**Post date:** [September 11, 2013, 9:18pm UTC](https://forum.ansible.com/t/lineinfile-fails-with-a-path-only-containing-a-file-name/13457/2 "2013-09-11T21:18:18Z")

</div>

I am on version 1.3 from fresh branch devel.

---

<div class="post-metadata">

**Author:** ![Pierre\_Thibault](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@Pierre\_Thibault](https://forum.ansible.com/u/Pierre_Thibault)\
**Post date:** [September 11, 2013, 9:36pm UTC](https://forum.ansible.com/t/lineinfile-fails-with-a-path-only-containing-a-file-name/13457/3 "2013-09-11T21:36:05Z")

</div>

I am having a hard time with lineinfile. It seems that the module is completely broken. Could it be?

I wait for an answer before giving more information.

Thank you.

---

<div class="post-metadata">

**Author:** ![kahlil.hodgson](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@kahlil.hodgson](https://forum.ansible.com/u/kahlil.hodgson)\
**Post date:** [September 11, 2013, 10:17pm UTC](https://forum.ansible.com/t/lineinfile-fails-with-a-path-only-containing-a-file-name/13457/4 "2013-09-11T22:17:59Z")

</div>

Module work fine for me and many others. You probably want to use an  
absolute filename for dest, all the examples do. Checkout the command:

&nbsp;&nbsp;&nbsp;&nbsp;ansible-doc lineinfile

K

Kahlil (Kal) Hodgson GPG: C9A02289  
Head of Technology (m) +61 (0) 4 2573 0382  
DealMax Pty Ltd (w) +61 (0) 3 9008 5281

Suite 1415  
401 Docklands Drive  
Docklands VIC 3008 Australia

"All parts should go together without forcing. You must remember that  
the parts you are reassembling were disassembled by you. Therefore,  
if you can't get them together again, there must be a reason. By all  
means, do not use a hammer." -- IBM maintenance manual, 1925
