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


Python PlayBook.run方法代码示例

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


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

示例1: aws

# 需要导入模块: from ansible.playbook import PlayBook [as 别名]
# 或者: from ansible.playbook.PlayBook import run [as 别名]
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,代码行数:62,代码来源:configure.py

示例2: gather_facts

# 需要导入模块: from ansible.playbook import PlayBook [as 别名]
# 或者: from ansible.playbook.PlayBook import run [as 别名]
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,代码行数:32,代码来源:utils_ansible.py

示例3: runPlayBook

# 需要导入模块: from ansible.playbook import PlayBook [as 别名]
# 或者: from ansible.playbook.PlayBook import run [as 别名]
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,代码行数:9,代码来源:runAnsible.py

示例4: Test

# 需要导入模块: from ansible.playbook import PlayBook [as 别名]
# 或者: from ansible.playbook.PlayBook import run [as 别名]
 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,代码行数:10,代码来源:Ansible.py

示例5: deploy_service

# 需要导入模块: from ansible.playbook import PlayBook [as 别名]
# 或者: from ansible.playbook.PlayBook import run [as 别名]
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,代码行数:11,代码来源:__init__.py

示例6: action

# 需要导入模块: from ansible.playbook import PlayBook [as 别名]
# 或者: from ansible.playbook.PlayBook import run [as 别名]
    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,代码行数:55,代码来源:ansible_playbook_local.py

示例7: configure_hosts

# 需要导入模块: from ansible.playbook import PlayBook [as 别名]
# 或者: from ansible.playbook.PlayBook import run [as 别名]
    def configure_hosts(self, reservation_obj, playbook):
        inven = Inventory(host_list=reservation_obj.keys())
        for host in inven.get_hosts():
            for key, value in reservation_obj[host.name].items():
                host.set_variable(key, value)

        stats = callbacks.AggregateStats()
        playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
        runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)
        pb = PlayBook(inventory=inven,
                      playbook=playbook,
                      stats=stats,
                      callbacks=playbook_cb,
                      runner_callbacks=runner_cb)
        pb.run()
开发者ID:amritbhanu,项目名称:SPark_VCL-On-CentOS,代码行数:17,代码来源:vclopsworks.py

示例8: run_playbook

# 需要导入模块: from ansible.playbook import PlayBook [as 别名]
# 或者: from ansible.playbook.PlayBook import run [as 别名]
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,代码行数:33,代码来源:ngspyeasy_play_run.py

示例9: RunRecepie

# 需要导入模块: from ansible.playbook import PlayBook [as 别名]
# 或者: from ansible.playbook.PlayBook import run [as 别名]
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,代码行数:30,代码来源:AnsibleV1Wrap.py

示例10: run_installer

# 需要导入模块: from ansible.playbook import PlayBook [as 别名]
# 或者: from ansible.playbook.PlayBook import run [as 别名]
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,代码行数:33,代码来源:installer.py

示例11: install_stuff

# 需要导入模块: from ansible.playbook import PlayBook [as 别名]
# 或者: from ansible.playbook.PlayBook import run [as 别名]
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,代码行数:34,代码来源:tasks.py

示例12: gather_facts

# 需要导入模块: from ansible.playbook import PlayBook [as 别名]
# 或者: from ansible.playbook.PlayBook import run [as 别名]
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,代码行数:35,代码来源:utils_ansible.py

示例13: run

# 需要导入模块: from ansible.playbook import PlayBook [as 别名]
# 或者: from ansible.playbook.PlayBook import run [as 别名]
    def run(self):
        """Run playbook

        Runs playbook and collects output to self.results

        """
        stats = PlayBook.run(self)
        return self.process_results(self.results)
开发者ID:pombreda,项目名称:ansiblereporter,代码行数:10,代码来源:result.py

示例14: execute

# 需要导入模块: from ansible.playbook import PlayBook [as 别名]
# 或者: from ansible.playbook.PlayBook import run [as 别名]
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,代码行数:58,代码来源:tasks.py

示例15: __run_playbook

# 需要导入模块: from ansible.playbook import PlayBook [as 别名]
# 或者: from ansible.playbook.PlayBook import run [as 别名]
    def __run_playbook(self, name):
        # 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)

        # load playbook
        pb = PlayBook(
            playbook = os.path.dirname(__file__) + '/ansible/' + name,
            host_list = self.__hosts.name,
            callbacks=playbook_cb,
            runner_callbacks=runner_cb,
            stats=stats
        )

        pb.run()

        return self.__check_success(pb.stats)
开发者ID:Carl-Shi,项目名称:RackHD,代码行数:21,代码来源:ansible_control.py


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