3

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.

1 Answer 1

2

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.

1
  • Man, if I wanted to read Python code...XD. Thanks! That makes a lot more sense now, and atomic file copy seems like a "right" thing to do. Sep 2, 2015 at 19:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .