task with delegate_to fails ansible_remote_tmp is set

21 views
Skip to first unread message

asi...@net-sense.com

unread,
Dec 19, 2018, 5:42:43 PM12/19/18
to Ansible Project
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

Jordan Borean

unread,
Dec 19, 2018, 11:01:23 PM12/19/18
to Ansible Project
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

asi...@net-sense.com

unread,
Dec 21, 2018, 4:43:31 PM12/21/18
to Ansible Project
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}
Reply all
Reply to author
Forward
0 new messages