首页 > 解决方案 > CentOS/Ansible - 如何修复错误“_ssl.c:602:握手操作超时”

问题描述

我正在为网络设备运行 API 登录任务,有时我会收到此错误:"_ssl.c:602: The handshake operation timed out". 有时它会运行,有时它会出现握手错误。我最近在使用 SSH 时向网络设备添加了 RADIUS 身份验证,但 API 仍然使用本地凭据。但这会导致问题吗?

我使用的模块是基本的 URI 模块,任务如下所示:

- name: Login to switch using API
  uri:
    url: "https://{{ ansible_host }}/rest/v4/login-sessions"
    method: POST
    headers:
      Accept: "application/json"
      Content-Type: "application/json"
    body: {"userName": "{{ ansible_user }}", "password": "{{ ansible_password }}"}
    body_format: json
    validate_certs: no
    status_code: 201
  register: switch_session

我得到的错误如下:

fatal: [test_switch]: FAILED! => {
    "changed": false,
    "content": "",
    "elapsed": 30,
    "invocation": {
        "module_args": {
            "attributes": null,
            "backup": null,
            "body": {
                "password": "<PASSWORD>",
                "userName": "<USERNAME>"
            },
            "body_format": "json",
            "client_cert": null,
            "client_key": null,
            "content": null,
            "creates": null,
            "delimiter": null,
            "dest": null,
            "directory_mode": null,
            "follow": false,
            "follow_redirects": "safe",
            "force": false,
            "force_basic_auth": false,
            "group": null,
            "headers": {
                "Accept": "application/json",
                "Content-Type": "application/json"
            },
            "http_agent": "ansible-httpget",
            "method": "POST",
            "mode": null,
            "owner": null,
            "regexp": null,
            "remote_src": null,
            "removes": null,
            "return_content": false,
            "selevel": null,
            "serole": null,
            "setype": null,
            "seuser": null,
            "src": null,
            "status_code": [
                "201"
            ],
            "timeout": 30,
            "unix_socket": null,
            "unsafe_writes": null,
            "url": "https://<IP_ADDR>/rest/v4/login-sessions",
            "url_password": null,
            "url_username": null,
            "use_proxy": true,
            "validate_certs": false
        }
    },
    "msg": "Status code was -1 and not [201]: Request failed: <urlopen error ('_ssl.c:602: The handshake operation timed out',)>",
    "redirected": false,
    "status": -1,
    "url": "https://<IP_ADDR>/rest/v4/login-sessions"

标签: ansiblecentos

解决方案


推荐阅读