diff options
author | chris meyers <chris.meyers.fsu@gmail.com> | 2019-06-24 20:08:43 +0200 |
---|---|---|
committer | chris meyers <chris.meyers.fsu@gmail.com> | 2019-07-17 21:36:09 +0200 |
commit | 9b95cc27c4840140996a036223e2909a30953b95 (patch) | |
tree | 9e283fce2fa5e87ac4a7303cc7eef07d80df1991 | |
parent | Merge pull request #4337 from ryanpetrello/activity-stream-missing-jt (diff) | |
download | awx-9b95cc27c4840140996a036223e2909a30953b95.tar.xz awx-9b95cc27c4840140996a036223e2909a30953b95.zip |
map in a global collections path
-rw-r--r-- | awx/main/tasks.py | 13 | ||||
-rw-r--r-- | awx/main/tests/functional/test_inventory_source_injectors.py | 1 | ||||
-rw-r--r-- | awx/main/tests/unit/test_tasks.py | 16 | ||||
-rw-r--r-- | awx/settings/defaults.py | 3 | ||||
-rw-r--r-- | awx/settings/local_settings.py.docker_compose | 2 | ||||
-rw-r--r-- | docs/collections.md | 6 |
6 files changed, 40 insertions, 1 deletions
diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 70f99c4bde..80a49d697c 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -859,10 +859,16 @@ class BaseTask(object): ''' process_isolation_params = dict() if self.should_use_proot(instance): + show_paths = self.proot_show_paths + [private_data_dir, cwd] + \ + settings.AWX_PROOT_SHOW_PATHS + + # Help the user out by including the collections path inside the bubblewrap environment + if getattr(settings, 'AWX_ANSIBLE_COLLECTIONS_PATHS', []): + show_paths.extend(settings.AWX_ANSIBLE_COLLECTIONS_PATHS) process_isolation_params = { 'process_isolation': True, 'process_isolation_path': settings.AWX_PROOT_BASE_PATH, - 'process_isolation_show_paths': self.proot_show_paths + [private_data_dir, cwd] + settings.AWX_PROOT_SHOW_PATHS, + 'process_isolation_show_paths': show_paths, 'process_isolation_hide_paths': [ settings.AWX_PROOT_BASE_PATH, '/etc/tower', @@ -936,6 +942,11 @@ class BaseTask(object): if self.should_use_proot(instance): env['PROOT_TMP_DIR'] = settings.AWX_PROOT_BASE_PATH env['AWX_PRIVATE_DATA_DIR'] = private_data_dir + + if 'ANSIBLE_COLLECTIONS_PATHS' in env: + env['ANSIBLE_COLLECTIONS_PATHS'] += os.pathsep + os.pathsep.join(settings.AWX_ANSIBLE_COLLECTIONS_PATHS) + else: + env['ANSIBLE_COLLECTIONS_PATHS'] = os.pathsep.join(settings.AWX_ANSIBLE_COLLECTIONS_PATHS) return env def should_use_proot(self, instance): diff --git a/awx/main/tests/functional/test_inventory_source_injectors.py b/awx/main/tests/functional/test_inventory_source_injectors.py index fd6edd09a5..b4a12b5802 100644 --- a/awx/main/tests/functional/test_inventory_source_injectors.py +++ b/awx/main/tests/functional/test_inventory_source_injectors.py @@ -258,6 +258,7 @@ def test_inventory_update_injected_content(this_kind, script_or_plugin, inventor """ private_data_dir = envvars.pop('AWX_PRIVATE_DATA_DIR') assert envvars.pop('ANSIBLE_INVENTORY_ENABLED') == ('auto' if use_plugin else 'script') + assert envvars.pop('ANSIBLE_COLLECTIONS_PATHS') == os.pathsep.join(settings.AWX_ANSIBLE_COLLECTIONS_PATHS) set_files = bool(os.getenv("MAKE_INVENTORY_REFERENCE_FILES", 'false').lower()[0] not in ['f', '0']) env, content = read_content(private_data_dir, envvars, inventory_update) base_dir = os.path.join(DATA, script_or_plugin) diff --git a/awx/main/tests/unit/test_tasks.py b/awx/main/tests/unit/test_tasks.py index 3db5f10caa..2b776bd610 100644 --- a/awx/main/tests/unit/test_tasks.py +++ b/awx/main/tests/unit/test_tasks.py @@ -441,6 +441,7 @@ class TestGenericRun(): settings.AWX_PROOT_HIDE_PATHS = ['/AWX_PROOT_HIDE_PATHS1', '/AWX_PROOT_HIDE_PATHS2'] settings.ANSIBLE_VENV_PATH = '/ANSIBLE_VENV_PATH' settings.AWX_VENV_PATH = '/AWX_VENV_PATH' + settings.AWX_ANSIBLE_COLLECTIONS_PATHS = ['/AWX_COLLECTION_PATH1', '/AWX_COLLECTION_PATH2'] process_isolation_params = task.build_params_process_isolation(job, private_data_dir, cwd) assert True is process_isolation_params['process_isolation'] @@ -450,6 +451,10 @@ class TestGenericRun(): "The per-job private data dir should be in the list of directories the user can see." assert cwd in process_isolation_params['process_isolation_show_paths'], \ "The current working directory should be in the list of directories the user can see." + assert '/AWX_COLLECTION_PATH1' in process_isolation_params['process_isolation_show_paths'], \ + "AWX global collection directory 1 of 2 should get added to the list of directories the user can see." + assert '/AWX_COLLECTION_PATH2' in process_isolation_params['process_isolation_show_paths'], \ + "AWX global collection directory 2 of 2 should get added to the list of directories the user can see." for p in [settings.AWX_PROOT_BASE_PATH, '/etc/tower', @@ -509,6 +514,17 @@ class TestGenericRun(): env = task.build_env(job, private_data_dir) assert env['FOO'] == 'BAR' + def test_awx_task_env_respects_ansible_collections_paths(self, patch_Job, private_data_dir): + job = Job(project=Project(), inventory=Inventory()) + + task = tasks.RunJob() + task._write_extra_vars_file = mock.Mock() + + with mock.patch('awx.main.tasks.settings.AWX_ANSIBLE_COLLECTIONS_PATHS', ['/AWX_COLLECTION_PATH']): + with mock.patch('awx.main.tasks.settings.AWX_TASK_ENV', {'ANSIBLE_COLLECTIONS_PATHS': '/MY_COLLECTION1:/MY_COLLECTION2'}): + env = task.build_env(job, private_data_dir) + assert env['ANSIBLE_COLLECTIONS_PATHS'] == '/MY_COLLECTION1:/MY_COLLECTION2:/AWX_COLLECTION_PATH' + def test_valid_custom_virtualenv(self, patch_Job, private_data_dir): job = Job(project=Project(), inventory=Inventory()) diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index b577e86ae5..a2a1fc7e4c 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -1187,6 +1187,9 @@ AWX_REQUEST_PROFILE = False # Delete temporary directories created to store playbook run-time AWX_CLEANUP_PATHS = True +# Expose collections to Ansible playbooks +AWX_ANSIBLE_COLLECTIONS_PATHS = ['/var/lib/awx/collections'] + MIDDLEWARE = [ 'awx.main.middleware.TimingMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', diff --git a/awx/settings/local_settings.py.docker_compose b/awx/settings/local_settings.py.docker_compose index d0d5f8c819..80b68e6193 100644 --- a/awx/settings/local_settings.py.docker_compose +++ b/awx/settings/local_settings.py.docker_compose @@ -276,3 +276,5 @@ TEST_OPENSTACK_PROJECT = '' # Azure credentials. TEST_AZURE_USERNAME = '' TEST_AZURE_KEY_DATA = '' + +AWX_ANSIBLE_COLLECTIONS_PATHS = ['/tmp/collections'] diff --git a/docs/collections.md b/docs/collections.md new file mode 100644 index 0000000000..4ab27bc350 --- /dev/null +++ b/docs/collections.md @@ -0,0 +1,6 @@ +## Collections Support + +AWX supports Ansible collections by appending the directories specified in `AWX_ANSIBLE_COLLECTIONS_PATHS` +to the environment variable `ANSIBLE_COLLECTIONS_PATHS`. The default value of `AWX_ANSIBLE_COLLECTIONS_PATHS` +contains `/varlib/awx/collections`. It is recommended that place your collections that you wish to call in +your playbooks into this path. |