diff --git a/ansible_runner/config/_base.py b/ansible_runner/config/_base.py index cc64ad75d..556ace4c9 100644 --- a/ansible_runner/config/_base.py +++ b/ansible_runner/config/_base.py @@ -39,6 +39,8 @@ from ansible_runner.defaults import registry_auth_prefix from ansible_runner.loader import ArtifactLoader from ansible_runner.utils import ( + get_plugin_dir, + get_callback_dir, open_fifo_write, args2cmdline, sanitize_container_name, @@ -256,7 +258,7 @@ def _prepare_env(self, runner_mode='pexpect'): if not self.containerized: callback_dir = self.env.get('AWX_LIB_DIRECTORY', os.getenv('AWX_LIB_DIRECTORY')) if callback_dir is None: - callback_dir = os.path.abspath(os.path.join(os.path.split(os.path.abspath(__file__))[0], "..", "display_callback", "callback")) + callback_dir = get_callback_dir() self.env['ANSIBLE_CALLBACK_PLUGINS'] = ':'.join(filter(None, (self.env.get('ANSIBLE_CALLBACK_PLUGINS'), callback_dir))) # this is an adhoc command if the module is specified, TODO: combine with logic in RunnerConfig class @@ -493,8 +495,7 @@ def wrap_args_for_containerization(self, args, execution_mode, cmdline_args): self._update_volume_mount_paths(new_args, "{}".format(self.private_data_dir), dst_mount_path="/runner", labels=":Z") # Mount the stdout callback plugin from the ansible-runner code base - plugin_dir = os.path.abspath(os.path.join(os.path.split(os.path.abspath(__file__))[0], "..", "display_callback")) - self._update_volume_mount_paths(new_args, "{}".format(plugin_dir), dst_mount_path="/home/runner/.ansible/plugins", labels=":Z") + self._update_volume_mount_paths(new_args, "{}".format(get_plugin_dir()), dst_mount_path="/home/runner/.ansible/plugins", labels=":Z") if self.container_auth_data: # Pull in the necessary registry auth info, if there is a container cred diff --git a/ansible_runner/utils/__init__.py b/ansible_runner/utils/__init__.py index 84b2b2a70..c0c64e815 100644 --- a/ansible_runner/utils/__init__.py +++ b/ansible_runner/utils/__init__.py @@ -46,6 +46,14 @@ def register_for_cleanup(folder): atexit.register(cleanup_folder, folder) +def get_plugin_dir(): + return os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "display_callback")) + + +def get_callback_dir(): + return os.path.join(get_plugin_dir(), 'callback') + + class Bunch(object): ''' diff --git a/test/unit/config/test__base.py b/test/unit/config/test__base.py index 1aec5d811..594e2266c 100644 --- a/test/unit/config/test__base.py +++ b/test/unit/config/test__base.py @@ -13,6 +13,7 @@ from ansible_runner.config._base import BaseConfig, BaseExecutionMode from ansible_runner.loader import ArtifactLoader from ansible_runner.exceptions import ConfigurationError +from ansible_runner.utils import get_plugin_dir try: Pattern = re._pattern_type @@ -316,6 +317,7 @@ def test_containerization_settings(tmp_path, runtime, mocker): expected_command_start.extend([ '-v', '{}/artifacts/:/runner/artifacts/:Z'.format(rc.private_data_dir), '-v', '{}/:/runner/:Z'.format(rc.private_data_dir), + '-v', '{}/:/home/runner/.ansible/plugins/:Z'.format(get_plugin_dir()), '--env-file', '{}/env.list'.format(rc.artifact_dir), ]) diff --git a/test/unit/config/test_ansible_cfg.py b/test/unit/config/test_ansible_cfg.py index ecc96bea7..7d8302790 100644 --- a/test/unit/config/test_ansible_cfg.py +++ b/test/unit/config/test_ansible_cfg.py @@ -6,7 +6,7 @@ from ansible_runner.config.ansible_cfg import AnsibleCfgConfig from ansible_runner.config._base import BaseExecutionMode from ansible_runner.exceptions import ConfigurationError -from ansible_runner.utils import get_executable_path +from ansible_runner.utils import get_executable_path, get_plugin_dir def test_ansible_cfg_init_defaults(tmp_path, patch_private_data_dir): @@ -91,6 +91,7 @@ def test_prepare_config_command_with_containerization(tmp_path, runtime, mocker) expected_command_start.extend([ '-v', '{}/artifacts/:/runner/artifacts/:Z'.format(rc.private_data_dir), '-v', '{}/:/runner/:Z'.format(rc.private_data_dir), + '-v', '{}/:/home/runner/.ansible/plugins/:Z'.format(get_plugin_dir()), '--env-file', '{}/env.list'.format(rc.artifact_dir), ]) diff --git a/test/unit/config/test_command.py b/test/unit/config/test_command.py index 75bc2db64..6fc49afca 100644 --- a/test/unit/config/test_command.py +++ b/test/unit/config/test_command.py @@ -6,6 +6,7 @@ from ansible_runner.config.command import CommandConfig from ansible_runner.config._base import BaseExecutionMode from ansible_runner.exceptions import ConfigurationError +from ansible_runner.utils import get_plugin_dir def test_ansible_config_defaults(tmp_path, patch_private_data_dir): @@ -105,6 +106,7 @@ def test_prepare_run_command_with_containerization(tmp_path, runtime, mocker): expected_command_start.extend([ '-v', '{}/artifacts/:/runner/artifacts/:Z'.format(rc.private_data_dir), '-v', '{}/:/runner/:Z'.format(rc.private_data_dir), + '-v', '{}/:/home/runner/.ansible/plugins/:Z'.format(get_plugin_dir()), '--env-file', '{}/env.list'.format(rc.artifact_dir), ]) diff --git a/test/unit/config/test_runner.py b/test/unit/config/test_runner.py index 309988d9a..44b96b8f9 100644 --- a/test/unit/config/test_runner.py +++ b/test/unit/config/test_runner.py @@ -14,6 +14,7 @@ from ansible_runner.interface import init_runner from ansible_runner.loader import ArtifactLoader from ansible_runner.exceptions import ConfigurationError +from ansible_runner.utils import get_plugin_dir try: Pattern = re._pattern_type @@ -731,6 +732,7 @@ def test_containerization_settings(tmp_path, runtime, mocker): expected_command_start = [runtime, 'run', '--rm', '--tty', '--interactive', '--workdir', '/runner/project'] + \ ['-v', '{}/:/runner/:Z'.format(rc.private_data_dir)] + \ + ['-v', '{}/:/home/runner/.ansible/plugins/:Z'.format(get_plugin_dir())] + \ ['-v', '/host1/:/container1/', '-v', '/host2/:/container2/'] + \ ['--env-file', '{}/env.list'.format(rc.artifact_dir)] + \ extra_container_args + \