# task with delegate\_to fails ansible\_remote\_tmp is set

**URL:** <https://forum.ansible.com/t/task-with-delegate-to-fails-ansible-remote-tmp-is-set/29307>\
**Category:** Ansible Project\
**Created:** [December 19, 2018, 10:42pm UTC](https://forum.ansible.com/t/task-with-delegate-to-fails-ansible-remote-tmp-is-set/29307 "2018-12-19T22:42:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![asilver](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@asilver](https://forum.ansible.com/u/asilver)\
**Post date:** [December 19, 2018, 10:42pm UTC](https://forum.ansible.com/t/task-with-delegate-to-fails-ansible-remote-tmp-is-set/29307/1 "2018-12-19T22:42:43Z")

</div>

Hello,  
I’m having a problem where a particular task is failing when I use delegate\_to. The problem is I’m also setting ansible\_remote\_tmp to a specific directory for the target systems. However, it appears that when I use delegate\_to: local, a local connection is setup and it wants to use the ansible\_remote\_tmp directory. However, that directory name does not exist on the local server. How to do I get around this??

Here is the snippet from the playbook where the playbook fails:

`

- name: Calculate md5sum from local file  
stat:  
path: “{{ src\_dir }}/{{ qcow\_file\_name }}”  
get\_checksum: yes  
checksum\_algorithm: md5  
register: file\_stats  
run\_once: true  
delegate\_to: localhost

- set\_fact: qcow\_md5sum=“{{ file\_stats.stat.checksum }}”  
`

Here is the failure:

` fatal: [ptr15-jdm]: UNREACHABLE! => { "changed": false, "msg": "Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: ( umask 77 && mkdir -p \"` echo /var/third-party/.ansible/tmp/ansible-tmp-1545258506.72-123539723643648 `\" && echo ansible-tmp-1545258506.72-123539723643648=\"` echo /var/third-party/.ansible/tmp/ansible-tmp-1545258506.72-123539723643648 `\" ), exited with result 1", "unreachable": true } `

Thanks  
Al

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [December 20, 2018, 4:01am UTC](https://forum.ansible.com/t/task-with-delegate-to-fails-ansible-remote-tmp-is-set/29307/2 "2018-12-20T04:01:23Z")

</div>

ansible\_remote\_tmp is a shell option so it isn’t affected by delegate\_to as you have seen it will use what was set before. To get around this you can set ansible\_remote\_tmp on the task itself to a temp dir that exists on the local host like so;

`

- name: Calculate md5sum from local file  
stat:  
path: “{{ src\_dir }}/{{ qcow\_file\_name }}”  
get\_checksum: yes  
checksum\_algorithm: md5  
register: file\_stats  
run\_once: True  
delegate\_to: localhost  
vars:  
ansible\_remote\_tmp: ~/.ansible/tmp

`

Thanks

Jordan

---

<div class="post-metadata">

**Author:** ![asilver](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@asilver](https://forum.ansible.com/u/asilver)\
**Post date:** [December 21, 2018, 9:43pm UTC](https://forum.ansible.com/t/task-with-delegate-to-fails-ansible-remote-tmp-is-set/29307/3 "2018-12-21T21:43:30Z")

</div>

Thank you Jordan. I did not know you could set ansible\_remote\_tmp at the task level. I will try that. As a work around before I saw your answer, I just build a filter to return the md5 as follows:

`

- name: Calculate md5sum from local file  
set\_fact: qcow\_md5sum=“{{ qcow\_filepath|getmd5sum() }}”  
run\_once: true  
`

`  
import subprocess

def getmd5sum (filename):

try:  
output = subprocess.check\_output([‘md5sum’,filename])  
except:  
print "Problem determining md5sum on file ", filename  
return 1

tmplist = output.split()  
md5sum = tmplist[0]

return md5sum

class FilterModule(object):  
def filters(self):  
return {‘getmd5sum’: getmd5sum}  
`
