# Problems with permissions accesing files with sudo

**URL:** <https://forum.ansible.com/t/problems-with-permissions-accesing-files-with-sudo/15581>\
**Category:** Ansible Project\
**Created:** [July 1, 2014, 7:21am UTC](https://forum.ansible.com/t/problems-with-permissions-accesing-files-with-sudo/15581 "2014-07-01T07:21:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![micafer](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@micafer](https://forum.ansible.com/u/micafer)\
**Post date:** [July 1, 2014, 7:21am UTC](https://forum.ansible.com/t/problems-with-permissions-accesing-files-with-sudo/15581/1 "2014-07-01T07:21:59Z")

</div>

Hi,

I’m having problems with permissions accessing files.  
I have this simple test playbook:

- hosts: all  
sudo: true  
tasks:
- copy: src=/tmp/root.txt dest=/tmp/pr.txt

The file “/tmp/root.txt” is owned by the root user with permissions 600.

If I’m using “sudo”, why the playbook cannot access the file?

---

<div class="post-metadata">

**Author:** ![micafer](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@micafer](https://forum.ansible.com/u/micafer)\
**Post date:** [July 1, 2014, 7:41am UTC](https://forum.ansible.com/t/problems-with-permissions-accesing-files-with-sudo/15581/2 "2014-07-01T07:41:00Z")

</div>

Now I have seen an issue in the Ansible github with the same problem:

[https://github.com/ansible/ansible/issues/6948](https://github.com/ansible/ansible/issues/6948)

It provides a patch to solve the error, but it only changes the error message.  
The original error was:

TASK: [copy src=/tmp/root.txt dest=/tmp/pr.txt] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [158.42.104.90] =\> Traceback (most recent call last):  
File “/usr/lib/pymodules/python2.7/ansible/runner/ **init**.py”, line 532, in \_executor  
exec\_rc = self.\_executor\_internal(host, new\_stdin)  
File “/usr/lib/pymodules/python2.7/ansible/runner/ **init**.py”, line 629, in \_executor\_internal  
return self.\_executor\_internal\_inner(host, self.module\_name, self.module\_args, inject, port, complex\_args=complex\_args)  
File “/usr/lib/pymodules/python2.7/ansible/runner/ **init**.py”, line 815, in \_executor\_internal\_inner  
result = handler.run(conn, tmp, module\_name, module\_args, inject, complex\_args)  
File “/usr/lib/pymodules/python2.7/ansible/runner/action\_plugins/copy.py”, line 158, in run  
local\_md5 = utils.md5(source\_full)  
File “/usr/lib/pymodules/python2.7/ansible/utils/ **init**.py”, line 570, in md5  
infile = open(filename, ‘rb’)  
IOError: [Errno 13] Permission denied: u’/tmp/root.txt’

The error with the patch provided in the issues is:

TASK: [copy src=/tmp/root.txt dest=/tmp/pr.txt] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [158.42.104.90] =\> error while accessing the file /tmp/root.txt, error was: [Errno 13] Permission denied: u’/tmp/root.txt’

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 1, 2014, 6:53pm UTC](https://forum.ansible.com/t/problems-with-permissions-accesing-files-with-sudo/15581/3 "2014-07-01T18:53:06Z")

</div>

This traceback is because the local ansible can’t access the file, though we do consider tracebacks in Ansible to be bugs - in this case this is a closed ticket.

If you are seeing problems in the most recent release where you are getting a traceback, please do make sure there is a bug filed - however if Ansible can’t read /tmp/root.txt above and is dying with a friendly error mesage about permissions, this is a sign it needs to read them locally and would not be a bug.

So it depends if you are getting a traceback or a nice error message, basically.

---

<div class="post-metadata">

**Author:** ![micafer](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@micafer](https://forum.ansible.com/u/micafer)\
**Post date:** [July 2, 2014, 7:33am UTC](https://forum.ansible.com/t/problems-with-permissions-accesing-files-with-sudo/15581/4 "2014-07-02T07:33:55Z")

</div>

My question is how can I copy a file from the Ansible node to the configured nodes when the file is only accessible by the root user.  
Using the copy module directly does not work, so now I have to make some tricky tasks like that:

- hosts: all  
sudo: true  
tasks:
- local\_action: shell cp /tmp/root.txt /tmp/root.txt,copy creates=/tmp/root.txt.copy
- local\_action: file path=/tmp/root.txt.copy mode=0644
- copy: src=/tmp/root.txt.copy dest=/tmp/pr.txt

Is there any other way to do it?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 2, 2014, 10:14pm UTC](https://forum.ansible.com/t/problems-with-permissions-accesing-files-with-sudo/15581/5 "2014-07-02T22:14:28Z")

</div>

sudo: true in ansible affects the remote (managed) nodes.

The user running ansible will need to be able to access the files on the local end, so sudo ansible itself in that case if you need to read /tmp/root.txt and can’t as you.
