Fix errors on 'ansible-playbook --flush-cache' (#18754)

Add a unit test, and split out the flush cache logic to
it's own method.
Fixes #18708
This commit is contained in:
Adrian Likins 2016-12-13 14:35:15 -05:00 committed by GitHub
parent 6c4f554f5a
commit 08a5d506bb
2 changed files with 46 additions and 2 deletions

View file

@ -148,8 +148,7 @@ class PlaybookCLI(CLI):
# flush fact cache if requested
if self.options.flush_cache:
for host in inventory.list_hosts():
variable_manager.clear_facts(host)
self._flush_cache(inventory, variable_manager)
# create the playbook executor, which manages running the plays via a task queue manager
pbex = PlaybookExecutor(playbooks=self.args, inventory=inventory, variable_manager=variable_manager, loader=loader, options=self.options, passwords=passwords)
@ -218,3 +217,8 @@ class PlaybookCLI(CLI):
return 0
else:
return results
def _flush_cache(self, inventory, variable_manager):
for host in inventory.list_hosts():
hostname = host.get_name()
variable_manager.clear_facts(hostname)