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


Python callbacks.AggregateStats方法代码示例

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


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

示例1: run

# 需要导入模块: from ansible import callbacks [as 别名]
# 或者: from ansible.callbacks import AggregateStats [as 别名]
def run(self, playbook_relational_path, extra_vars=None):
        """
        run ansible playbook,
        only surport relational path.
        """
        stats = callbacks.AggregateStats()
        playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
        runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)
        playbook_path = os.path.join(ANSIBLE_DIR, playbook_relational_path)

        pb = PlayBook(
            playbook=playbook_path,
            stats=stats,
            callbacks=playbook_cb,
            runner_callbacks=runner_cb,
            inventory=self.inventory,
            extra_vars=extra_vars,
            check=False)

        self.results = pb.run() 
开发者ID:sgr-smile2015,项目名称:server,代码行数:22,代码来源:ansible_api.py

示例2: conf

# 需要导入模块: from ansible import callbacks [as 别名]
# 或者: from ansible.callbacks import AggregateStats [as 别名]
def conf(self):
        stats = callbacks.AggregateStats()
        playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
        runner_cb = callbacks.DefaultRunnerCallbacks()
        res = ansible.playbook.PlayBook(
                    playbook = self.playbook, #'/etc/ansible/playbooks/user.yml',
                    stats = stats,#??????
                    callbacks = playbook_cb,
                    runner_callbacks = runner_cb,
                    host_list = self.host_list,
                    extra_vars = self.module_args
            ).run()
        data = json.dumps(res,indent=4)
        data_list = []    
        for k,v in json.loads(data).items():
            data = {} 
            for x,y in v.items():  
                data['ip'] = k 
                data[x] = y
            data_list.append(data)   
        if data_list:
            return  data_list
        else:
            return False 
开发者ID:welliamcao,项目名称:OpsManage,代码行数:26,代码来源:ansible_api_v1.py

示例3: run_playbook

# 需要导入模块: from ansible import callbacks [as 别名]
# 或者: from ansible.callbacks import AggregateStats [as 别名]
def run_playbook(**kwargs):

    stats = callbacks.AggregateStats()
    playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
    runner_cb = callbacks.PlaybookRunnerCallbacks(
        stats, verbose=utils.VERBOSITY)

    # use /tmp instead of $HOME
    ansible.constants.DEFAULT_REMOTE_TMP = '/tmp/ansible'

    out = ansible.playbook.PlayBook(
        callbacks=playbook_cb,
        runner_callbacks=runner_cb,
        stats=stats,
        **kwargs
    ).run()

    return out 
开发者ID:lordmuffin,项目名称:aws-cfn-plex,代码行数:20,代码来源:ansible.py

示例4: adduser

# 需要导入模块: from ansible import callbacks [as 别名]
# 或者: from ansible.callbacks import AggregateStats [as 别名]
def adduser(ips, users):
    inventory ="""
    {% for i in hosts -%}
    {{ i }}
    {% endfor %}
    """
    inventory_template = jinja2.Template(inventory)
    rendered_inventory = inventory_template.render({'hosts': ips})
    hosts = NamedTemporaryFile(delete=False,suffix='tmp',dir='/tmp/ansible/')
    hosts.write(rendered_inventory)
    hosts.close()
    inventory = Inventory(hosts.name)
    stats =  callbacks.AggregateStats()
    playbook_cb =callbacks.PlaybookCallbacks()
    runner_cb   =callbacks.PlaybookRunnerCallbacks(stats)
    vars={}
    vars['users'] = users
    results = PlayBook(playbook='user.yaml',callbacks=playbook_cb,runner_callbacks=runner_cb,stats=stats,inventory=inventory,extra_vars=vars)
    res = results.run()
    logs = []
    logs.append("finish playbook\n")
    logs.append(str(res))
    return  logs 
开发者ID:shencan,项目名称:Ansible-Book-Code,代码行数:25,代码来源:flask-celery-server.py

示例5: run

# 需要导入模块: from ansible import callbacks [as 别名]
# 或者: from ansible.callbacks import AggregateStats [as 别名]
def run(self, playbook_relational_path, extra_vars=None):
        """
        run ansible playbook,
        only surport relational path.
        """
        stats = callbacks.AggregateStats()
        playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
        runner_cb = callbacks.PlaybookRunnerCallbacks(
            stats, verbose=utils.VERBOSITY)
        playbook_path = os.path.join(ANSIBLE_DIR, playbook_relational_path)

        pb = PlayBook(
            playbook=playbook_path,
            stats=stats,
            callbacks=playbook_cb,
            runner_callbacks=runner_cb,
            inventory=self.inventory,
            extra_vars=extra_vars,
            check=False)

        self.results = pb.run() 
开发者ID:xiaomatech,项目名称:ops,代码行数:23,代码来源:jumserver.py

示例6: playbook_run

# 需要导入模块: from ansible import callbacks [as 别名]
# 或者: from ansible.callbacks import AggregateStats [as 别名]
def playbook_run(inventory, playbook, default_user=None, default_port=None, default_pri_key_path=None):
    stats = callbacks.AggregateStats()
    playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
    runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)
    # run the playbook
    print default_user, default_port, default_pri_key_path, inventory, playbook
    if default_user and default_port and default_pri_key_path:
        playbook = PlayBook(host_list=inventory,
                            playbook=playbook,
                            forks=5,
                            remote_user=default_user,
                            remote_port=default_port,
                            private_key_file=default_pri_key_path,
                            callbacks=playbook_cb,
                            runner_callbacks=runner_cb,
                            stats=stats,
                            become=True,
                            become_user='root')
    else:
        playbook = PlayBook(host_list=inventory,
                            playbook=playbook,
                            forks=5,
                            callbacks=playbook_cb,
                            runner_callbacks=runner_cb,
                            stats=stats,
                            become=True,
                            become_user='root')
    results = playbook.run()
    print results
    results_r = {'unreachable': [], 'failures': [], 'success': []}
    for hostname, result in results.items():
        if result.get('unreachable', 2):
            results_r['unreachable'].append(hostname)
            print "%s >>> unreachable" % hostname
        elif result.get('failures', 2):
            results_r['failures'].append(hostname)
            print "%s >>> Failed" % hostname
        else:
            results_r['success'].append(hostname)
            print "%s >>> Success" % hostname
    return results_r 
开发者ID:Mr-Linus,项目名称:geekcloud,代码行数:43,代码来源:tasks.py

示例7: Playbook

# 需要导入模块: from ansible import callbacks [as 别名]
# 或者: from ansible.callbacks import AggregateStats [as 别名]
def Playbook():
    vars={}
    inventory = Inventory(hostfile)
    stats =  callbacks.AggregateStats()
    playbook_cb =callbacks.PlaybookCallbacks()
    runner_cb   =callbacks.PlaybookRunnerCallbacks(stats)
    hosts=request.args.get('ip')
    task=request.args.get('playbook')
    vars['hosts'] = hosts
    play=task + '.yml'
    results = PlayBook(playbook=play,callbacks=playbook_cb,runner_callbacks=runner_cb,stats=stats,inventory=inventory,extra_vars=vars)
    res = results.run()
    return json.dumps(res,indent=4) 
开发者ID:shencan,项目名称:Ansible-Book-Code,代码行数:15,代码来源:flask-api.py

示例8: playbook

# 需要导入模块: from ansible import callbacks [as 别名]
# 或者: from ansible.callbacks import AggregateStats [as 别名]
def playbook():
    inventory = """
    [initial]
    {% for i in hosts %}
    {{ i }}
    {% endfor %}
    """
    
    inventory_template = jinja2.Template(inventory)
    #inst_ip  = [ i.encode('ascii') for i in request.form['ips']]
    #ips = [  i for i in request.form.getlist("ips") ]
    #inst_ip = request.form.get('ips')
    #inst_ip = json.loads(request.form.getlist('ips'))
    #inst_ip  = [ i.encode('ascii') for i in request.form.getlist('ips') ]
    #print inst_ip
    #print request.form
    print request.get_data()
    #data = request.get_data()
    #inst_ip = request.form.getlist('ips[]')
    #print data 
    #inst_ip = data['ips']
    #inst_ip = request.form.getlist('ips')
    data = json.loads(request.get_data())
    inst_ip = data["ips"]
    print inst_ip
    #inst_ip = ["192.168.1.3","192.168.1.4","192.168.1.5"]
    rendered_inventory = inventory_template.render({'hosts':inst_ip})
    hosts = NamedTemporaryFile(delete=False,suffix='tmp',dir='/tmp/ansible/')
    hosts.write(rendered_inventory)
    hosts.close()
    inventory = Inventory(hosts.name)
    print inventory

    vars = {}
    stats = callbacks.AggregateStats()
    playbook_cb = callbacks.PlaybookCallbacks()
    runner_cb = callbacks.PlaybookRunnerCallbacks(stats)
    # hosts = request.args.get('ip')
    # task = request.args.get('playbook')
    # vars['hosts'] = hosts
    # play = task + '.yml'
    pb = PlayBook(playbook='mytest.yml',callbacks=playbook_cb,runner_callbacks=runner_cb,stats=stats,inventory=inventory,extra_vars=vars)
    job = q.enqueue_call(pb.run, result_ttl=5000, timeout=2000)
    jid = job.get_id()
    if jid:
      app.logger.info("Job Succesfully Queued with JobID: %s" % jid)
    else:
      app.logger.error("Failed to Queue the Job")
    return jid 
开发者ID:yuhongchun,项目名称:devops,代码行数:51,代码来源:initialv0.1.py


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