def __init__(self, playbooks, inventory, variable_manager, loader, options, passwords): super(PlaybookExecutorV2, self).__init__(playbooks, inventory, variable_manager, loader, options, passwords) if self._tqm is not None: self._tqm._stdout_callback = CallbackModule()
def __init__(self, playbooks, inventory, variable_manager, loader, options, passwords): self._playbooks = playbooks self._inventory = inventory self._variable_manager = variable_manager self._loader = loader self._options = options self.passwords = passwords self._unreachable_hosts = dict() if options.listhosts or options.listtasks or options.listtags or options.syntax: self._tqm = None else: self._tqm = TaskQueueManager(inventory=inventory, variable_manager=variable_manager, loader=loader, options=options, passwords=self.passwords, stdout_callback=CallbackModule())
def runCmd(name, target, module, arg, sudo, forks): # initialize needed objects variable_manager = VariableManager() loader = DataLoader() Options = namedtuple('Options', [ 'listtags', 'listtasks', 'listhosts', 'syntax', 'connection', 'module_path', 'forks', 'remote_user', 'private_key_file', 'ssh_common_args', 'ssh_extra_args', 'sftp_extra_args', 'scp_extra_args', 'become', 'become_method', 'become_user', 'verbosity', 'check' ]) pb_options = Options(listtags=False, listtasks=False, listhosts=False, syntax=False, connection='ssh', module_path=None, forks=forks, remote_user='******', private_key_file=None, ssh_common_args=None, ssh_extra_args=None, sftp_extra_args=None, scp_extra_args=None, become=sudo, become_method='sudo', become_user='******', verbosity=None, check=False) passwords = {} # create inventory and pass to var manager inventory = Inventory(loader=loader, variable_manager=variable_manager) variable_manager.set_inventory(inventory) # create play with tasks play_source = dict( name=name, # likes this "taskname#taskid_123@projectname", hosts=target, gather_facts='no', tasks=[dict(action=dict(module=module, args=arg))]) play = Play().load(play_source, variable_manager=variable_manager, loader=loader) tqm = None try: tqm = TaskQueueManager( inventory=inventory, variable_manager=variable_manager, loader=loader, options=pb_options, passwords=passwords, stdout_callback=CallbackModule(), ) rc = tqm.run(play) d = DetailProcess(tqm._prst) finally: if tqm is not None: tqm.cleanup() return {'rc': rc, 'detail': d.run()}
def run_cmd(name, host_list, module, arg, sudo, forks): sources = ','.join(host_list) if len(host_list) == 1: sources += ',' # initialize needed objects Options = namedtuple('Options', [ 'connection', 'module_path', 'forks', 'remote_user', 'private_key_file', 'ssh_common_args', 'ssh_extra_args', 'sftp_extra_args', 'scp_extra_args', 'become', 'become_method', 'become_user', 'verbosity', 'check', 'diff' ]) loader = DataLoader() options = Options(connection='ssh', module_path=None, forks=forks, remote_user="******", private_key_file=None, ssh_common_args=None, ssh_extra_args=None, sftp_extra_args=None, scp_extra_args=None, become=sudo, become_method='sudo', become_user='******', verbosity=None, check=False, diff=False) passwords = dict() # create inventory and pass to var manager inventory = InventoryManager(loader=loader, sources=sources) variable_manager = VariableManager(loader=loader, inventory=inventory) check_raw = module in ('command', 'shell', 'script', 'raw') # create play with tasks play_source = dict( name=name, # likes this "taskname#taskid_123@projectname", hosts=host_list, gather_facts='no', tasks=[ dict(action=dict(module=module, args=parse_kv(arg, check_raw=check_raw))) ]) play = Play().load(play_source, variable_manager=variable_manager, loader=loader) tqm = None try: tqm = TaskQueueManager( inventory=inventory, variable_manager=variable_manager, loader=loader, options=options, passwords=passwords, stdout_callback=CallbackModule(), ) rc = tqm.run(play) detail = tqm._stdout_callback.std_lines finally: if tqm is not None: tqm.cleanup() return {'rc': rc, 'detail': detail}