diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index aee41669061..a4c03420dce 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -23,6 +23,8 @@ DEFAULT_HOST_LIST = os.environ.get('ANSIBLE_HOSTS', '/etc/ansible/hosts') DEFAULT_MODULE_PATH = os.environ.get('ANSIBLE_LIBRARY', '/usr/share/ansible') +DEFAULT_REMOTE_TMP = os.environ.get('ANSIBLE_REMOTE_TMP', + '/$HOME/.ansible/tmp') DEFAULT_MODULE_NAME = 'command' DEFAULT_PATTERN = '*' diff --git a/lib/ansible/runner.py b/lib/ansible/runner.py index bb9e5964fc8..730d8d7e419 100644 --- a/lib/ansible/runner.py +++ b/lib/ansible/runner.py @@ -247,13 +247,13 @@ class Runner(object): if self.remote_user == 'root': args = "%s metadata=/etc/ansible/setup" % args else: - args = "%s metadata=$HOME/.ansible/setup" % args + args = "%s metadata=%s/.ansible/setup" % (args, C.DEFAULT_REMOTE_TMP) else: if not 'metadata' in args: if self.remote_user == 'root': args['metadata'] = '/etc/ansible/setup' else: - args['metadata'] = "$HOME/.ansible/setup" + args['metadata'] = "%s/.ansible/setup" % C.DEFAULT_REMOTE_TMP return args # ***************************************************** @@ -667,13 +667,9 @@ class Runner(object): def _get_tmp_path(self, conn): ''' gets a temporary path on a remote box ''' - # The problem with this is that it's executed on the - # overlord, not on the target so we can't use tempdir and os.path - # Only support the *nix world for now by using the $HOME env var - - basetmp = "/var/tmp" - if self.remote_user != 'root': - basetmp = "$HOME/.ansible/tmp" + basetmp = C.DEFAULT_REMOTE_TMP + if self.remote_user == 'root': + basetmp ="/var/tmp" cmd = "mktemp -d %s/ansible.XXXXXX" % basetmp if self.remote_user != 'root': cmd = "mkdir -p %s && %s" % (basetmp, cmd)