ANSIBLE_REMOTE_TMP environment variable sets where ansible will stuf tmp files on remote host. Default is /var/tmp for root, and $HOME/.ansible/tmp for non-root
This commit is contained in:
parent
1864a480ba
commit
5917aba761
6 changed files with 19 additions and 9 deletions
|
@ -77,6 +77,7 @@ def main(args):
|
||||||
sudo=options.sudo,
|
sudo=options.sudo,
|
||||||
sudo_user=options.sudo_user,
|
sudo_user=options.sudo_user,
|
||||||
sudo_pass=sudopass,
|
sudo_pass=sudopass,
|
||||||
|
basetmp=C.DEFAULT_REMOTE_TEMPDIR,
|
||||||
extra_vars=extra_vars
|
extra_vars=extra_vars
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -90,6 +90,7 @@ ANSIBLE_HOSTS -- Override the default ansible hosts file
|
||||||
|
|
||||||
ANSIBLE_LIBRARY -- Override the default ansible module library path
|
ANSIBLE_LIBRARY -- Override the default ansible module library path
|
||||||
|
|
||||||
|
ANSIBLE_REMOTE_TMP -- Override the default ansible remote tmpdir
|
||||||
|
|
||||||
AUTHOR
|
AUTHOR
|
||||||
------
|
------
|
||||||
|
|
|
@ -135,6 +135,8 @@ ANSIBLE_HOSTS -- Override the default ansible hosts file
|
||||||
|
|
||||||
ANSIBLE_LIBRARY -- Override the default ansible module library path
|
ANSIBLE_LIBRARY -- Override the default ansible module library path
|
||||||
|
|
||||||
|
ANSIBLE_REMOTE_TMP -- Override the default ansible remote tmpdir
|
||||||
|
|
||||||
|
|
||||||
AUTHOR
|
AUTHOR
|
||||||
------
|
------
|
||||||
|
|
|
@ -23,6 +23,8 @@ DEFAULT_HOST_LIST = os.environ.get('ANSIBLE_HOSTS',
|
||||||
'/etc/ansible/hosts')
|
'/etc/ansible/hosts')
|
||||||
DEFAULT_MODULE_PATH = os.environ.get('ANSIBLE_LIBRARY',
|
DEFAULT_MODULE_PATH = os.environ.get('ANSIBLE_LIBRARY',
|
||||||
'/usr/share/ansible')
|
'/usr/share/ansible')
|
||||||
|
DEFAULT_REMOTE_TEMPDIR = os.environ.get('ANSIBLE_REMOTE_TMP',
|
||||||
|
'/$HOME/.ansible/tmp')
|
||||||
|
|
||||||
DEFAULT_MODULE_NAME = 'command'
|
DEFAULT_MODULE_NAME = 'command'
|
||||||
DEFAULT_PATTERN = '*'
|
DEFAULT_PATTERN = '*'
|
||||||
|
|
|
@ -62,6 +62,7 @@ class PlayBook(object):
|
||||||
stats = None,
|
stats = None,
|
||||||
sudo = False,
|
sudo = False,
|
||||||
sudo_user = C.DEFAULT_SUDO_USER,
|
sudo_user = C.DEFAULT_SUDO_USER,
|
||||||
|
basetmp = C.DEFAULT_REMOTE_TEMPDIR,
|
||||||
extra_vars = None):
|
extra_vars = None):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -101,6 +102,7 @@ class PlayBook(object):
|
||||||
self.sudo = sudo
|
self.sudo = sudo
|
||||||
self.sudo_pass = sudo_pass
|
self.sudo_pass = sudo_pass
|
||||||
self.sudo_user = sudo_user
|
self.sudo_user = sudo_user
|
||||||
|
self.basetmp = basetmp
|
||||||
self.extra_vars = extra_vars
|
self.extra_vars = extra_vars
|
||||||
self.global_vars = {}
|
self.global_vars = {}
|
||||||
|
|
||||||
|
@ -286,7 +288,8 @@ class PlayBook(object):
|
||||||
setup_cache=SETUP_CACHE, basedir=self.basedir,
|
setup_cache=SETUP_CACHE, basedir=self.basedir,
|
||||||
conditional=only_if, callbacks=self.runner_callbacks,
|
conditional=only_if, callbacks=self.runner_callbacks,
|
||||||
debug=self.debug, sudo=sudo, sudo_user=sudo_user,
|
debug=self.debug, sudo=sudo, sudo_user=sudo_user,
|
||||||
transport=transport, sudo_pass=self.sudo_pass, is_playbook=True
|
transport=transport, sudo_pass=self.sudo_pass,
|
||||||
|
basetmp=self.basetmp, is_playbook=True
|
||||||
)
|
)
|
||||||
|
|
||||||
if async_seconds == 0:
|
if async_seconds == 0:
|
||||||
|
|
|
@ -79,7 +79,7 @@ class Runner(object):
|
||||||
sudo_pass=C.DEFAULT_SUDO_PASS, background=0, basedir=None,
|
sudo_pass=C.DEFAULT_SUDO_PASS, background=0, basedir=None,
|
||||||
setup_cache=None, transport=C.DEFAULT_TRANSPORT, conditional='True',
|
setup_cache=None, transport=C.DEFAULT_TRANSPORT, conditional='True',
|
||||||
callbacks=None, debug=False, sudo=False, sudo_user=C.DEFAULT_SUDO_USER,
|
callbacks=None, debug=False, sudo=False, sudo_user=C.DEFAULT_SUDO_USER,
|
||||||
module_vars=None, is_playbook=False, inventory=None):
|
module_vars=None, is_playbook=False, inventory=None,basetmp=C.DEFAULT_REMOTE_TEMPDIR):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
host_list : path to a host list file, like /etc/ansible/hosts
|
host_list : path to a host list file, like /etc/ansible/hosts
|
||||||
|
@ -96,6 +96,7 @@ class Runner(object):
|
||||||
sudo_pass : sudo password if using sudo and sudo requires a password
|
sudo_pass : sudo password if using sudo and sudo requires a password
|
||||||
background : run asynchronously with a cap of this many # of seconds (if not 0)
|
background : run asynchronously with a cap of this many # of seconds (if not 0)
|
||||||
basedir : paths used by modules if not absolute are relative to here
|
basedir : paths used by modules if not absolute are relative to here
|
||||||
|
basetmp : TMPDIR used on remote host
|
||||||
setup_cache : this is a internalism that is going away
|
setup_cache : this is a internalism that is going away
|
||||||
transport : transport mode (paramiko, local)
|
transport : transport mode (paramiko, local)
|
||||||
conditional : only execute if this string, evaluated, is True
|
conditional : only execute if this string, evaluated, is True
|
||||||
|
@ -119,6 +120,7 @@ class Runner(object):
|
||||||
|
|
||||||
self.sudo_user = sudo_user
|
self.sudo_user = sudo_user
|
||||||
self.transport = transport
|
self.transport = transport
|
||||||
|
self.basetmp = basetmp
|
||||||
self.connector = ansible.connection.Connection(self, self.transport, self.sudo_user)
|
self.connector = ansible.connection.Connection(self, self.transport, self.sudo_user)
|
||||||
|
|
||||||
if inventory is None:
|
if inventory is None:
|
||||||
|
@ -236,7 +238,7 @@ class Runner(object):
|
||||||
|
|
||||||
def _add_setup_metadata(self, args):
|
def _add_setup_metadata(self, args):
|
||||||
''' automatically determine where to store variables for the setup module '''
|
''' automatically determine where to store variables for the setup module '''
|
||||||
|
basetmp = self.basetmp
|
||||||
is_dict = False
|
is_dict = False
|
||||||
if type(args) == dict:
|
if type(args) == dict:
|
||||||
is_dict = True
|
is_dict = True
|
||||||
|
@ -247,13 +249,13 @@ class Runner(object):
|
||||||
if self.remote_user == 'root':
|
if self.remote_user == 'root':
|
||||||
args = "%s metadata=/etc/ansible/setup" % args
|
args = "%s metadata=/etc/ansible/setup" % args
|
||||||
else:
|
else:
|
||||||
args = "%s metadata=$HOME/.ansible/setup" % args
|
args = "%s metadata=%s/.ansible/setup" % (args,basetmp)
|
||||||
else:
|
else:
|
||||||
if not 'metadata' in args:
|
if not 'metadata' in args:
|
||||||
if self.remote_user == 'root':
|
if self.remote_user == 'root':
|
||||||
args['metadata'] = '/etc/ansible/setup'
|
args['metadata'] = '/etc/ansible/setup'
|
||||||
else:
|
else:
|
||||||
args['metadata'] = "$HOME/.ansible/setup"
|
args['metadata'] = "%s/.ansible/setup" % basetmp
|
||||||
return args
|
return args
|
||||||
|
|
||||||
# *****************************************************
|
# *****************************************************
|
||||||
|
@ -657,10 +659,9 @@ class Runner(object):
|
||||||
# The problem with this is that it's executed on the
|
# 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
|
# 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
|
# Only support the *nix world for now by using the $HOME env var
|
||||||
|
basetmp = self.basetmp
|
||||||
|
if self.remote_user == 'root':
|
||||||
basetmp ="/var/tmp"
|
basetmp ="/var/tmp"
|
||||||
if self.remote_user != 'root':
|
|
||||||
basetmp = "$HOME/.ansible/tmp"
|
|
||||||
cmd = "mktemp -d %s/ansible.XXXXXX" % basetmp
|
cmd = "mktemp -d %s/ansible.XXXXXX" % basetmp
|
||||||
if self.remote_user != 'root':
|
if self.remote_user != 'root':
|
||||||
cmd = "mkdir -p %s && %s" % (basetmp, cmd)
|
cmd = "mkdir -p %s && %s" % (basetmp, cmd)
|
||||||
|
|
Loading…
Reference in a new issue