HuaweiSwitch / CloudEngine-Ansible

Ansible modules to automate HUAWEI CloudEngine switches
GNU General Public License v3.0
143 stars 51 forks source link

执行该命令的时候报ce_command的时候报raise socket.timeout() #27

Closed slientup closed 6 years ago

slientup commented 6 years ago

ansible -m ce_command -a 'host=192.168.1.5 port=22 username=admin@123 password=Huawei@123456 commands="display version"' localhost --connection local -vvvv 执行该命令的时候报raise socket.timeout() An exception occurred during task execution. The full traceback is: Traceback (most recent call last): File "/tmp/ansible_un2ETe/ansible_module_ce_command.py", line 263, in main() File "/tmp/ansible_un2ETe/ansible_module_ce_command.py", line 199, in main supports_check_mode=True) File "/tmp/ansible_un2ETe/ansible_modlib.zip/ansible/module_utils/network.py", line 112, in init File "/tmp/ansible_un2ETe/ansible_modlib.zip/ansible/module_utils/network.py", line 148, in connect File "/tmp/ansible_un2ETe/ansible_modlib.zip/ansible/module_utils/cloudengine.py", line 243, in connect File "/tmp/ansible_un2ETe/ansible_modlib.zip/ansible/module_utils/shell.py", line 226, in connect File "/tmp/ansible_un2ETe/ansible_modlib.zip/ansible/module_utils/shell.py", line 116, in open File "/tmp/ansible_un2ETe/ansible_modlib.zip/ansible/module_utils/shell.py", line 128, in receive File "/usr/lib/python2.7/site-packages/paramiko/channel.py", line 667, in recv

raise socket.timeout()

socket.timeout

localhost | FAILED! => { "changed": false, "failed": true, "invocation": { "module_name": "ce_command" }, "module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_un2ETe/ansible_module_ce_command.py\", line 263, in \n main()\n File \"/tmp/ansible_un2ETe/ansible_module_ce_command.py\", line 199, in main\n supports_check_mode=True)\n File \"/tmp/ansible_un2ETe/ansible_modlib.zip/ansible/module_utils/network.py\", line 112, in init\n File \"/tmp/ansible_un2ETe/ansible_modlib.zip/ansible/module_utils/network.py\", line 148, in connect\n File \"/tmp/ansible_un2ETe/ansible_modlib.zip/ansible/module_utils/cloudengine.py\", line 243, in connect\n File \"/tmp/ansible_un2ETe/ansible_modlib.zip/ansible/module_utils/shell.py\", line 226, in connect\n File \"/tmp/ansible_un2ETe/ansible_modlib.zip/ansible/module_utils/shell.py\", line 116, in open\n File \"/tmp/ansible_un2ETe/ansible_modlib.zip/ansible/module_utils/shell.py\", line 128, in receive\n File \"/usr/lib/python2.7/site-packages/paramiko/channel.py\", line 667, in recv\n raise socket.timeout()\nsocket.timeout\n", "module_stdout": "", "msg": "MODULE FAILURE"

slientup commented 6 years ago

通过日志查看报如下错误,在unable to load cliconf for network_os ce 我再cliconf目录下也没有找到ce.py 2017-12-09 11:52:39,570 p=1216 u=root | loaded terminal plugin for network_os ce unable to load cliconf for network_os ce

QijunPan commented 6 years ago

请确定设备可以通过ssh方式登录。

QijunPan commented 6 years ago

同时,请提供下版本信息。 1)ansible版本 2)ce库版本(或从哪获取)?

QijunPan commented 6 years ago

从现象上来看,这个是ansible新增加的处理逻辑,只在ansible 2.5(开发分支devel)中有。请使用发布release版本。

slientup commented 6 years ago

ssh可以登录,从日志就可以看出, ansible的版本是ansible 2.4.2.0 通过pip管道安装的,CE库的版本是直接集成在ansible2.4.2.0里面的并没有单独安装, 相关日志: 2017-12-09 11:45:04,398 p=1195 u=root | connecting to host 192.168.1.108 returned an error 2017-12-09 11:45:04,398 p=1195 u=root | timed out 2017-12-09 11:52:38,270 p=1216 u=root | creating new control socket for host 192.168.1.108:22 as user admin123 2017-12-09 11:52:38,271 p=1216 u=root | control socket path is /root/.ansible/pc/90d67a59a6 2017-12-09 11:52:38,271 p=1216 u=root | current working directory is / 2017-12-09 11:52:38,271 p=1216 u=root | using connection plugin network_cli 2017-12-09 11:52:38,527 paramiko.transport starting thread (client mode): 0x2331290L 2017-12-09 11:52:38,528 paramiko.transport Local version/idstring: SSH-2.0-paramiko_2.1.1 2017-12-09 11:52:38,750 paramiko.transport Remote version/idstring: SSH-2.0-- 2017-12-09 11:52:38,751 paramiko.transport Connected (version 2.0, client -) 2017-12-09 11:52:38,755 paramiko.transport kex algos:[u'diffie-hellman-group1-sha1', u'ecdh-sha2-nistp521', u'ecdh-sha2-nistp384', u'ecdh-sha2-nistp256', u'diffie-hellman-group-exchange-sha256', u'diffie-hellman-group-exchange-sha1', u'sm2kep-sha2-nistp256'] server key:[u'ssh-dss', u'ssh-rsa', u'ecdsa-sha2-nistp521'] client encrypt:[u'aes256-ctr', u'aes128-ctr', u'aes256-cbc', u'aes128-cbc', u'blowfish-cbc', u'3des-cbc'] server encrypt:[u'aes256-ctr', u'aes128-ctr', u'aes256-cbc', u'aes128-cbc', u'blowfish-cbc', u'3des-cbc'] client mac:[u'hmac-sha2-256', u'hmac-sha2-256-96', u'hmac-sha1', u'hmac-sha1-96'] server mac:[u'hmac-sha2-256', u'hmac-sha2-256-96', u'hmac-sha1', u'hmac-sha1-96'] client compress:[u'none', u'zlib'] server compress:[u'none', u'zlib'] client lang:[u''] server lang:[u''] kex follows?False 2017-12-09 11:52:38,755 paramiko.transport Kex agreed: diffie-hellman-group1-sha1 2017-12-09 11:52:38,755 paramiko.transport Cipher agreed: aes128-ctr 2017-12-09 11:52:38,756 paramiko.transport MAC agreed: hmac-sha2-256 2017-12-09 11:52:38,756 paramiko.transport Compression agreed: none 2017-12-09 11:52:39,083 paramiko.transport kex engine KexGroup1 specified hash_algo 2017-12-09 11:52:39,085 paramiko.transport Switch to new keys ... 2017-12-09 11:52:39,319 paramiko.transport userauth is OK 2017-12-09 11:52:39,381 paramiko.transport Authentication (password) successful! 2017-12-09 11:52:39,383 p=1216 u=root | ssh connection done, setting terminal 2017-12-09 11:52:39,383 paramiko.transport [chan 0] Max packet in: 32768 bytes 2017-12-09 11:52:39,419 paramiko.transport [chan 0] Max packet out: 32768 bytes 2017-12-09 11:52:39,419 paramiko.transport Secsh channel 0 opened. 2017-12-09 11:52:39,451 paramiko.transport [chan 0] Sesch channel 0 request ok 2017-12-09 11:52:39,548 paramiko.transport [chan 0] Sesch channel 0 request ok 2017-12-09 11:52:39,570 p=1216 u=root | loaded terminal plugin for network_os ce unable to load cliconf for network_os ce 2017-12-09 11:52:39,577 p=1216 u=root | unable to load cliconf for network_os ce 2017-12-09 11:52:48,321 p=1207 u=root | localhost | FAILED! => { "changed": false, "msg": "unable to open shell. Please see: https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell" } 2017-12-09 11:52:49,578 p=1216 u=root | failed to create control socket for host 172.16.255.1 2017-12-09 11:52:49,585 p=1216 u=root | Traceback (most recent call last): File "/usr/bin/ansible-connection", line 315, in main server = Server(socket_path, pc) File "/usr/bin/ansible-connection", line 112, in init self.connection._connect() File "/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.py", line 139, in _connect self.receive() File "/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.py", line 176, in receive data = self._shell.recv(256) File "/usr/lib/python2.7/site-packages/paramiko/channel.py", line 667, in recv raise socket.timeout() timeout

2017-12-09 11:52:49,606 paramiko.transport EOF in transport thread

slientup commented 6 years ago

在cliconf的目录下面有cisco操作系统的py文件,但是并没有看到我们华为 ce.py的文件 [root@localhost cliconf]# ll 总用量 96 -rw-r--r-- 1 root root 2670 11月 30 05:08 aireos.py -rw-r--r-- 1 root root 2971 12月 8 17:39 aireos.pyc -rw-r--r-- 1 root root 2656 11月 30 05:08 aruba.py -rw-r--r-- 1 root root 2949 12月 8 17:39 aruba.pyc -rw-r--r-- 1 root root 2546 11月 30 05:08 asa.py -rw-r--r-- 1 root root 2876 12月 8 17:39 asa.pyc -rw-r--r-- 1 root root 2385 11月 30 05:08 eos.py -rw-r--r-- 1 root root 2663 12月 8 17:39 eos.pyc -rw-r--r-- 1 root root 8340 11月 30 05:08 init.py -rw-r--r-- 1 root root 9950 12月 8 17:39 init.pyc -rw-r--r-- 1 root root 2544 11月 30 05:08 ios.py -rw-r--r-- 1 root root 2874 12月 8 17:39 ios.pyc -rw-r--r-- 1 root root 2900 11月 30 05:08 iosxr.py -rw-r--r-- 1 root root 3430 12月 8 17:39 iosxr.pyc -rw-r--r-- 1 root root 2991 11月 30 05:08 junos.py -rw-r--r-- 1 root root 3721 12月 8 17:39 junos.pyc -rw-r--r-- 1 root root 2052 11月 30 05:08 nxos.py -rw-r--r-- 1 root root 2427 12月 8 17:39 nxos.pyc -rw-r--r-- 1 root root 2529 11月 30 05:08 vyos.py -rw-r--r-- 1 root root 3111 12月 8 17:39 vyos.pyc

QijunPan commented 6 years ago

这个有个已知问题,把这个pull request的改动(2行)直接更新到你的环境,手动改下,当前这个PR还没合入。 https://github.com/ansible/ansible/pull/33732/files

QijunPan commented 6 years ago

确定了,这个是新的机制,还没适配。

slientup commented 6 years ago
         那我添加这两行能实现访问吗?
         display.vvv('using connection plugin %s' % pc.connection, pc.remote_addr)
          connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
slientup commented 6 years ago

我做了如下修改之后还是一样,请问是不是修改后还是不行,如果不行的话,能否推荐下可以成功的ansible版本和ce库的版本? 66 # password=pc.password, 67 # ssh_keyfile=pc.private_key_file 68 password=pc.password 69 ) 70 display.vvv('using connection plugin %s' % pc.connection, pc.remote_addr) 71 connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)

91 self._task.args['transport'] = transport 92 self._task.args['provider'] = provider

justbiaoliu commented 6 years ago

@zhixiongzeng ,2.4.2.0的release版本修改ce.py后,我这试了是OK的啊 [root@SZV1000182092 ansible]# ansible -m ce_command -a 'host=10.134.124.254 port=6850 username=client001 password=Admin@123 commands="display version"' localhost --connection local -vvvv ansible 2.4.2.0 config file = /etc/ansible/ansible.cfg configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/site-packages/ansible-2.4.2.0-py2.7.egg/ansible executable location = /usr/bin/ansible python version = 2.7.5 (default, Sep 15 2016, 22:37:39) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] Using /etc/ansible/ansible.cfg as config file setting up inventory plugins Set default localhost to localhost Parsed /etc/ansible/hosts inventory source with ini plugin [WARNING]: Found both group and host with same name: localhost

Loading callback plugin minimal of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible-2.4.2.0-py2.7.egg/ansible/plugins/callback/init.pyc META: ran handlers

connection transport is cli <10.134.124.254> using connection plugin network_cli <10.134.124.254> socket_path: /root/.ansible/pc/c5ddb762f8 Using module file /usr/lib/python2.7/site-packages/ansible-2.4.2.0-py2.7.egg/ansible/modules/network/cloudengine/ce_command.py ESTABLISH LOCAL CONNECTION FOR USER: root EXEC /bin/sh -c 'echo ~ && sleep 0' EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1515554422.3-89856805366188 `" && echo ansible-tmp-1515554422.3-89856805366188="` echo /root/.ansible/tmp/ansible-tmp-1515554422.3-89856805366188 `" ) && sleep 0' PUT /tmp/tmp64TEJk TO /root/.ansible/tmp/ansible-tmp-1515554422.3-89856805366188/ce_command.py EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1515554422.3-89856805366188/ /root/.ansible/tmp/ansible-tmp-1515554422.3-89856805366188/ce_command.py && sleep 0' EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1515554422.3-89856805366188/ce_command.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1515554422.3-89856805366188/" > /dev/null 2>&1 && sleep 0' [WARNING]: argument username has been deprecated and will be removed in a future version [WARNING]: argument host has been deprecated and will be removed in a future version [WARNING]: argument password has been deprecated and will be removed in a future version [WARNING]: argument port has been deprecated and will be removed in a future version localhost | SUCCESS => { "changed": false, "invocation": { "module_args": { "commands": [ "display version" ], "host": "10.134.124.254", "interval": 1, "match": "all", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "port": 6850, "provider": { "host": "10.134.124.254", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "port": 6850, "timeout": null, "transport": "cli", "use_ssl": null, "username": "client001", "validate_certs": null }, "retries": 10, "timeout": null, "transport": "cli", "use_ssl": null, "username": "client001", "validate_certs": null, "wait_for": null } }, "stdout": [ "Huawei Versatile Routing Platform Software\nVRP (R) software, Version 8.160 (CE6850HI V200R003C00SPC810)\nCopyright (C) 2012-2018 Huawei Technologies Co., Ltd.\nHUAWEI CE6850U-48S6Q-HI uptime is 1 day, 18 hours, 38 minutes \n\nCE6850U-48S6Q-HI(Master) 1 : uptime is 1 day, 18 hours, 37 minutes\n StartupTime 2018/01/08 16:46:49 \nMemory Size : 4096 M bytes\nFlash Size : 1024 M bytes\nNVRAM Size : 512 K bytes\nCE6850U-48S6Q-HI version information \n1. PCB Version : CEM48S6QP02 VER A\n2. MAB Version : 1\n3. Board Type : CE6850U-48S6Q-HI\n4. CPLD1 Version : 102\n5. BIOS Version : 402" ], "stdout_lines": [ [ "Huawei Versatile Routing Platform Software", "VRP (R) software, Version 8.160 (CE6850HI V200R003C00SPC810)", "Copyright (C) 2012-2018 Huawei Technologies Co., Ltd.", "HUAWEI CE6850U-48S6Q-HI uptime is 1 day, 18 hours, 38 minutes ", "", "CE6850U-48S6Q-HI(Master) 1 : uptime is 1 day, 18 hours, 37 minutes", " StartupTime 2018/01/08 16:46:49 ", "Memory Size : 4096 M bytes", "Flash Size : 1024 M bytes", "NVRAM Size : 512 K bytes", "CE6850U-48S6Q-HI version information ", "1. PCB Version : CEM48S6QP02 VER A", "2. MAB Version : 1", "3. Board Type : CE6850U-48S6Q-HI", "4. CPLD1 Version : 102", "5. BIOS Version : 402" ] ] } META: ran handlers META: ran handlers [root@SZV1000182092 ansible]# [root@SZV1000182092 ansible]# [root@SZV1000182092 ansible]# ansible --version ansible 2.4.2.0 config file = /etc/ansible/ansible.cfg configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/site-packages/ansible-2.4.2.0-py2.7.egg/ansible executable location = /usr/bin/ansible python version = 2.7.5 (default, Sep 15 2016, 22:37:39) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] [root@SZV1000182092 ansible]#
slientup commented 6 years ago

我这边再试后,依然是那个错误。 2018-03-06 18:16:46,664 p=8607 u=root | ssh connection done, setting terminal 2018-03-06 18:16:46,666 paramiko.transport [chan 0] Max packet in: 32768 bytes 2018-03-06 18:16:46,674 paramiko.transport [chan 0] Max packet out: 32768 bytes 2018-03-06 18:16:46,675 paramiko.transport Secsh channel 0 opened. 2018-03-06 18:16:46,682 paramiko.transport [chan 0] Sesch channel 0 request ok 2018-03-06 18:16:46,692 paramiko.transport [chan 0] Sesch channel 0 request ok 2018-03-06 18:16:46,702 p=8607 u=root | loaded terminal plugin for network_os ce unable to load cliconf for network_os ce 2018-03-06 18:16:46,707 p=8607 u=root | unable to load cliconf for network_os ce 2018-03-06 18:16:55,534 p=8596 u=root | localhost | FAILED! => { "changed": false, "msg": "unable to open shell. Please see: https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell" } 2018-03-06 18:16:56,709 p=8607 u=root | failed to create control socket for host 172.16.255.1 2018-03-06 18:16:56,712 p=8607 u=root | Traceback (most recent call last):

slientup commented 6 years ago

能否远程支持帮忙看下?

justbiaoliu commented 6 years ago

可以,您告诉我下时间,和方式,邮件发我下,或者微信等联系方式

slientup commented 6 years ago

我什么时候都可以,微信号18780106305 谢谢

justbiaoliu commented 6 years ago

已经联系处理,问题闭环。