Skip to content

Commit

Permalink
Change mount location and introduce shared method
Browse files Browse the repository at this point in the history
This changes the location of the mount for the stdout callback
prior value was at
/home/runner/.ansible/plugins

new mount location is at
/home/runner/.ansible/plugins/callback

This is more targeted and more desirable for this reason.
We cannot mount single-files like awx_display.py,
due to permissions error, which
  may be because changes are needed in the Dockerfile
  or some other reason

To carry this out, new utils method callback_mount is introduced
  to make such changes easier to carry out in the future
  • Loading branch information
AlanCoding committed Jan 17, 2022
1 parent 0fee719 commit 11292eb
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 15 deletions.
4 changes: 2 additions & 2 deletions ansible_runner/config/_base.py
Expand Up @@ -39,7 +39,7 @@
from ansible_runner.defaults import registry_auth_prefix
from ansible_runner.loader import ArtifactLoader
from ansible_runner.utils import (
get_plugin_dir,
callback_mount,
get_callback_dir,
open_fifo_write,
args2cmdline,
Expand Down Expand Up @@ -495,7 +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
self._update_volume_mount_paths(new_args, "{}".format(get_plugin_dir()), dst_mount_path="/home/runner/.ansible/plugins", labels=":Z")
self._update_volume_mount_paths(new_args, callback_mount()[0], dst_mount_path=callback_mount()[1], labels=":Z")

if self.container_auth_data:
# Pull in the necessary registry auth info, if there is a container cred
Expand Down
12 changes: 12 additions & 0 deletions ansible_runner/utils/__init__.py
Expand Up @@ -54,6 +54,18 @@ def get_callback_dir():
return os.path.join(get_plugin_dir(), 'callback')


def callback_mount():
'''
Return a tuple that gives mount points for the standard out callback
in the form of (<host location>, <location in container>)
'''
container_dot_ansible = '/home/runner/.ansible'
rel_path = ('callback', '',)
callback_file = os.path.join(get_plugin_dir(), *rel_path)
container_path = os.path.join(container_dot_ansible, 'plugins', *rel_path)
return (callback_file, container_path)


class Bunch(object):

'''
Expand Down
4 changes: 2 additions & 2 deletions test/unit/config/test__base.py
Expand Up @@ -13,7 +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
from ansible_runner.utils import callback_mount

try:
Pattern = re._pattern_type
Expand Down Expand Up @@ -317,7 +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()),
'-v', '{0}:{1}:Z'.format(*callback_mount()),
'--env-file', '{}/env.list'.format(rc.artifact_dir),
])

Expand Down
4 changes: 2 additions & 2 deletions test/unit/config/test_ansible_cfg.py
Expand Up @@ -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, get_plugin_dir
from ansible_runner.utils import get_executable_path, callback_mount


def test_ansible_cfg_init_defaults(tmp_path, patch_private_data_dir):
Expand Down Expand Up @@ -91,7 +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()),
'-v', '{0}:{1}:Z'.format(*callback_mount()),
'--env-file', '{}/env.list'.format(rc.artifact_dir),
])

Expand Down
4 changes: 2 additions & 2 deletions test/unit/config/test_command.py
Expand Up @@ -6,7 +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
from ansible_runner.utils import callback_mount


def test_ansible_config_defaults(tmp_path, patch_private_data_dir):
Expand Down Expand Up @@ -106,7 +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()),
'-v', '{0}:{1}:Z'.format(*callback_mount()),
'--env-file', '{}/env.list'.format(rc.artifact_dir),
])

Expand Down
6 changes: 3 additions & 3 deletions test/unit/config/test_doc.py
Expand Up @@ -6,7 +6,7 @@
from ansible_runner.config.doc import DocConfig
from ansible_runner.config._base import BaseExecutionMode
from ansible_runner.exceptions import ConfigurationError
from ansible_runner.utils import get_executable_path, get_plugin_dir
from ansible_runner.utils import get_executable_path, callback_mount


def test_ansible_doc_defaults(tmp_path, patch_private_data_dir):
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_prepare_plugin_docs_command_with_containerization(tmp_path, runtime, mo
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()),
'-v', '{0}:{1}:Z'.format(*callback_mount()),
'--env-file', '{}/env.list'.format(rc.artifact_dir),
])

Expand Down Expand Up @@ -170,7 +170,7 @@ def test_prepare_plugin_list_command_with_containerization(tmp_path, runtime, mo
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()),
'-v', '{0}:{1}:Z'.format(*callback_mount()),
'--env-file', '{}/env.list'.format(rc.artifact_dir),
])

Expand Down
4 changes: 2 additions & 2 deletions test/unit/config/test_inventory.py
Expand Up @@ -6,7 +6,7 @@
from ansible_runner.config.inventory import InventoryConfig
from ansible_runner.config._base import BaseExecutionMode
from ansible_runner.exceptions import ConfigurationError
from ansible_runner.utils import get_executable_path, get_plugin_dir
from ansible_runner.utils import get_executable_path, callback_mount


def test_ansible_inventory_init_defaults(tmp_path, patch_private_data_dir):
Expand Down Expand Up @@ -126,7 +126,7 @@ def test_prepare_inventory_command_with_containerization(tmp_path, runtime, mock
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()),
'-v', '{0}:{1}:Z'.format(*callback_mount()),
'--env-file', '{}/env.list'.format(rc.artifact_dir),
])

Expand Down
4 changes: 2 additions & 2 deletions test/unit/config/test_runner.py
Expand Up @@ -14,7 +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
from ansible_runner.utils import callback_mount

try:
Pattern = re._pattern_type
Expand Down Expand Up @@ -732,7 +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', '{0}:{1}:Z'.format(*callback_mount())] + \
['-v', '/host1/:/container1/', '-v', '/host2/:/container2/'] + \
['--env-file', '{}/env.list'.format(rc.artifact_dir)] + \
extra_container_args + \
Expand Down

0 comments on commit 11292eb

Please sign in to comment.