def ansible_syntax_check():
    # templ = """{{ lookup(
    #           'template', '%s/ansible/roles/sigia/templates/ansible_extra_vars.j2')
    #            }}""" % ( config.rootdir )
    loader = DataLoader()
    inventory = InventoryManager(loader=loader, sources='local,')
    variable_manager = VariableManager(loader=loader, inventory=inventory)
    pb = Playbook.load(config.rootdir +
                       "/infrastructure/ansible/aws-security.yml",
                       variable_manager=variable_manager,
                       loader=loader)
    plays = pb.get_plays()
    localhost = inventory.get_host("local")
    for play in plays:
        variable_manager.set_host_facts(localhost,
                                        variable_manager.get_vars(play))
    # local_vars = variable_manager.get_vars(host=localhost)
    # templar = Templar(loader=loader, variables=local_vars)
    # extra_vars = templar.template(templ)
    # if extra_vars:
    #     variable_manager.extra_vars = extra_vars
    r = ansible_runner.run(
        private_data_dir=TEST_DIR,
        inventory='local,',
        playbook=str(config.rootdir) +
        '/infrastructure/ansible/aws-security.yml',
        # extravars=extra_vars,
        artifact_dir="/tmp/ansible",
        rotate_artifacts=5)
    return r
Esempio n. 2
0
    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)