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


Python Runner.module_name方法代码示例

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


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

示例1: check_health

# 需要导入模块: from ansible.runner import Runner [as 别名]
# 或者: from ansible.runner.Runner import module_name [as 别名]
def check_health(opts, vm_name, vm_ip):
    """
    Test connectivity to the VM

    :param vm_ip: ip address to the newly created VM
    :raises: :py:class:`~backend.exceptions.CoprWorkerSpawnFailError`: validation fails
    """
    # setproctitle("check VM: {}".format(vm_ip))

    log = get_redis_logger(opts, "vmm.check_health.detached", "vmm")

    runner_options = dict(
        remote_user=opts.build_user or "root",
        host_list="{},".format(vm_ip),
        pattern=vm_ip,
        forks=1,
        transport=opts.ssh.transport,
        timeout=opts.vm_ssh_check_timeout
    )
    connection = Runner(**runner_options)
    connection.module_name = "shell"
    connection.module_args = "echo hello"

    result = {
        "vm_ip": vm_ip,
        "vm_name": vm_name,
        "msg": "",
        "result": "OK",
        "topic": EventTopics.HEALTH_CHECK
    }
    err_msg = None
    try:
        res = connection.run()
        if vm_ip not in res.get("contacted", {}):
            err_msg = (
                "VM is not responding to the testing playbook."
                "Runner options: {}".format(runner_options) +
                "Ansible raw response:\n{}".format(res))

    except Exception as error:
        err_msg = "Failed to check  VM ({})due to ansible error: {}".format(vm_ip, error)
        log.exception(err_msg)

    try:
        if err_msg:
            result["result"] = "failed"
            result["msg"] = err_msg
        rc = get_redis_connection(opts)
        rc.publish(PUBSUB_MB, json.dumps(result))
    except Exception as err:
        log.exception("Failed to publish msg health check result: {} with error: {}"
                      .format(result, err))
开发者ID:seocam,项目名称:copr,代码行数:54,代码来源:check.py


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