linux - Ansible wait_for 重启

标签 linux ssh ansible developer-tools

我正在尝试使用 ansible 来配置我必须使用的环境。特别是,我需要编写一个重启服务器的任务,所以我写了这个任务:

- name: waiting for server to come back
  local_action: wait_for 
    host={{ ansible_hostname }}
    port=22
    state=started 
    delay=50
    timeout=300
  sudo: false

但即使服务器已正确重新启动,任务仍无法达到超时。

我想知道它是否因为我的 ssh 配置而失败。与这些服务器的连接是通过代理完成的(~/.ssh/config 中的ProxyCommand)。


FROM VERBOSE OUTPUT

<servername> ESTABLISH SSH CONNECTION FOR USER: username

<servername> SSH: EXEC ssh -C -vvv -o ControlMaster=False -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=username -o ConnectTimeout=10 -tt hostname

...

fatal: [servername -> localhost]: FAILED! => {"changed": false, "elapsed": 300, "failed": true, "invocation": {"module_args": {"connect_timeout": 5, "delay": "10", "exclude_hosts": null, "host": "hostname", "path": null, "port": "22", "search_regex": null, "state": "started", "timeout": "300"}, "module_name": "wait_for"}, "msg": "Timeout when waiting for host:22"}

我不知道是否相关,但在输出中:

hostname != servername: hostname = foo, servername = foo.bar.com

我认为 hostname=ansible_hostnameservername=inventory_hostname


Ansible版本:ansible 2.0.1.0

最佳答案

这是一个连接问题。为了摆脱这个问题,我增加了 ssh 超时。

一个简单的方法是在 ansible 脚本的同一目录中创建一个 ansible.cfg 文件并放入以下内容:

[defaults]
timeout = xx

xx 对我来说是 30。

关于linux - Ansible wait_for 重启,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35964441/

相关文章:

linux - 我可以逐行读取hadoop文件吗

我可以通过堆栈转储判断一个进程是被杀死还是它自己崩溃了吗?

networking - Beaglebone black 上的 ping 和 opkg 更新问题

ansible - 在 ansible playbook 文件中指定 ssh key

ssl - Ansible,如何信任证书?

c - 如何从终端“按键缓冲区”读取?

linux - 使用 shell 脚本向电子邮件组发送电子邮件

linux - EC2 上的 SSH 连接问题

linux - 无需密码即可通过 ssh 连接到 ec2 实例

linux - 如何在 Ubuntu 上固定 Rabbitmq 版本?