From 7d9e4d6e2fc1d2293576630765dea0bd049d892d Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Tue, 20 Feb 2018 15:00:47 -0500 Subject: [PATCH] support fact caching for isolated hosts see: https://github.com/ansible/awx/issues/198 --- awx/main/tasks.py | 6 +++--- awx/playbooks/check_isolated.yml | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 42a7db56fc..917eecc9b9 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -901,7 +901,7 @@ class BaseTask(LogErrorsTask): # Fetch "cached" fact data from prior runs and put on the disk # where ansible expects to find it - if getattr(instance, 'use_fact_cache', False) and not kwargs.get('isolated'): + if getattr(instance, 'use_fact_cache', False): instance.start_job_fact_cache( os.path.join(kwargs['private_data_dir']), kwargs.setdefault('fact_modification_times', {}) @@ -1140,7 +1140,7 @@ class RunJob(BaseTask): # callbacks to work. env['JOB_ID'] = str(job.pk) env['INVENTORY_ID'] = str(job.inventory.pk) - if job.use_fact_cache and not kwargs.get('isolated'): + if job.use_fact_cache: library_path = env.get('ANSIBLE_LIBRARY') env['ANSIBLE_LIBRARY'] = ':'.join( filter(None, [ @@ -1349,7 +1349,7 @@ class RunJob(BaseTask): def final_run_hook(self, job, status, **kwargs): super(RunJob, self).final_run_hook(job, status, **kwargs) - if job.use_fact_cache and not kwargs.get('isolated'): + if job.use_fact_cache: job.finish_job_fact_cache( kwargs['private_data_dir'], kwargs['fact_modification_times'] diff --git a/awx/playbooks/check_isolated.yml b/awx/playbooks/check_isolated.yml index 69018a6ed2..775389893c 100644 --- a/awx/playbooks/check_isolated.yml +++ b/awx/playbooks/check_isolated.yml @@ -25,3 +25,14 @@ fail: msg: "isolated task is still running" when: "is_alive.rc == 0" + + - stat: path="{{src}}/facts/" + register: fact_cache + + - name: Copy gathered facts from the isolated host. + synchronize: + src: "{{src}}/facts/" + dest: "{{src}}/facts/" + delete: yes # delete fact cache records that go missing via clear_facts + mode: pull + when: fact_cache.stat.exists