ansible-playbook 计时器仅在某些节点上 10 秒后过期,但在其他节点上工作正常

ansible-playbook Timer expired after 10 seconds only on some nodes but works just fine on others

我能够 ping 所有服务器,但是当我 运行 所有节点上的 playbook 仅在某些节点和其他节点上有效时,我得到

TimeoutError:定时器在 10 秒后过期

它运行良好。它发生在过去 1 周。

剧本或 ansible cfg 文件没有任何变化。

    The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_Kh_sLm/ansible_modlib.zip/ansible/module_utils/basic.py", line 2853, in run_command
    cmd = subprocess.Popen(args, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1308, in _execute_child
    data = _eintr_retry_call(os.read, errpipe_read, 1048576)
  File "/usr/lib64/python2.7/subprocess.py", line 478, in _eintr_retry_call
    return func(*args)
  File "/tmp/ansible_Kh_sLm/ansible_modlib.zip/ansible/module_utils/facts/timeout.py", line 37, in _handle_timeout
    raise TimeoutError(msg)
TimeoutError: Timer expired after 10 seconds

fatal: [hostname]: FAILED! => {
    "changed": false, 
    "cmd": "/bin/findmnt --list --noheadings --notruncate", 
    "invocation": {
        "module_args": {
            "fact_path": "/etc/ansible/facts.d", 
            "filter": "*", 
            "gather_subset": [
                "all"
            ], 
            "gather_timeout": 10
        }
    }, 
    "msg": "Timer expired after 10 seconds", 
    "rc": 257
}

这似乎不是剧本的问题。正如@MatthewLDaniel 所提到的,尝试通过 ssh 访问失败的节点。由于各种原因,这些 nodes/instances 可能在网络上 unreachable/unresponsive。首先检查实例指标,即 cpu、内存、磁盘和网络连接。

PS: Restarting the instance via AWS/GCP console usually resolves ssh timeouts issue if its a system level one.

另一方面,Ansible 剧本的默认超时为 10 秒。您可以通过在 运行 剧本时传递 timeout 参数来覆盖它。

ansible-playbook playbook.yml -T <TIMEOUT>

ansible-playbook playbook.yml --timeout <TIMEOUT>

这个解决方法对我很有帮助。 在 /etc/ansible/ansible.cfg 我设置 gather_subset = !all 基本上只收集最少的事实。我认为在收集事实时有些事情搞砸了。因此,根据您的要求,将值设置为仅收集您需要的那些事实。

在 ansible.cfg 中设置 gather_timeout=20 应该可以解决。解决方案的来源: https://github.com/ansible/ansible/issues/43884