From 2955842c44c69cc4b93811ac8311abdf48ba28bc Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Mon, 15 Jan 2018 13:35:51 -0500 Subject: [PATCH] don't overwrite env['ANSIBLE_LIBRARY'] when fact caching is enabled see: https://github.com/ansible/awx/issues/815 see: https://github.com/ansible/ansible-tower/issues/7830 --- awx/main/tasks.py | 8 +++++++- awx/main/tests/unit/test_tasks.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index b60ee6b16d..3345dada44 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -1040,7 +1040,13 @@ class RunJob(BaseTask): env['JOB_ID'] = str(job.pk) env['INVENTORY_ID'] = str(job.inventory.pk) if job.use_fact_cache and not kwargs.get('isolated'): - env['ANSIBLE_LIBRARY'] = self.get_path_to('..', 'plugins', 'library') + library_path = env.get('ANSIBLE_LIBRARY') + env['ANSIBLE_LIBRARY'] = ':'.join( + filter(None, [ + library_path, + self.get_path_to('..', 'plugins', 'library') + ]) + ) env['ANSIBLE_CACHE_PLUGIN'] = "jsonfile" env['ANSIBLE_CACHE_PLUGIN_CONNECTION'] = os.path.join(kwargs['private_data_dir'], 'facts') if job.project: diff --git a/awx/main/tests/unit/test_tasks.py b/awx/main/tests/unit/test_tasks.py index 963ebc87ae..20a051ec30 100644 --- a/awx/main/tests/unit/test_tasks.py +++ b/awx/main/tests/unit/test_tasks.py @@ -348,6 +348,25 @@ class TestGenericRun(TestJobExecution): assert env['ANSIBLE_CACHE_PLUGIN'] == 'jsonfile' assert env['ANSIBLE_CACHE_PLUGIN_CONNECTION'] == os.path.join(tmpdir, 'facts') + @pytest.mark.parametrize('task_env, ansible_library_env', [ + [{}, '/awx_devel/awx/plugins/library'], + [{'ANSIBLE_LIBRARY': '/foo/bar'}, '/foo/bar:/awx_devel/awx/plugins/library'], + ]) + def test_fact_cache_usage_with_ansible_library(self, task_env, ansible_library_env): + patch = mock.patch('awx.main.tasks.settings.AWX_TASK_ENV', task_env) + patch.start() + + self.instance.use_fact_cache = True + start_mock = mock.Mock() + patch = mock.patch.object(Job, 'start_job_fact_cache', start_mock) + self.patches.append(patch) + patch.start() + + self.task.run(self.pk) + call_args, _ = self.run_pexpect.call_args_list[0] + args, cwd, env, stdout = call_args + assert env['ANSIBLE_LIBRARY'] == ansible_library_env + class TestAdhocRun(TestJobExecution):