Merge pull request #1306 from ryanpetrello/isolated-fact-cache

support fact caching for isolated hosts
This commit is contained in:
Ryan Petrello
2018-02-20 15:50:49 -05:00
committed by GitHub
2 changed files with 14 additions and 3 deletions

View File

@@ -901,7 +901,7 @@ class BaseTask(LogErrorsTask):
# Fetch "cached" fact data from prior runs and put on the disk # Fetch "cached" fact data from prior runs and put on the disk
# where ansible expects to find it # 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( instance.start_job_fact_cache(
os.path.join(kwargs['private_data_dir']), os.path.join(kwargs['private_data_dir']),
kwargs.setdefault('fact_modification_times', {}) kwargs.setdefault('fact_modification_times', {})
@@ -1140,7 +1140,7 @@ class RunJob(BaseTask):
# callbacks to work. # callbacks to work.
env['JOB_ID'] = str(job.pk) env['JOB_ID'] = str(job.pk)
env['INVENTORY_ID'] = str(job.inventory.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') library_path = env.get('ANSIBLE_LIBRARY')
env['ANSIBLE_LIBRARY'] = ':'.join( env['ANSIBLE_LIBRARY'] = ':'.join(
filter(None, [ filter(None, [
@@ -1349,7 +1349,7 @@ class RunJob(BaseTask):
def final_run_hook(self, job, status, **kwargs): def final_run_hook(self, job, status, **kwargs):
super(RunJob, self).final_run_hook(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( job.finish_job_fact_cache(
kwargs['private_data_dir'], kwargs['private_data_dir'],
kwargs['fact_modification_times'] kwargs['fact_modification_times']

View File

@@ -25,3 +25,14 @@
fail: fail:
msg: "isolated task is still running" msg: "isolated task is still running"
when: "is_alive.rc == 0" 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