# lineinfile with backrefs and create: yes is failing with path does not exist

**URL:** <https://forum.ansible.com/t/lineinfile-with-backrefs-and-create-yes-is-failing-with-path-does-not-exist/22062>\
**Category:** Ansible Project\
**Created:** [July 20, 2016, 4:11pm UTC](https://forum.ansible.com/t/lineinfile-with-backrefs-and-create-yes-is-failing-with-path-does-not-exist/22062 "2016-07-20T16:11:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [July 20, 2016, 4:11pm UTC](https://forum.ansible.com/t/lineinfile-with-backrefs-and-create-yes-is-failing-with-path-does-not-exist/22062/1 "2016-07-20T16:11:12Z")

</div>

Is this expected behaviour? I am trying to change a line in a file if it is already present, or create the file if it isn’t:

`

- name: set ypserver to localhost  
lineinfile:  
dest: /etc/yp.conf  
create: yes  
state: present  
backup: yes  
backrefs: yes  
regexp: “^ypserver .\*”  
line: “ypserver 127.0.0.1”  
notify: restart ypservices  
`

But I keep getting this error:

`  
TASK [nismaster : set ypserver to localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [octans]: FAILED! =\> {“changed”: false, “failed”: true, “msg”: “path /etc/yp.conf does not exist”, “path”: “/etc/yp.conf”, “state”: “absent”}

`

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 20, 2016, 5:00pm UTC](https://forum.ansible.com/t/lineinfile-with-backrefs-and-create-yes-is-failing-with-path-does-not-exist/22062/2 "2016-07-20T17:00:19Z")

</div>

I guess it because of backrefs=yes.  
The documentation says this about backrefs,  
"... and if the `regexp' doesn't match anywhere in the file, the file will be left unchanged."

So if the file doesn't exist regexp will not match and it will not do anything.

Since you are not using backrefs just remove the line since the default is no.
