本文整理汇总了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))