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

38 views
Skip to first unread message

Joanna Delaporte

unread,
Jul 20, 2016, 12:11:12 PM7/20/16
to Ansible Project
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"}



Kai Stian Olstad

unread,
Jul 20, 2016, 1:00:31 PM7/20/16
to ansible...@googlegroups.com
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.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages