长时间运行的模块的 Ansible 连接被远程主机关闭

问题描述 投票:0回答:1

我正在运行一个 Ansible 脚本,它有一个在远程服务器中进行备份的模块。由于备份作业花费的时间超过 15 分钟,conn 被远程主机关闭,因为实施了安全标准,在 15 分钟的空闲时间(在 ssh_config 中设置的 ClientAliveInterval)后关闭 conn。不想改变安全标准,同时又希望 Ansible 能够工作。

我已经尝试过以下两种解决方案,但都不起作用。任何在这方面的帮助将不胜感激。

  1. 包含
    -o ServerAliveInterval
    于 ssh_args 部分的 ansible.cfg 文件中。
  2. 通过在
    .~/.ssh/config
  3. 中创建配置文件在 Ansible 主机中实现以下参数
TCPKeepAlive yes
ServerAliveInterval 30

提前谢谢您。

ansible
1个回答
0
投票

这并不适用于所有 ansible 任务,但对于支持

async
的任务,您可以添加:

  async: <how long to wait>
  poll: <poll time in seconds>

例如

- name: Execute command and wait for 2 hours for it to finish, polling every 60 seconds
  command: "/tmp/long_running.sh"
  async: 7200
  poll: 60

轮询让我保持了连接。

我无法在 ansible 文档中找到哪些任务支持异步,所以这对我来说是一次尝试和错误。

command
shell
unarchive
可以。
copy
script
不要。

© www.soinside.com 2019 - 2024. All rights reserved.