write custom inventory scripts to AWX_PRIVATE_DATA_DIR

this makes it so that custom inventory scripts can access credential
files laid down in `/tmp/awx_N_<xyz>`

see: https://github.com/ansible/tower/issues/2951
This commit is contained in:
Ryan Petrello
2018-08-30 08:32:27 -04:00
parent 34c659d8b6
commit 9ae41dc3ba

View File

@@ -2163,8 +2163,7 @@ class RunInventoryUpdate(BaseTask):
elif src == 'scm': elif src == 'scm':
args.append(inventory_update.get_actual_source_path()) args.append(inventory_update.get_actual_source_path())
elif src == 'custom': elif src == 'custom':
runpath = tempfile.mkdtemp(prefix='awx_inventory_', dir=settings.AWX_PROOT_BASE_PATH) handle, path = tempfile.mkstemp(dir=kwargs['private_data_dir'])
handle, path = tempfile.mkstemp(dir=runpath)
f = os.fdopen(handle, 'w') f = os.fdopen(handle, 'w')
if inventory_update.source_script is None: if inventory_update.source_script is None:
raise RuntimeError('Inventory Script does not exist') raise RuntimeError('Inventory Script does not exist')
@@ -2173,7 +2172,6 @@ class RunInventoryUpdate(BaseTask):
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
args.append(path) args.append(path)
args.append("--custom") args.append("--custom")
self.cleanup_paths.append(runpath)
args.append('-v%d' % inventory_update.verbosity) args.append('-v%d' % inventory_update.verbosity)
if settings.DEBUG: if settings.DEBUG:
args.append('--traceback') args.append('--traceback')