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


Python playbook.PlayBook类代码示例

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


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

示例1: runPlayBook

def runPlayBook(path):
    stats = callbacks.AggregateStats()
    inven = Inventory(host_list=path["hosts"]);
    playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
    runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)
    pb = PlayBook(inventory=inven,playbook=path["playbook"],stats=stats,callbacks=playbook_cb,runner_callbacks=runner_cb,)
    pb.run()
开发者ID:anishashetty,项目名称:AnsiblePlaybook,代码行数:7,代码来源:runAnsible.py

示例2: run_installer

def run_installer(user_list, package_list, sudo_password):
    """
    Runs the playbook `installer.yml` with the supplied parameters
    """

    # Create the inventory
    controller = Host(name="localhost")
    controller.set_variable("users", user_list)
    controller.set_variable("apt_packages", package_list)
    local_inventory = Inventory([])
    local_inventory.get_group("all").add_host(controller)

    # Boilerplate for callbacks setup
    utils.VERBOSITY = 0
    # Output callbacks setup
    output_callbacks = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
    # API callbacks setup
    stats = callbacks.AggregateStats()
    api_callbacks = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)

    provision_playbook = PlayBook(
        playbook="installer.yml",
        stats=stats,
        callbacks=output_callbacks,
        runner_callbacks=api_callbacks,
        inventory=local_inventory,
        transport="local",
        become_pass=sudo_password,
    )
    playbook_result = provision_playbook.run()
    return playbook_result
开发者ID:lekum,项目名称:ee-ansible-with-python,代码行数:31,代码来源:installer.py

示例3: run_playbook

def run_playbook(dir, extra_vars):
    utils.VERBOSITY = 0
    playbook_cb = MyPlaybookCallbacks(verbose=utils.VERBOSITY)
    stats = callbacks.AggregateStats()
    runner_cb = MyPlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)

    inventory = """
[localhost]
localhost ansible_connection=local
"""

    # Create a temporary file and write the template string to it
    hosts = tempfile.NamedTemporaryFile(delete=False, dir=dir)
    hosts.write(inventory)
    hosts.close()

    pb = PlayBook(
        playbook=os.path.join(dir, "playbook.yml"),
        host_list=hosts.name,
        callbacks=playbook_cb,
        runner_callbacks=runner_cb,
        extra_vars=extra_vars,
        stats=stats
    )

    results = pb.run()

    # Ensure on_stats callback is called
    # for callback modules
    playbook_cb.on_stats(pb.stats)
    logger().info(results)
开发者ID:olgamelnichuk,项目名称:ngspyeasy,代码行数:31,代码来源:ngspyeasy_play_run.py

示例4: install_stuff

def install_stuff(ip_list, sshpass, req_list):
    task_id = str(install_stuff.request.id)
    db.write_in_progress(req_list, ip_list, task_id)
    pb_name = helper.write_playbook(req_list)

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

    pb = PlayBook(remote_user='rack',
        remote_pass=sshpass,
        playbook=pb_name,
        callbacks=playbook_cb,
        runner_callbacks=runner_cb,
        stats=stats,
        host_list=ip_list,
    )
    results = pb.run()
    if results[ip_list[:-1]]['unreachable'] != 0:
        os.remove(pb_name)
        db.del_in_progress(task_id)
        raise RuntimeError('df//' + ip_list[:-1] + '//' + '1' + '//fd')

    if results[ip_list[:-1]]['failures'] != 0:
        os.remove(pb_name)
        db.del_in_progress(task_id)
        raise RuntimeError('df//' + ip_list[:-1] + '//' + '1' + '//fd')

    os.remove(pb_name)
    db.del_in_progress(task_id)
    ans = '//' + ip_list[:-1] + '//0//'
    return ans
开发者ID:dev-ace,项目名称:build,代码行数:32,代码来源:tasks.py

示例5: gather_facts

def gather_facts(host, inventory=None):
    if inventory is None:
        inventory = get_inventory()

    # Gather facts
    try:

        # ... temporary playbook file
        playbook_file = tempfile.NamedTemporaryFile()
        playbook_file.write(SETUP_PLAYBOOK.format(host=host))
        playbook_file.seek(0)

        # ... run setup module
        stats = ansible.callbacks.AggregateStats()
        # callbacks = ansible.callbacks.PlaybookCallbacks(verbose=VERBOSITY)
        # runner_callbacks = ansible.callbacks.PlaybookRunnerCallbacks(
        #     stats, verbose=VERBOSITY)
        playbook = PlayBook(
            playbook=playbook_file.name,
            inventory=inventory,
            callbacks=Callbacks(),
            runner_callbacks=Callbacks(),
            stats=stats,
        )
        playbook.run()

    finally:
        playbook_file.close()

    return playbook.SETUP_CACHE
开发者ID:gregorycox,项目名称:ansible-toolkit,代码行数:30,代码来源:utils_ansible.py

示例6: aws

def aws(phase):
   #parse args
   with open("keys/rootkey.csv","r") as keyfile:
      lines = keyfile.readlines()
      aws_access_key = lines[0].split('=')[1].strip(' ').rstrip()
      aws_secret_key = lines[1].split('=')[1].strip(' ').rstrip()

   os.environ['AWS_ACCESS_KEY_ID']= aws_access_key
   os.environ['AWS_SECRET_ACCESS_KEY']= aws_secret_key
   
   d = deployment()
   red = redis.StrictRedis(host='localhost', port=6379, db=0)
   if phase == 0:
      print "Clean up stale reservations...*****************\n"
      d.destroy_aws_instance()
   if phase == 1:
      d.create_aws_instance()
      d.create_aws_instance()
      print "\nCheck AWS instance status...******************"
      aws_ip = d.get_aws_reservation()
      while aws_ip == None or len(aws_ip) < 2:
         print "AWS Instance not ready, retry after 30 sec"
         time.sleep(30)
         aws_ip = d.get_aws_reservation()
      canary = aws_ip[0]
      production = aws_ip[1]
      print "AWS Canary Instance =" + canary
      print "AWS Production Instance =" + production
      print "Update Redis"
      red.set('canary',"http://"+canary+":3000")
      red.set('production', "http://"+production+":3000")
      red.set('production0', "http://"+production+":3000")
      red.set('instances',1);
      print red.get('canary')
      print red.get('production')
      print "\nWriting Inventory...**************************"
      aws_inv_can = "canary ansible_ssh_host="+canary+" ansible_ssh_user=ubuntu ansible_ssh_private_key_file=./keys/devops.pem\n"
      with open("inventory_canary","w") as f:
         f.write(aws_inv_can)
      aws_inv_prod = "production ansible_ssh_host="+production+" ansible_ssh_user=ubuntu ansible_ssh_private_key_file=./keys/devops.pem\n"
      with open("inventory_production","w") as f:
         f.write(aws_inv_prod)
      with open("inventory", "w") as f:
         f.write(aws_inv_can+"\n")
         f.write(aws_inv_prod)
   if phase == 2:
      os.environ['ANSIBLE_HOST_KEY_CHECKING']="false"
      utils.VERBOSITY = 0
      playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
      stats = callbacks.AggregateStats()
      runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)
      inventory = Inventory('inventory')
      print "\nRun Ansible PlayBook...**********************"
      pb = PlayBook(playbook='server_play.yml',
              inventory=inventory,
              callbacks=playbook_cb,
              runner_callbacks=runner_cb,
              stats=stats
           )
      pb.run()	
开发者ID:gsrajadh,项目名称:Devops-Project,代码行数:60,代码来源:configure.py

示例7: gather_facts

def gather_facts(host, inventory=None, user=None):
    if inventory is None:
        inventory = get_inventory()

    # Gather facts
    try:

        # ... temporary playbook file
        playbook_file = tempfile.NamedTemporaryFile()
        playbook_file.write(SETUP_PLAYBOOK.format(host=host))
        playbook_file.seek(0)

        # ... run setup module
        stats = ansible.callbacks.AggregateStats()
        playbook = PlayBook(
            playbook=playbook_file.name,
            inventory=inventory,
            callbacks=Callbacks(),
            runner_callbacks=Callbacks(),
            remote_user=user or C.DEFAULT_REMOTE_USER,
            stats=stats,
        )
        results = playbook.run()

        # ... notify the user of failures
        for host, result in results.iteritems():
            if result.get('unreachable') or result.get('failures'):
                yellow('Unable to gather facts for host "{}"'.format(host))

    finally:
        playbook_file.close()

    return playbook.SETUP_CACHE
开发者ID:amiguez,项目名称:ansible-toolkit,代码行数:33,代码来源:utils_ansible.py

示例8: RunRecepie

def RunRecepie(inventory, playbook_file):
    """
    Run playbook

    :param hosts:
    :return:
    """
    # Boilerplace callbacks for stdout/stderr and log output
    utils.VERBOSITY = 0
    playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
    stats = callbacks.AggregateStats()
    runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)

    pb = PlayBook(
        playbook=playbook_file,
        inventory=inventory,
        callbacks=playbook_cb,
        runner_callbacks=runner_cb,
        stats=stats,
    )

    results = pb.run()

    # Ensure on_stats callback is called
    # for callback modules
    playbook_cb.on_stats(pb.stats)

    return results
开发者ID:eisen-dev,项目名称:eisen_engine,代码行数:28,代码来源:AnsibleV1Wrap.py

示例9: Test

 def Test(self,host):
     playbook = PlayBook(playbook='/Users/ezeng/Development/mesos-poc/vm_booting/playbook.yml',
                         # inventory=Inventory('/Users/ezeng/Development/mesos-poc/vm_booting/ansible/inventory'),
                         host_list=host.split(","),
                         callbacks=playbook_cb,
                         runner_callbacks=runner_cb,
                         stats=stats)
     playbook.run()
开发者ID:jiamaoweilie,项目名称:mesos-poc,代码行数:8,代码来源:Ansible.py

示例10: deploy_service

def deploy_service(username, passwd, hosts, extras):

	ruta = os.path.join(ROLESDIR, 'ansible-role-mailserver/site.yml')
	
	pb = PlayBook(playbook=ruta, sudo=True, sudo_pass=passwd, host_list=hosts,
		remote_user=username, extra_vars=extras, callbacks=playbook_cb,
		runner_callbacks=runner_cb, stats=stats)
	
	pb.run()
开发者ID:vpino,项目名称:kds,代码行数:9,代码来源:__init__.py

示例11: execute

def execute(taskexecution_id):
    from ansible.playbook import PlayBook
    from ansible.inventory import Inventory
    from ansible import callbacks
    from ansible import utils

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

    time.sleep(5)

    taskexecution = TaskExecution.objects.get(pk=taskexecution_id)
    taskexecution.start()
    taskexecution.save()

    inventory = "[local]\n\
localhost   ansible_connection=local\n\
\n\
[tasker]\n\
localhost\n\
\n\
[tasker:vars]\n\
taskexecution_id={}".format(taskexecution_id)

    hosts = NamedTemporaryFile(delete=False)
    hosts.write(inventory)
    hosts.close()

    pb = PlayBook(
        playbook='/tmp/main.yml',
        host_list=hosts.name,
        # remote_user='mskarbek',
        callbacks=playbook_cb,
        runner_callbacks=runner_cb,
        stats=stats,
        # private_key_file='/path/to/key.pem'
    )

    results = pb.run()

    playbook_cb.on_stats(pb.stats)

    os.remove(hosts.name)

    status = results.get('localhost')

    if status['failures'] > 0 or status['unreachable'] > 0:
        taskexecution.failed()
        taskexecution.save()
        return False

    taskexecution.succeed()
    taskexecution.save()
    return True
开发者ID:pombredanne,项目名称:ansible-tasker,代码行数:56,代码来源:tasks.py

示例12: run

 def run(self):
     pb = PlayBook(playbook=self.playbook,
                   host_list=self.host_list,
                   module_path=self.module_path,
                   callbacks=self.playbook_cb,
                   runner_callbacks=self.runner_cb,
                   stats=self.stats
                   )
     results = pb.run()
     return results
     print results
开发者ID:devops,项目名称:zsphere,代码行数:11,代码来源:ansibletask.py

示例13: action

    def action(self, resource, action):
        # This would require to put this file to remote and execute it (mostly)

        ssh_props = find_named_transport(resource, 'ssh')

        remote_user = ssh_props['user']
        private_key_file = ssh_props.get('key')
        ssh_password = ssh_props.get('password')

        action_file = os.path.join(
            resource.db_obj.actions_path,
            resource.actions[action])

        variables = resource.args
        if 'roles' in variables:
            self.download_roles(variables['roles'])

        host = resource.ip()
        transport = C.DEFAULT_TRANSPORT

        C.HOST_KEY_CHECKING = False

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

        opts = dict(
            playbook=action_file,
            remote_user=remote_user,
            host_list=[host],
            extra_vars=variables,
            callbacks=playbook_cb,
            runner_callbacks=runner_cb,
            stats=stats,
            transport=transport)

        if ssh_password:
            opts['remote_pass'] = ssh_password
        elif private_key_file:
            opts['private_key_file'] = private_key_file
        else:
            raise Exception("No key and no password given")

        play = PlayBook(**opts)

        play.run()
        summary = stats.summarize(host)

        if summary.get('unreachable') or summary.get('failures'):
            raise errors.SolarError(
                'Ansible playbook %s failed with next summary %s',
                action_file, summary)
开发者ID:pigmej,项目名称:solar,代码行数:53,代码来源:ansible_playbook_local.py

示例14: systemtemplate_Install

def systemtemplate_Install():
        playbook = PlayBook(remote_user='root',
                            remote_pass=passwd,
                            playbook='./ansible/play-books/cldstk-preseed-kvm-systmpl.yml',
                            callbacks=playbook_cb,
                            runner_callbacks=runner_cb,
                            stats=stats,
                            host_list='ansible/hosts'
                            )

        playoutput = playbook.run()
        for l in playoutput:print l,playoutput[l]
开发者ID:Tosta-Mixta,项目名称:cldstk-deploy,代码行数:12,代码来源:cldstk-deploy.py

示例15: db_replication_Install

def db_replication_Install():
        playbook = PlayBook(remote_user='root',
                            remote_pass=passwd,
                            playbook='./ansible/play-books/mysql-replication-setup.yml',
                            callbacks=playbook_cb,
                            runner_callbacks=runner_cb,
                            stats=stats,
                            host_list='ansible/hosts'
                            )

        playoutput = playbook.run()
        for l in playoutput:print l,playoutput[l]
开发者ID:Tosta-Mixta,项目名称:cldstk-deploy,代码行数:12,代码来源:cldstk-deploy.py


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