diff --git a/ansible_runner/config/_base.py b/ansible_runner/config/_base.py index a1e996fbe..4129b9285 100644 --- a/ansible_runner/config/_base.py +++ b/ansible_runner/config/_base.py @@ -100,7 +100,7 @@ def __init__(self, # attempt to compromise the directories via a race. os.makedirs(self.private_data_dir, exist_ok=True, mode=0o700) else: - self.private_data_dir = tempfile.mkdtemp(prefix=".ansible-runner-") + self.private_data_dir = tempfile.mkdtemp(prefix=defaults.AUTO_CREATE_NAMING, dir=defaults.AUTO_CREATE_DIR) if artifact_dir is None: artifact_dir = os.path.join(self.private_data_dir, 'artifacts') diff --git a/ansible_runner/defaults.py b/ansible_runner/defaults.py index 6a2681ee1..81ac2e976 100644 --- a/ansible_runner/defaults.py +++ b/ansible_runner/defaults.py @@ -4,3 +4,8 @@ # for ansible-runner worker cleanup command GRACE_PERIOD_DEFAULT = 60 # minutes + +# values passed to tempfile.mkdtemp to generate a private data dir +# when user did not provide one +AUTO_CREATE_NAMING = '.ansible-runner-' +AUTO_CREATE_DIR = None diff --git a/test/conftest.py b/test/conftest.py index 6e361811b..d8785b4ea 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -2,6 +2,8 @@ from distutils.version import LooseVersion +from ansible_runner import defaults + import pkg_resources import pytest @@ -17,6 +19,11 @@ def mock_env_user(monkeypatch): monkeypatch.setenv("ANSIBLE_DEVEL_WARNING", "False") +@pytest.fixture(autouse=True) +def change_save_path(tmp_path, mocker): + mocker.patch.object(defaults, 'AUTO_CREATE_DIR', str(tmp_path)) + + @pytest.fixture(scope='session') def is_pre_ansible28(): try: