Exemple #1
0
def read_playbook(*args):
    args_list = list(args)
    cli = PlaybookCLI(args_list)
    parser = cli.base_parser(
        connect_opts=True,
        meta_opts=True,
        runas_opts=True,
        subset_opts=True,
        check_opts=True,
        inventory_opts=True,
        runtask_opts=True,
        vault_opts=True,
        fork_opts=True,
        module_opts=True,
    )
    cli.options, cli.args = parser.parse_args(args_list)
    cli.normalize_become_options()
    cli.options.connection = 'smart'
    cli.options.inventory = 'inventory'

    loader, inventory, variable_manager = cli._play_prereqs(cli.options)

    pb = Playbook.load(cli.args[0], variable_manager, loader)

    for play in pb.get_plays():
        yield variable_manager.get_vars(play)
Exemple #2
0
class General(object):
    def __init__(self):
        self.cli = PlaybookCLI(sys.argv, callback=CallbackModule)
        self.cli.parse()

    def run(self):
        sshpass = None
        becomepass = None
        passwords = {}

        if not self.cli.options.listhosts and not self.cli.options.listtasks and not self.cli.options.listtags and not self.cli.options.syntax:
            self.cli.normalize_become_options()
            (sshpass, becomepass) = self.cli.ask_passwords()
            passwords = {'conn_pass': sshpass, 'become_pass': becomepass}

        loader, inventory, variable_manager = self.cli._play_prereqs(
            self.cli.options)

        for playbook_path in self.cli.args:
            pb = Playbook.load(playbook_path,
                               variable_manager=variable_manager,
                               loader=loader)
            plays = pb.get_plays()

            for play in plays:
                tqm = None
                try:
                    tqm = TaskQueueManager(
                        inventory=inventory,
                        variable_manager=variable_manager,
                        loader=loader,
                        options=self.cli.options,
                        passwords=passwords,
                        stdout_callback=CallbackModule(),
                    )
                    tqm.run(play)
                finally:
                    if tqm is not None:
                        tqm.cleanup()