# Copy module not working with sudo or su

**URL:** <https://forum.ansible.com/t/copy-module-not-working-with-sudo-or-su/15632>\
**Category:** Ansible Project\
**Created:** [July 9, 2014, 2:24pm UTC](https://forum.ansible.com/t/copy-module-not-working-with-sudo-or-su/15632 "2014-07-09T14:24:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alberto\_Losada\_Grand](https://avatars.discourse-cdn.com/v4/letter/a/e19adc/32.png) [@Alberto\_Losada\_Grand](https://forum.ansible.com/u/Alberto_Losada_Grand)\
**Post date:** [July 9, 2014, 2:24pm UTC](https://forum.ansible.com/t/copy-module-not-working-with-sudo-or-su/15632/1 "2014-07-09T14:24:15Z")

</div>

Hi all,

I can’t find why my code is not working when running copy with another user than root. It works fine with root and also other modules like template or yum are working fine with “no root” permissions…

I tried with sudo and then move to su with no luck… thanks in advance!

Error:

failed: [vofe4] =\> {“failed”: true, “item”: “”, “md5sum”: “99d5c87b8ae2f7cd88ed1afb47959943”, “parsed”: false}  
invalid output was:  
SUDO-SUCCESS-sfilimasfllysodrjbihhgpdiaurkvyn  
Traceback (most recent call last):  
File “/home/alosada/.ansible/tmp/ansible-tmp-1404915322.93-16253228171966/copy”, line 1386, in   
main()  
File “/home/alosada/.ansible/tmp/ansible-tmp-1404915322.93-16253228171966/copy”, line 213, in main  
module.atomic\_move(src, dest)  
File “/home/alosada/.ansible/tmp/ansible-tmp-1404915322.93-16253228171966/copy”, line 1237, in atomic\_move  
os.chown(tmp\_dest.name, st.st\_uid, st.st\_gid)  
UnboundLocalError: local variable ‘st’ referenced before assignment

FATAL: all hosts have already failed – aborting

My code:

ansible-playbook -i production -l webservers ossec-client.yml -k -S -R root --ask-su-pass --tags ossec\_rpm -v

# file: ossec-client.yml

- hosts: all  
su: yes  
su\_user: root  
roles:
- ossec-client

# file: roles/ossec-client/tasks/main.yml

#COPY MOD\_JK

- name: Creates a writeable repository  
file: path=/usr/local/src/ossec state=directory owner=alosada group=alosada  
tags: ossec\_rpm

- name: Copy ossec-hids-2.8-45.el6.art.x86\_64.rpm compiled for Linux 64bits  
copy: src=ossec-hids-2.8-45.el6.art.x86\_64.rpm dest=/usr/local/src/ossec/ossec-hids-2.8-45.el6.art.x86\_64.rpm  
tags: ossec\_rpm

Version: ansible 1.6 (devel bb723bedee) last updated 2014/03/24 16:53:13 (GMT +200)

---

<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 9, 2014, 7:51pm UTC](https://forum.ansible.com/t/copy-module-not-working-with-sudo-or-su/15632/2 "2014-07-09T19:51:21Z")

</div>

Update first to the latest Ansible.

If you can produce this error with 1.6.5, please file a bug in GitHub, as tracebacks are errors and need to be handled.
