[英]How do I set a timeout for an Ansible Runner task?
In the following hypothetical example, I'm executing sleep
for five sec on the remote host via the shell module.在下面的假设示例中,我通过 shell 模块在远程主机上执行sleep
5 秒。 I'd like the Ansible Runner to timeout after four seconds if the remote shell process hasn't returned.如果远程 shell 进程没有返回,我希望 Ansible Runner 在四秒后超时。 Is this possible?这可能吗?
r = ansible_runner.run(inventory=ansible_inventory, host_pattern="all",
module="shell",
module_args=("sleep 5"),
envvars = {
"ansible_command_timeout": 4 # This doesn't seem to work
}
)
This worked for me.这对我有用。 envvars is assigned the return of this method: envvars 被分配了这个方法的返回值:
def runnerenv(self):
"""ansible runner environment"""
env = os.environ.copy()
path = f"{env['PATH']}:{self.venvpath}"
self.logger.debug(f"Updated PATH {path}")
env['PATH'] = path
env['ANSIBLE_TASK_TIMEOUT'] = 60
return env
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.