当前位置: 首页>>代码示例>>Python>>正文


Python PlaybookExecutor.run方法代码示例

本文整理汇总了Python中ansible.executor.playbook_executor.PlaybookExecutor.run方法的典型用法代码示例。如果您正苦于以下问题:Python PlaybookExecutor.run方法的具体用法?Python PlaybookExecutor.run怎么用?Python PlaybookExecutor.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ansible.executor.playbook_executor.PlaybookExecutor的用法示例。


在下文中一共展示了PlaybookExecutor.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ansible_task

# 需要导入模块: from ansible.executor.playbook_executor import PlaybookExecutor [as 别名]
# 或者: from ansible.executor.playbook_executor.PlaybookExecutor import run [as 别名]
def ansible_task(playbooks):
    Options = namedtuple('Options', \
    ['connection', 'module_path', 'forks', 'become', 'become_method', 'become_user', 'check', 'listhosts', 'listtasks', 'listtags', 'syntax'])

    options = Options(
        connection = 'ssh', 
        module_path = '/opt/ansible/modules',
        forks = 100, 
        become = True, 
        become_method = 'sudo', 
        become_user = 'root', 
        check = False, 
        listhosts = None,
        listtasks = None,
        listtags = None,
        syntax = None
    )

    loader = DataLoader()
    variable_manager = VariableManager()
    inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list='/opt/ansible/inventory')
    variable_manager.set_inventory(inventory)

    pb = PlaybookExecutor(playbooks=[playbooks], inventory=inventory, variable_manager=variable_manager, loader=loader, options=options, passwords=None)
    pb.run()

    stats = pb._tqm._stats
    ips = stats.processed.keys()
    return [ {ip : stats.summarize(ip)} for ip in ips ]
开发者ID:liujitao,项目名称:teamworkflow,代码行数:31,代码来源:views.py

示例2: PlayBook

# 需要导入模块: from ansible.executor.playbook_executor import PlaybookExecutor [as 别名]
# 或者: from ansible.executor.playbook_executor.PlaybookExecutor import run [as 别名]
class PlayBook(object):
    def __init__(self, playbook, inventory="inventory.py", extra_vars=None):
        basedir = os.path.abspath(os.path.dirname(__file__))
        self.playbook = os.path.join(basedir, playbook)
        self.options = Options(
            inventory=inventory,
            sudo=False, su=False, sudo_user=None, su_user=None,
            listtags=False, listtasks=False, listhosts=False,
            syntax=False, check=False,
            ask_pass=False,ask_su_pass=False,ask_sudo_pass=False,ask_vault_pass=False,
            connection='smart', timeout=10, remote_user=None, private_key_file=None,
            ssh_common_args=None, ssh_extra_args=None,
            sftp_extra_args=None, scp_extra_args=None,
            module_path=None, forks=5,
            become=False, become_method='sudo', become_user=None,
            verbosity=0)
        self.loader = DataLoader()
        self.variable_manager = VariableManager()
        self.variable_manager.extra_vars = extra_vars
        self.inventory = Inventory(loader=self.loader,
                                   variable_manager=self.variable_manager,
                                   host_list=inventory)
        self.pbex = PlaybookExecutor(playbooks=[self.playbook],
                                     inventory=self.inventory,
                                     loader=self.loader,
                                     variable_manager=self.variable_manager,
                                     options=self.options,
                                     passwords={'become_pass': None})

    def run(self):
        self.pbex.run()
        stats = self.pbex._tqm._stats
        self.pbex._tqm.send_callback('human_log')
        return stats
开发者ID:nxintech,项目名称:Charlie,代码行数:36,代码来源:playbook_api.py

示例3: playbook_api

# 需要导入模块: from ansible.executor.playbook_executor import PlaybookExecutor [as 别名]
# 或者: from ansible.executor.playbook_executor.PlaybookExecutor import run [as 别名]
 def playbook_api(self,yml_fp):
     loader = DataLoader()
     variable_manager = VariableManager()
     
     inventory = Inventory(
         loader=loader,
         variable_manager=variable_manager,
         host_list=self.ansible_host_list
     )
     
     variable_manager.set_inventory(inventory)
     
     playbooks = ["%s" % yml_fp]
     
     pbex = PlaybookExecutor(
                   playbooks=playbooks,
                   inventory=inventory,
                   variable_manager=variable_manager,
                   loader=loader,
                   options=self.options,
                   passwords=self.passwords
             )
                   
     callback = AnsiCallBack()
     pbex._tqm._stdout_callback = callback
     pbex.run()
     
     return self.evaluate_results(callback)
开发者ID:527593036,项目名称:AnsiApi,代码行数:30,代码来源:ansi2v.py

示例4: run_playbook

# 需要导入模块: from ansible.executor.playbook_executor import PlaybookExecutor [as 别名]
# 或者: from ansible.executor.playbook_executor.PlaybookExecutor import run [as 别名]
    def run_playbook(self, hosts, playbook_path):
        """ 
        run ansible palybook 
        """
        global tasklist
        tasklist = {}
        for host in hosts:
            tasklist[host] = {}
            tasklist[host]['ok'] = []
            tasklist[host]['failed'] = []
            tasklist[host]['skppied'] = []

        self.results_callback = PlayBookResultCallback(tasklist)
        try:
            executor = PlaybookExecutor(
                playbooks=[playbook_path],
                inventory=self.inventory,
                variable_manager=self.variable_manager,
                loader=self.loader,
                options=self.options,
                passwords=self.passwords)
            executor._tqm._stdout_callback = self.results_callback
            executor.run()
        except Exception as e:
            print(e)
            return False
开发者ID:boer0924,项目名称:deploy,代码行数:28,代码来源:remoteshell.py

示例5: run_playbook

# 需要导入模块: from ansible.executor.playbook_executor import PlaybookExecutor [as 别名]
# 或者: from ansible.executor.playbook_executor.PlaybookExecutor import run [as 别名]
    def run_playbook(self, host_list, role_name, role_uuid, temp_param):
        """
        run ansible palybook
        """
        try:
            self.callback = ResultsCollector()
            filenames = [BASE_DIR + '/handlers/ansible/v1_0/sudoers.yml']
            logger.info('ymal file path:%s'% filenames)
            template_file = TEMPLATE_DIR
            if not os.path.exists(template_file):
                logger.error('%s 路径不存在 '%template_file)
                sys.exit()

            extra_vars = {}
            host_list_str = ','.join([item for item in host_list])
            extra_vars['host_list'] = host_list_str
            extra_vars['username'] = role_name
            extra_vars['template_dir'] = template_file
            extra_vars['command_list'] = temp_param.get('cmdList')
            extra_vars['role_uuid'] = 'role-%s'%role_uuid
            self.variable_manager.extra_vars = extra_vars
            logger.info('playbook 额外参数:%s'%self.variable_manager.extra_vars)
            # actually run it
            executor = PlaybookExecutor(
                playbooks=filenames, inventory=self.inventory, variable_manager=self.variable_manager, loader=self.loader,
                options=self.options, passwords=self.passwords,
            )
            executor._tqm._stdout_callback = self.callback
            executor.run()
        except Exception as e:
            logger.error("run_playbook:%s"%e)
开发者ID:AutoOps,项目名称:MagicStack-Proxy,代码行数:33,代码来源:ansible_play.py

示例6: __init__

# 需要导入模块: from ansible.executor.playbook_executor import PlaybookExecutor [as 别名]
# 或者: from ansible.executor.playbook_executor.PlaybookExecutor import run [as 别名]
    def __init__(self, **kwargs):
        super(Ansible_playbook, self).__init__(**kwargs)

        self.task_file = kwargs.get('task_file', None)
        self.sudo = kwargs.get('sudo', False)
        self.sudo_user = kwargs.get('sudo_user', False)
        self.sudo_password = kwargs.get('sudo_password', False)

        # check if parameters have been provided
        if self._is_parameters_ok():

            variable_manager = VariableManager()
            loader = DataLoader()
            options = self._get_options()
            passwords = {'become_pass': self.sudo_password}

            inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list="localhost")
            variable_manager.set_inventory(inventory)
            playbooks = [self.task_file]

            executor = PlaybookExecutor(
                playbooks=playbooks,
                inventory=inventory,
                variable_manager=variable_manager,
                loader=loader,
                options=options,
                passwords=passwords)

            executor.run()
开发者ID:igorstarki,项目名称:kalliope,代码行数:31,代码来源:ansible_playbook.py

示例7: _run_playbook

# 需要导入模块: from ansible.executor.playbook_executor import PlaybookExecutor [as 别名]
# 或者: from ansible.executor.playbook_executor.PlaybookExecutor import run [as 别名]
 def _run_playbook(self, playbook):
     self.options = options = self.Options(**self.options_args)
     vm = self.variable_manager
     vm.extra_vars = load_extra_vars(loader=self.loader, options=options)
     pbe = PlaybookExecutor(
         playbooks=[playbook],
         inventory=self.inventory,
         variable_manager=vm,
         loader=self.loader,
         options=options,
         passwords=dict(),
     )
     pbe.run()
     return vm.get_vars(self.loader)
开发者ID:Zempashi,项目名称:stratus,代码行数:16,代码来源:ansible_helper.py

示例8: run

# 需要导入模块: from ansible.executor.playbook_executor import PlaybookExecutor [as 别名]
# 或者: from ansible.executor.playbook_executor.PlaybookExecutor import run [as 别名]
    def run(self):
        executor = PlaybookExecutor(
            playbooks=[self.playbook_path],
            inventory=self.inventory,
            variable_manager=self.variable_manager,
            loader=self.loader,
            options=self.options,
            passwords=self.passwords
        )

        if executor._tqm:
            executor._tqm._stdout_callback = self.results_callback
        executor.run()
        executor._tqm.cleanup()
        return self.results_callback.output
开发者ID:achachadra7,项目名称:jumpserver,代码行数:17,代码来源:runner.py

示例9: run

# 需要导入模块: from ansible.executor.playbook_executor import PlaybookExecutor [as 别名]
# 或者: from ansible.executor.playbook_executor.PlaybookExecutor import run [as 别名]
    def run(self):
        executor = PlaybookExecutor(
            playbooks=[self.playbook_path],
            inventory=self.inventory,
            variable_manager=self.variable_manager,
            loader=self.loader,
            passwords={"conn_pass": self.passwords}
        )
        context.CLIARGS = ImmutableDict(self.options)

        if executor._tqm:
            executor._tqm._stdout_callback = self.results_callback
        executor.run()
        executor._tqm.cleanup()
        return self.results_callback.output
开发者ID:jumpserver,项目名称:jumpserver,代码行数:17,代码来源:runner.py

示例10: run

# 需要导入模块: from ansible.executor.playbook_executor import PlaybookExecutor [as 别名]
# 或者: from ansible.executor.playbook_executor.PlaybookExecutor import run [as 别名]
 def run(self, log):
     if not self.playbook:
         code = 999
         simple = 'playbook must exist'
         return code, simple, None
     if log:
         log_file.append(log)
     if not os.path.exists(self.playbook):
         code = 1000
         results = 'not exists playbook: ' + self.playbook
         return code, results, None
     pbex = PlaybookExecutor(playbooks=[self.playbook],
                             inventory=self.inventory,
                             variable_manager=self.variable_manager,
                             loader=self.loader,
                             options=self.options,
                             passwords=self.passwords)
     try:
         code = pbex.run()
     except AnsibleParserError:
         code = 1001
         results = 'syntax problems in ' + self.playbook
         return  code, results, None
     stats = pbex._tqm._stats
     hosts = sorted(stats.processed.keys())
     results = [{h: stats.summarize(h)} for h in hosts]
     if not results:
         code = 1002
         results = 'no host executed in ' + self.playbook
         return  code, results, None
     complex = '\n'.join(log_add)
     return code, results, complex
开发者ID:stanleylst,项目名称:ansibleUI,代码行数:34,代码来源:Ansi_play2.py

示例11: run

# 需要导入模块: from ansible.executor.playbook_executor import PlaybookExecutor [as 别名]
# 或者: from ansible.executor.playbook_executor.PlaybookExecutor import run [as 别名]
    def run(self, playbooks, limit=''):
        """
        param: `playbooks`: type string or list, example: ['/etc/ansible/test.yml'], '/etc/ansible/test1.yml, /etc/ansible/test2.yml'
        param: `limit`:  eq --limit ''
        """
        self._prepare_run()

        results = 0

        if isinstance(playbooks, basestring):
            if ',' in playbooks:
                playbooks = [pl.strip() for pl in playbooks.split(',') if os.path.exists(pl)]
            else:
                playbooks = [playbooks.strip()]

        # --limit
        if limit:
            self.inventory.subset(limit)

        try:
            # create the playbook executor, which manages running the plays via a task queue manager
            pbex = PlaybookExecutor(playbooks=playbooks, inventory=self.inventory,
                                    variable_manager=self.variable_manager,
                                    loader=self.loader, options=self.options, passwords=self.passwords)

            results = pbex.run()
        except Exception, ex:
            results = str(ex)
开发者ID:sunyaxiong,项目名称:mygit,代码行数:30,代码来源:ans_ui2_share.py

示例12: runPlaybook

# 需要导入模块: from ansible.executor.playbook_executor import PlaybookExecutor [as 别名]
# 或者: from ansible.executor.playbook_executor.PlaybookExecutor import run [as 别名]
  def runPlaybook(self):
    sys.stdout = open('Output-pythonAnsible','w')
    variable_manager = VariableManager()
    loader = DataLoader()

    inventory = Inventory(loader=loader, variable_manager=variable_manager,  host_list=self.host_list)
    #self.playbook_path
    #playbook_path = '/home/davis/Documents/Network-automation/cisco_xe.yml'

    if not os.path.exists(self.playbook_path):
        print '[INFO] The playbook does not exist'
        sys.exit()

    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'])
    options = Options(listtags=False, listtasks=False, listhosts=False, syntax=False, connection='ssh', module_path=None, forks=100, remote_user='slotlocker', private_key_file=None, ssh_common_args=None, ssh_extra_args=None, sftp_extra_args=None, scp_extra_args=None, become=True, become_method=None, become_user='root', verbosity=None, check=False)

    #variable_manager.extra_vars = {'hosts': 'mywebserver'} # This can accomodate various other command line arguments.`

    passwords = {}

    pbex = PlaybookExecutor(playbooks=[self.playbook_path], inventory=inventory, variable_manager=variable_manager, loader=loader, options=options, passwords=passwords)

    results = pbex.run()

    print "Output ::-",results
    return results
开发者ID:davismathew,项目名称:netautgui,代码行数:28,代码来源:runplaybook.py

示例13: PlayBook

# 需要导入模块: from ansible.executor.playbook_executor import PlaybookExecutor [as 别名]
# 或者: from ansible.executor.playbook_executor.PlaybookExecutor import run [as 别名]
class PlayBook(object):
    def __init__(self, inventory='/etc/ansible/hosts', extra_vars=None, private_key_file=None):
        """
        :param playbook: playbook.yml
        :param inventory: inventory file or script
        :type param extra_vars: dict
        :param private_key_file: ssh private key
        """
        self.pbex = None
        self.options = Options(private_key_file=private_key_file, connection='smart', forks=10, timeout=10,
                               verbosity=0, check=False,
                               listtasks=False, listhosts=False, syntax=False,
                               subset=None, module_path=None, become=None, become_user=None, become_method='sudo')

        # initialize needed objects
        self.loader = DataLoader()
        self.variable_manager = VariableManager()
        self.variable_manager.extra_vars = extra_vars
        self.variable_manager.options_vars = {'ansible_check_mode': self.options.check}
        self.inventory = Inventory(loader=self.loader, variable_manager=self.variable_manager, host_list=inventory)
        self.variable_manager.set_inventory(self.inventory)
        # Limits inventory results to a subset of inventory that matches a given pattern
        self.inventory._subset = self.options.subset

    def run_playbook(self, playbook):
        self.pbex = PlaybookExecutor(playbooks=[playbook], inventory=self.inventory,
                                     variable_manager=self.variable_manager,
                                     loader=self.loader, options=self.options,
                                     passwords={'conn_pass': None, 'become_pass': None})
        self.pbex._tqm._stdout_callback = ResultCallback()
        return self.pbex.run()

    def run_play(self, play):
        pass
开发者ID:nxintech,项目名称:Charlie,代码行数:36,代码来源:playbook_api2.py

示例14: pbexe

# 需要导入模块: from ansible.executor.playbook_executor import PlaybookExecutor [as 别名]
# 或者: from ansible.executor.playbook_executor.PlaybookExecutor import run [as 别名]
def pbexe(userid,serial,host,module,apppath,yaml,url=None):
    variable_manager = VariableManager()
    loader = DataLoader()
    hostfile = '/ansible/hosts'
    inventory = Inventory(loader=loader, variable_manager=variable_manager,host_list='/ansible/hosts')
    playbook_path = yaml

    if not os.path.exists(playbook_path):
        print playbook_path
        print '[INFO] The playbook does not exist'
        sys.exit()

    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'])
    options = Options(listtags=False, listtasks=False, listhosts=False, syntax=False, connection='ssh', module_path=None, forks=100, remote_user='root', private_key_file=None, ssh_common_args=None, ssh_extra_args=None, sftp_extra_args=None, scp_extra_args=None, become=True, become_method=None, become_user='root', verbosity=None, check=False)

    variable_manager.extra_vars = {
            'host': host,
            'module': module,
            'tomcat_root': apppath,
            'url': url
} # This can accomodate various other command line arguments.`
    passwords = {}
    cb = CallbackModule(serial)
#  cb = default.CallbackModule()
    pbex = PlaybookExecutor( playbooks=[playbook_path],  inventory=inventory, variable_manager=variable_manager, loader=loader, options=options, passwords=passwords)
    pbex._tqm._stdout_callback = cb
    results = pbex.run()
    return results
开发者ID:zabbixfan,项目名称:manatee,代码行数:30,代码来源:playbooktask.py

示例15: run

# 需要导入模块: from ansible.executor.playbook_executor import PlaybookExecutor [as 别名]
# 或者: from ansible.executor.playbook_executor.PlaybookExecutor import run [as 别名]
	def run(self,mission_id,role_name,exe_group):			
                '''
		 create play with tasks actually run it
		'''
		tqm = None
		try:
                        retry_path = '/etc/ansible/main.yml'
			inventory_path = [retry_path]
			self.results_callback = ResultCallback()
                        extra_vars = {}
			extra_vars['host_list'] = exe_group
			extra_vars['role_name'] = role_name
			extra_vars['run_id'] = mission_id
			self.variable_manager.extra_vars = extra_vars
    			pbex = PlaybookExecutor(
              			playbooks=inventory_path, 
              			inventory=self.inventory, 
              			variable_manager=self.variable_manager, 
              			loader=self.loader, 
              			options=self.options, 
              			passwords=self.passwords,
          		)

    			pbex._tqm._stdout_callback = self.results_callback
    			result = pbex.run()
		finally:
    			if tqm is not None:
        			tqm.cleanup()
开发者ID:EvenStone,项目名称:devops,代码行数:30,代码来源:playbook.py


注:本文中的ansible.executor.playbook_executor.PlaybookExecutor.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。