gpt4 book ai didi

linux - Ansible wait_for 重启

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:25:24 27 4
gpt4 key购买 nike

我正在尝试使用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com