Ansible lineinfile and Permissions of Parent Directory

ansiblefile-permissions

I'm using lineinfile to update a configuration file. The file exists and the ansible_ssh_user owns it and has write permission, but the containing directory is owned by root. When my task runs I the error:

The destination directory (/parent/directory/name) is not writable by the current user.

I can edit the file by hand using vim, and my lineinfile task includes create=no, so I don't understand why Ansible needs write permission to the parent directory. Is there something I'm missing? Is there a way to allow ansible to write the to the file without granting permissions to the directory it's in?

PS – I really don't want to use become or sudo with this playbook; it's intended to a simple playbook without having to type in a password.

Best Answer

Use the source, Luke! :)

If you look at the source for the lineinfile module, you can see that it writes changes to a temp file and then does an atomic file copy to the target filename, overwriting the old version of the file.

The user you're running ansible as will need write permissions on the parent directory.