# \[file-permissions\] Getting permission denied with become: yes

**URL:** <https://forum.ansible.com/t/file-permissions-getting-permission-denied-with-become-yes/29410>\
**Category:** Ansible Project\
**Created:** [January 9, 2019, 6:47pm UTC](https://forum.ansible.com/t/file-permissions-getting-permission-denied-with-become-yes/29410 "2019-01-09T18:47:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ajay\_Tripathi](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@Ajay\_Tripathi](https://forum.ansible.com/u/Ajay_Tripathi)\
**Post date:** [January 9, 2019, 6:47pm UTC](https://forum.ansible.com/t/file-permissions-getting-permission-denied-with-become-yes/29410/1 "2019-01-09T18:47:05Z")

</div>

Hi,

I am getting `[Errno 13] Permission denied` with `become: yes` and a user that can access the desired file with sudo.  
The file access permission is 0600 (root:root) and `connection: local` is set.

Example:

Consider machine with 2 users;  
`root` & `bob`. `bob` has privilege access with sudo.

Consider playbook task:

```auto

- name: Copy file
become: yes
copy:
src: "/etc/fakepath/file"
dest: "/home/bob/fakepath/file"
owner: bob
group: bob
mode: 0644

```

Running this playbook:

```auto
ansible-playbook -vvv -i inventory.yml playbook.yml -u bob -K

```

Output:

```auto

TASK [local/system-backup : Copy file] **********************************************************************************************
task path: /home/bob/roles/fakerole/tasks/main.yml:22
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: bob
<localhost> EXEC /bin/sh -c 'echo ~bob && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/bob/.ansible/tmp/ansible-tmp-1547058060.7636507-83324408153016 `" && echo ansible-tmp-1547058060.7636507-83324408153016="` echo /home/bob/.ansible/tmp/ansible-tmp-1547058060.7636507-83324408153016 `" ) && sleep 0'
fatal: [localhost]: FAILED! => {
"msg": "an error occurred while trying to read the file '/etc/fakepath/file': [Errno 13] Permission denied: b'/etc/fakepath/file'"
}

```

Information:

- ansible\_connection: local

- ansible-playbook 2.7.5

- python version = 3.6.7

Any pointers to copy the file with chown (bob:bob) would be really helpful.

Thank You.

Best,  
Ajay Tripathi

---

<div class="post-metadata">

**Author:** ![Ajay\_Tripathi](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@Ajay\_Tripathi](https://forum.ansible.com/u/Ajay_Tripathi)\
**Post date:** [January 9, 2019, 6:57pm UTC](https://forum.ansible.com/t/file-permissions-getting-permission-denied-with-become-yes/29410/2 "2019-01-09T18:57:12Z")

</div>

**Update:**

I ran the playbook as user root (however, i do not want to do that in production):

```auto
ansible-playbook -vvv -i inventory.yml playbook.yml -u **root** -K

```

I am still getiing output:

```auto

TASK [local/system-backup : Copy file] **********************************************************************************************
task path: /home/bob/roles/fakerole/tasks/main.yml:22
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: bob
<localhost> EXEC /bin/sh -c 'echo ~bob && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/bob/.ansible/tmp/ansible-tmp-1547058060.7636507-83324408153016 `" && echo ansible-tmp-1547058060.7636507-83324408153016="` echo /home/bob/.ansible/tmp/ansible-tmp-1547058060.7636507-83324408153016 `" ) && sleep 0'
fatal: [localhost]: FAILED! => {
"msg": "an error occurred while trying to read the file '/etc/fakepath/file': [Errno 13] Permission denied: b'/etc/fakepath/file'"
}

```

Note: the user in the output is still `CONNECTION FOR USER: bob` although i ran the playbook with option `-u root`.  
My understanding seems flawed somewhere as i was expecting connection to be for root now.

Best,  
Ajay Tripathi
