FreeKB - Resolve "Destination not writable"
Ansible - Resolve "Destination not writable"

Destination not writable is returned when using the copy module and the user does not have write permission to the target directory. In this example, the user does not have write permission to the /var directory.

PLAY [all]

TASKS [mkdir /opt/foo]
fatal: [server1.example.com]: FAILED! => {"changed": false, "checksum": "34949034fz73467b77cdc923aa747b", "msg": "Destination /var not writable"}

PLAY RECAP
server1.example.com   : ok=0  changed=0  unreachable=0  failed=1

 

Let's say you are attempting to copy /tmp/foo.txt to the /var directory on the target server as john.doe.

---
- hosts: all
  tasks:
    - name: copy foo.txt
      copy:
        src: /tmp/foo.txt
        dest: /var/foo.txt
        owner: foo
        group: foo
        mode: '0644'

 

This could be done by setting john.doe as the ansible_user in the /etc/ansible/hosts file, like this.

ansible_user=john.doe

 

Or by setting remote_user: john.doe in the playbook, like this.

---
- hosts: all
  remote_user: john.doe
  tasks:
    - name: copy foo.txt
      copy:
        src: /tmp/foo.txt
        dest: /var/foo.txt
        owner: foo
        group: foo
        mode: '0644'

 

Let's also say that only root has write access to the /var directory on the target server, like this. This will return Destination /var not writable.

drwxr-xr-x 1 root root 4096 Sep 18 13:49

 

This can be resolved by placing become_user: root and become: yes in the task, like this. Refer to our sudo become article for more details on this.

---
- hosts: all
  remote_user: john.doe
  tasks:
    - name: copy foo.txt
      become: yes
      become_user: root
      copy:
        src: /tmp/foo.txt
        dest: /var/foo.txt
        owner: root
        group: root
        mode: '0644'

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter a16a3 in the box below so that we can be sure you are a human.




Comments