當前位置: 首頁>>代碼示例>>Python>>正文


Python playbook.PlayBook方法代碼示例

本文整理匯總了Python中ansible.playbook.PlayBook方法的典型用法代碼示例。如果您正苦於以下問題:Python playbook.PlayBook方法的具體用法?Python playbook.PlayBook怎麽用?Python playbook.PlayBook使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ansible.playbook的用法示例。


在下文中一共展示了playbook.PlayBook方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: from ansible import playbook [as 別名]
# 或者: from ansible.playbook import PlayBook [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: run

# 需要導入模塊: from ansible import playbook [as 別名]
# 或者: from ansible.playbook import PlayBook [as 別名]
def run(self, task, playbook, extra_vars=None, check=False):
        stats = MyAggregateStats()
        playbook_callback = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
        runner_callback = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)
        abs_playbook_path = os.path.join(current_app.config['ANSIBLE_PLAYBOOKS_DIR'], playbook)

        pb = PlayBook(
            playbook=abs_playbook_path,
            stats=stats,
            callbacks=playbook_callback,
            runner_callbacks=runner_callback,
            inventory=self.inventory,
            extra_vars=extra_vars,
            check=check,
        )
        self.result_raw = pb.run()
        self.result_raw['celery_task_id'] = task
        log_redis(self.result_raw)
        return self.result_raw 
開發者ID:Erazx,項目名稱:ansible_api,代碼行數:21,代碼來源:ansible_api.py

示例3: adduser

# 需要導入模塊: from ansible import playbook [as 別名]
# 或者: from ansible.playbook import PlayBook [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

示例4: run

# 需要導入模塊: from ansible import playbook [as 別名]
# 或者: from ansible.playbook import PlayBook [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

示例5: playbook_run

# 需要導入模塊: from ansible import playbook [as 別名]
# 或者: from ansible.playbook import PlayBook [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

示例6: Playbook

# 需要導入模塊: from ansible import playbook [as 別名]
# 或者: from ansible.playbook import PlayBook [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

示例7: playbook

# 需要導入模塊: from ansible import playbook [as 別名]
# 或者: from ansible.playbook import PlayBook [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.playbook.PlayBook方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。