def test_flush_cache(self): cli = PlaybookCLI(args=["--flush-cache", "foobar.yml"]) variable_manager = VariableManager() fake_loader = DictDataLoader({'foobar.yml': ""}) inventory = InventoryManager(loader=fake_loader, sources='testhost,') cli._flush_cache(inventory, variable_manager) self.assertFalse('testhost' in variable_manager._fact_cache)
def test_flush_cache(self): cli = PlaybookCLI(args=["ansible-playbook", "--flush-cache", "foobar.yml"]) cli.parse() self.assertTrue(cli.options.flush_cache) variable_manager = VariableManager() fake_loader = DictDataLoader({'foobar.yml': ""}) inventory = InventoryManager(loader=fake_loader, sources='testhost,') variable_manager.set_host_facts(inventory.get_host('testhost'), {'canary': True}) self.assertTrue('testhost' in variable_manager._fact_cache) cli._flush_cache(inventory, variable_manager) self.assertFalse('testhost' in variable_manager._fact_cache)
def test_flush_cache(self): cli = PlaybookCLI( args=["ansible-playbook", "--flush-cache", "foobar.yml"]) cli.parse() self.assertTrue(context.CLIARGS['flush_cache']) variable_manager = VariableManager() fake_loader = DictDataLoader({'foobar.yml': ""}) inventory = InventoryManager(loader=fake_loader, sources='testhost,') variable_manager.set_host_facts('testhost', {'canary': True}) self.assertTrue('testhost' in variable_manager._fact_cache) cli._flush_cache(inventory, variable_manager) self.assertFalse('testhost' in variable_manager._fact_cache)
# don't deal with privilege escalation or passwords when we don't need to if not (context.CLIARGS['listhosts'] or context.CLIARGS['listtasks'] or context.CLIARGS['listtags'] or context.CLIARGS['syntax']): (sshpass, becomepass) = pb_cli.ask_passwords() passwords = {'conn_pass': sshpass, 'become_pass': becomepass} # create base objects loader, inventory, variable_manager = pb_cli._play_prereqs() # Fix this when we rewrite inventory by making localhost a real host (and thus show up in list_hosts()) hosts = CLI.get_host_list(inventory, context.CLIARGS['subset']) # flush fact cache if requplaybook_pathested if context.CLIARGS['flush_cache']: pb_cli._flush_cache(inventory, variable_manager) ###################################################################### # Execute the playbook file pbex = PlaybookExecutor( playbooks=context.CLIARGS['args'], inventory=inventory, variable_manager=variable_manager, loader=loader, passwords=passwords, ) # Override the default stdout callback with our custom callback pbex._tqm._stdout_callback = results_callback results = pbex.run()