xezpeleta/Ansible-Proxmox-inventory

Error: socket.timeout: The read operation timed out

wonkytreestump opened this issue · 6 comments

Hello,
thanks for your work so far. I have an issue with your script, there is a timeout which I am not sure where it comes from:

 > /usr/bin/python3 proxmox.py --list --pretty
Traceback (most recent call last):
  File "/etc/ansible/proxmox.py", line 447, in <module>
    main()
  File "/etc/ansible/proxmox.py", line 432, in main
    data = main_list(options, config_path)
  File "/etc/ansible/proxmox.py", line 288, in main_list
    proxmox_api.auth()
  File "/etc/ansible/proxmox.py", line 145, in auth
    data = json.load(open_url(request_path, data=request_params,
  File "/home/<usr>/.local/lib/python3.9/site-packages/ansible/module_utils/urls.py", line 1393, in open_url
    return Request().open(method, url, data=data, headers=headers, use_proxy=use_proxy,
  File "/home/<usr>/.local/lib/python3.9/site-packages/ansible/module_utils/urls.py", line 1304, in open
    return urllib_request.urlopen(request, None, timeout)
  File "/usr/lib/python3.9/urllib/request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.9/urllib/request.py", line 517, in open
    response = self._open(req, data)
  File "/usr/lib/python3.9/urllib/request.py", line 534, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/usr/lib/python3.9/urllib/request.py", line 494, in _call_chain
    result = func(*args)
  File "/home/<usr>/.local/lib/python3.9/site-packages/ansible/module_utils/urls.py", line 483, in https_open
    return self.do_open(self._build_https_connection, req)
  File "/usr/lib/python3.9/urllib/request.py", line 1350, in do_open
    r = h.getresponse()
  File "/usr/lib/python3.9/http/client.py", line 1347, in getresponse
    response.begin()
  File "/usr/lib/python3.9/http/client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.9/http/client.py", line 268, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib/python3.9/socket.py", line 704, in readinto
    return self._sock.recv_into(b)
  File "/usr/lib/python3.9/ssl.py", line 1241, in recv_into
    return self.read(nbytes, buffer)
  File "/usr/lib/python3.9/ssl.py", line 1099, in read
    return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

The proxmox.json looks as follows:

cat proxmox.json 
{
    "url": "https://ip:8006/",
    "username": "user@realm",
    "password": "pass",
    "validateCert": false
}

Any idea what may be wrong here? Thanks in advance!

What ProxmoxVE version do you have?

Can you test connecting to https://ip:8006/ URL vía curl?

Thanks

Proxmox Version:

Kernel Version Linux 5.4.114-1-pve #1 SMP PVE 5.4.114-1 (Sun, 09 May 2021 17:13:05 +0200)
PVE Manager Version pve-manager/6.4-8/185e14db

curl (without the -k parameter curl fails because it is a self-signed cert)

> curl -k https://ip:8006
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>ol-prox01-rz1 - Proxmox Virtual Environment</title>
    <link rel="icon" sizes="128x128" href="/pve2/images/logo-128.png" />
    <link rel="apple-touch-icon" sizes="128x128" href="/pve2/images/logo-128.png" />
    <link rel="stylesheet" type="text/css" href="/pve2/ext6/theme-crisp/resources/theme-crisp-all.css" />
    <link rel="stylesheet" type="text/css" href="/pve2/ext6/crisp/resources/charts-all.css" />
    <link rel="stylesheet" type="text/css" href="/pve2/fa/css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="/pve2/css/ext6-pve.css?ver=6.3-3" />
    <link rel="stylesheet" type="text/css" href="/pwt/css/ext6-pmx.css?ver=2.4-5" />
    
    <script type='text/javascript'>function gettext(buf) { return buf; }</script>
    
    <script type="text/javascript" src="/pve2/ext6/ext-all.js"></script>
    <script type="text/javascript" src="/pve2/ext6/charts.js"></script>
    
    <script type="text/javascript" src="/pve2/js/u2f-api.js"></script>
    <script type="text/javascript" src="/pve2/js/qrcode.min.js"></script>
    <script type="text/javascript">
    Proxmox = {
	Setup: { auth_cookie_name: 'PVEAuthCookie' },
	defaultLang: 'en',
	UserName: '',
	CSRFPreventionToken: 'null'
    };
    </script>
    <script type="text/javascript" src="/proxmoxlib.js?ver=2.4-5"></script>
    <script type="text/javascript" src="/pve2/js/pvemanagerlib.js?ver=6.3-3"></script>
    <script type="text/javascript" src="/pve2/ext6/locale/locale-en.js"></script>

    <script type="text/javascript">
    if (typeof(PVE) === 'undefined') PVE = {};
    Ext.History.fieldid = 'x-history-field';
    Ext.onReady(function() { Ext.create('PVE.StdWorkspace');});
    </script>

  </head>
  <body>
    <!-- Fields required for history management -->
    <form id="history-form" class="x-hidden">
    <input type="hidden" id="x-history-field"/>
    </form>
  </body>
</html>

So apparently it's not a connection issue.

It looks that your Proxmox requires more time to return the gathered data. You could try incrementing the timeout in your /etc/ansible/ansible.cfg file:

command_timeout = 60

Thanks

Thanks, but that didn't do the trick. I noticed that the timeout occurs after 8 to 10 seconds, even after increasing every timeout in ansible.cfg.

Using another Proxmox Cluster with less machines didn't help either.

@xezpeleta Any other ideas what might cause this timeout? Your help is highly appreciated!

@wonkytreestump Just curious, when you run the curl, did you run that on the machine where you want to run ansible? Can you curl again but this time use the actual API URI for that authentication, be sure to run it on the machine where you expect to run ansible.

curl -k  https://ip:8006/api2/json/access/ticket