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


Python playbook_executor.PlaybookExecutor类代码示例

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


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

示例1: run

	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,代码行数:28,代码来源:playbook.py

示例2: pbexe

def pbexe(sid,war,mode):
  variable_manager = VariableManager()
  loader = DataLoader()

#  inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=[])
  inventory = Inventory(loader=loader, variable_manager=variable_manager)
  playbook_path = '/etc/ansible/yml/'+sid+'.yml'

  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 = {'war': war,'mode': mode} # This can accomodate various other command line arguments.`

  passwords = {}

  #cb = ResultCallback()
#  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
  op=sys.stdout

  filename='/var/log/ansible/'+time.strftime('%Y%m%d%H%M%S')+'.log'
  opf=open(filename,'w')
  sys.stdout=opf
  results = pbex.run()
  sys.stdout=op
  opf.close
  print open(filename,'r').read()
  return filename
开发者ID:zabbixfan,项目名称:manatee,代码行数:34,代码来源:pb3.py

示例3: runPlaybook

  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,代码行数:26,代码来源:runplaybook.py

示例4: run_playbook

def run_playbook():
    playbooks = ['/Users/CYu/Code/Python/python-demo/demo_ansible/playbook.yml']  # 这里是一个列表, 因此可以运行多个playbook
    variable_manager.extra_vars = {"ansible_ssh_user": "root", "ansible_ssh_pass": "xxx"}  # 增加外部变量
    pb = PlaybookExecutor(playbooks=playbooks, inventory=inventory, variable_manager=variable_manager, loader=loader,
                          options=options, passwords=None)
    result = pb.run()
    print result
开发者ID:cuyu,项目名称:python-demo,代码行数:7,代码来源:tmp.py

示例5: pbexe

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,代码行数:28,代码来源:playbooktask.py

示例6: PlayBook

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,代码行数:34,代码来源:playbook_api.py

示例7: test_init

 def test_init(self):
     """
     Initialises and runs sample echo playbook for testing
     """
     path = os.path.realpath(__file__).split("/")[0:-1]
     path = "/".join(path)
     playbook_path = path+'/playbooks/test_playbook.yml'
     options = self.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=3,
                       check=False)
     self.variable_manager.extra_vars = {'hosts': 'mywebserver'}
     passwords = {}
     pbex = PlaybookExecutor(playbooks=[playbook_path],
                             inventory=self.inventory,
                             variable_manager=self.variable_manager,
                             loader=self.loader,
                             options=options,
                             passwords=passwords)
     results = pbex.run()
     assert_equal(results, 0)
开发者ID:greg-hellings,项目名称:linch-pin,代码行数:35,代码来源:test_linchpin_env.py

示例8: playbook_api

 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,代码行数:28,代码来源:ansi2v.py

示例9: ansible_task

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,代码行数:29,代码来源:views.py

示例10: run

    def run(self):

        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', 'diff'])
        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, diff=False)
        #OPTION_FLAGS = ('connection', 'remote_user', 'private_key_file', 'verbosity', 'force_handlers', 'step', 'start_at_task', 'diff',
        #        'ssh_common_args', 'docker_extra_args', 'sftp_extra_args', 'scp_extra_args', 'ssh_extra_args')
        passwords = {}

        pbex = PlaybookExecutor(playbooks=[self.playbook],
                                inventory=self.inventory,
                                variable_manager=self.variable_manager,
                                loader=self.loader,
                                options=options,
                                passwords=passwords)
        result = pbex.run()
        return result
开发者ID:openshift,项目名称:svt,代码行数:27,代码来源:network-test.py

示例11: run_playbook

    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,代码行数:31,代码来源:ansible_play.py

示例12: __init__

    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,代码行数:29,代码来源:ansible_playbook.py

示例13: run_playbook

    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,代码行数:26,代码来源:remoteshell.py

示例14: run_playbook

def run_playbook(playbook_path, cluster):
    playbook_file = '{playbook_path}/provision/site.yml'.format(
        playbook_path=playbook_path,
    )
    loader = DataLoader()
    variable_manager = VariableManager()
    inventory = Inventory(
        loader=loader,
        variable_manager=variable_manager,
        host_list=get_host_list(playbook_path, cluster),
    )
    file_handle, private_key_file = mkstemp(dir=playbook_path)
    with open(private_key_file, 'w') as key_file:
        key_file.write(cluster.sshKey)
    options = Options(
        inventory=inventory,
        remote_user=cluster.username,
        private_key_file=private_key_file,
    )
    executor = PlaybookExecutor(
        playbooks=[playbook_file],
        inventory=inventory,
        variable_manager=variable_manager,
        loader=loader,
        options=options,
        passwords={
            'become_pass': 'vagrant',
        },
    )
    return executor.run()
开发者ID:mlrdk,项目名称:backend,代码行数:30,代码来源:provision.py

示例15: run

 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,代码行数:32,代码来源:Ansi_play2.py


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